-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
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]
# [...]
passDescribe 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 B606And 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.