You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue is half bug report, half feature request ;)
The issue
Whole-file # type: ignore was added in: #6830
To my surprise, adding # type: ignore[valid-type] as the first line of a file doesn't do what I expected.
It does the exact same as # type: ignore as the first line would do, i.e. the [valid-type] portion is totally ignored, without printing any error or warning... If this is unsupported syntax, it would be good if mypy errors out on it, because accepting this without warning is misleading (one might think only some errors are suppressed, but in fact all errors are suppressed).
The feature request
Even better would be if we can add support for error-code specific whole-file ignores. I.e. properly support start-of-file annotations like # type: ignore[valid-type]
Pitch
An example I ran into is a case where a certain framework defines framework types using =. E.g. MyType = CustomType(Foo=BarType). This causes many issues with mypy (perhaps for good reasons?), but when fixing the framework is not within our abilities, we should at least have a way to suppress the various error types this causes globally in a file, otherwise I would need to add many line ignores into that file (I have an example hitting tens of valid-type errors in a single file) or ignore the file completely...
Other things I've tried
1: mypy.ini based ignores
I tried using this in mypy.ini:
Mostly duplicates. But this focusses on code comments (applying to the whole file), rather than achieving this through the mypy ini file (though both aren't possible at this time). Perhaps we can extend the discussion in #9440 to cover support on file-level too?
This issue is half bug report, half feature request ;)
The issue
Whole-file
# type: ignore
was added in: #6830To my surprise, adding
# type: ignore[valid-type]
as the first line of a file doesn't do what I expected.It does the exact same as
# type: ignore
as the first line would do, i.e. the[valid-type]
portion is totally ignored, without printing any error or warning... If this is unsupported syntax, it would be good if mypy errors out on it, because accepting this without warning is misleading (one might think only some errors are suppressed, but in fact all errors are suppressed).The feature request
Even better would be if we can add support for error-code specific whole-file ignores. I.e. properly support start-of-file annotations like
# type: ignore[valid-type]
Pitch
An example I ran into is a case where a certain framework defines framework types using
=
. E.g.MyType = CustomType(Foo=BarType)
. This causes many issues with mypy (perhaps for good reasons?), but when fixing the framework is not within our abilities, we should at least have a way to suppress the various error types this causes globally in a file, otherwise I would need to add many line ignores into that file (I have an example hitting tens of valid-type errors in a single file) or ignore the file completely...Other things I've tried
1: mypy.ini based ignores
I tried using this in mypy.ini:
Fails because apparently disable_error_code can only toggle things globally, not per-module.
Doing this at global scope (
[mypy]
) worked, but that's not what I want.2: ignore-errors file setting
Is there any difference between adding:
# mypy: ignore-errors
versus this at the start of a file
# type: ignore
Both work for me, but both don't see to allow narrowing down the error...
3: inline config
# mypy: disable-error-code="valid_type"
Fails because apparently disable_error_code can only toggle things globally, not per-module.
The text was updated successfully, but these errors were encountered: