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

Allow error-code specific whole-file # type: ignores #10304

Closed
koenlek opened this issue Apr 9, 2021 · 3 comments
Closed

Allow error-code specific whole-file # type: ignores #10304

koenlek opened this issue Apr 9, 2021 · 3 comments
Labels
feature topic-type-ignore # type: ignore comments

Comments

@koenlek
Copy link

koenlek commented Apr 9, 2021

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.

@koenlek koenlek added the feature label Apr 9, 2021
@DevilXD
Copy link

DevilXD commented Apr 15, 2021

Looks like a duplicate of #9440

@koenlek
Copy link
Author

koenlek commented Apr 15, 2021

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?

Perhaps once we support:

[mypy-tests.*]
disable_error_code = ["valid_type"]

We could easily support something like this in files too? Though file-level != module-level so that could challenge implementing this?

# mypy: disable-error-code=["valid_type"]

@JelleZijlstra JelleZijlstra added the topic-type-ignore # type: ignore comments label Mar 19, 2022
@hauntsaninja
Copy link
Collaborator

Fixed by #13502

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature topic-type-ignore # type: ignore comments
Projects
None yet
Development

No branches or pull requests

4 participants