Skip to content

globl "type: ignore" ignores too much #13435

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

Closed
socketpair opened this issue Aug 16, 2022 · 7 comments · Fixed by #13512
Closed

globl "type: ignore" ignores too much #13435

socketpair opened this issue Aug 16, 2022 · 7 comments · Fixed by #13512
Labels
bug mypy got something wrong documentation topic-type-ignore # type: ignore comments

Comments

@socketpair
Copy link

socketpair commented Aug 16, 2022

Structure:

sample_proj/__init__.py:

from sample_proj.commons import some_const
from sample_proj.some_file import SomeClass

sample_proj/comons.py:

some_const = 'qwe'

sample_proj/some_file.py:

# type: ignore

from sample_proj.commons import some_const


class SomeClass:
    def fun(self, param=some_const):
        pass
$ mypy sample_proj
sample_proj/__init__.py:2: error: Module "sample_proj.some_file" has no attribute "SomeClass"
Found 1 error in 1 file (checked 3 source files)

I think it's a bug.

Removing # type: ignore[union-attr] helps. I wanted this comment to ignore only this exact error in the whole file.

$ mypy --version
mypy 0.942
$ python3 --version
Python 3.10.5

@socketpair socketpair added the bug mypy got something wrong label Aug 16, 2022
@AlexWaygood AlexWaygood added the topic-type-ignore # type: ignore comments label Aug 16, 2022
@hauntsaninja
Copy link
Collaborator

Duplicate of #12076

@hauntsaninja hauntsaninja marked this as a duplicate of #12076 Aug 16, 2022
@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Aug 16, 2022
@socketpair
Copy link
Author

@hauntsaninja seems it's another bug. It's not about ignoring specific rule. Please reopen

@hauntsaninja hauntsaninja reopened this Aug 16, 2022
@socketpair socketpair changed the title type: ignore[<something>] ignores too much globl "type: ignore" ignores too much Aug 16, 2022
@socketpair
Copy link
Author

@hauntsaninja I have checked. Yes, just global ignore line still reproduces the bug (and I edited the example). Who to trigger for this issue ?

@hauntsaninja
Copy link
Collaborator

I think this is just the documented behaviour? https://mypy.readthedocs.io/en/stable/common_issues.html#ignoring-a-whole-file

@socketpair
Copy link
Author

@hauntsaninja I think no:

image

I understand as has the effect of ignoring [all type errors in] the entire module.

In my case, something different happens.

@hauntsaninja
Copy link
Collaborator

Yes, in your case mypy ignores that entire module.

You probably want the ignore_errors configuration:
https://mypy.readthedocs.io/en/stable/config_file.html#confval-ignore_errors
You can do this inline using:
https://mypy.readthedocs.io/en/stable/inline_config.html

So something like # mypy: ignore-errors should do what you want.

I agree that this is confusing, but not sure how to change in a backward compatible manner. (I'm also here for fun and am not personally motivated to fix confusing mypy configuration)

@socketpair
Copy link
Author

OK I will try. But could you fix the documentation? I mean correcting the ambiguity of the phrase above.

hauntsaninja added a commit to hauntsaninja/mypy that referenced this issue Aug 25, 2022
Per-module error codes were added in python#13502, let's recommend using them.

The existing type ignore behaviour is pretty unintuitive; I think most
people actually want `# mypy: ignore-errors`. There are probably people
depending on the current behaviour though.

Fixes python#13435, fixes python#12076, fixes python#11999, fixes python#11027, fixes python#9318,
fixes python#7839
hauntsaninja added a commit that referenced this issue Aug 26, 2022
Per-module error codes were added in #13502, let's recommend using them.

The existing type ignore behaviour is pretty unintuitive; I think most
people actually want `# mypy: ignore-errors`. There are probably people
depending on the current behaviour though.

Fixes #13435, fixes #12076, fixes #11999, fixes #11027, fixes #9318,
fixes #7839
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong documentation topic-type-ignore # type: ignore comments
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants