Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: support # pyright: ignore not at the start of a comment #4259

Closed
Avasam opened this issue Nov 30, 2022 · 2 comments
Closed
Labels
addressed in next version Issue is fixed and will appear in next published version enhancement request New feature or request

Comments

@Avasam
Copy link

Avasam commented Nov 30, 2022

Is your feature request related to a problem? Please describe.
Some tools (pyright included) expect their special keyword in a comment to be at the start of a comment. This can be problematic if two of those tools need a comment on the same line.

One such other example (with a high risk of collision), is mypy (for example to validate that a library will pass both checkers). I can't ignore both pyright and mypy if they have an error on the same line and enableTypeIgnoreComments is turned off (to separate mypy issues from pyright issues in the first place)
Same line doesn't even necessarily mean same error. But certain formatters (like black), will force everytihing on a line until the set limit.

Example (neither will work):

class Task(Future[_T_co], Generic[_T_co]):  # type: ignore[type-var]  # pyright: ignore[reportGeneralTypeIssues]
  # [...]
  pass
 
# OR

class Task(Future[_T_co], Generic[_T_co]):  # pyright: ignore[reportGeneralTypeIssues]  # type: ignore[type-var]
  # [...]
  pass

Describe the solution you'd like
One solution is support # pyright: ignore even if it's not at the start of the comment.
For instance, pylint, bandit, flake8, isort all do it to avoid this exact kind of issue:

from typing import Any, Any  # pyright: ignore[reportDuplicateImport]  # isort:skip

class CaptureMethodMeta(EnumMeta):
    # Allow checking if simple string is enum
    def __contains__(self, other: str):
        try:
            self(other)  # pyright: ignore [reportGeneralTypeIssues] pylint: disable=no-value-for-parameter
        except ValueError:
            return False
        else:
            return True

def openFile(file_path: str):  # pyright: ignore[reportUnknownParameterType, reportMissingParameterType]  # noqa: N802
    os.startfile(file_path)  # pyright: ignore[reportUnknownArgumentType]  # nosec B606

And given discussions in python/mypy#12358 , I don't think mypy is going to be able to support ignores at the end of the line anytime soon.

Additional context

Other possible solutions (but already declined) include block-level comments: #2607
and a "next-line" ignore.

@Avasam Avasam added the enhancement request New feature or request label Nov 30, 2022
erictraut pushed a commit that referenced this issue Dec 1, 2022
…hat are not at the start of a comment. This addresses #4259.
@erictraut
Copy link
Collaborator

This will be addressed in the next release.

@erictraut erictraut added the addressed in next version Issue is fixed and will appear in next published version label Dec 1, 2022
@erictraut
Copy link
Collaborator

This is addressed in pyright 1.1.283, which I just published. It will also be included in a future version of pylance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version enhancement request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants