Description
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:
[mypy-this-is-my.module]
disable_error_code = valid-type
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.