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

__spec__ incorrectly flagged as not existing in the global/module namespace #4145

Closed
brettcannon opened this issue Oct 20, 2017 · 4 comments · Fixed by #14739
Closed

__spec__ incorrectly flagged as not existing in the global/module namespace #4145

brettcannon opened this issue Oct 20, 2017 · 4 comments · Fixed by #14739
Labels
bug mypy got something wrong priority-1-normal topic-runtime-semantics mypy doesn't model runtime semantics correctly

Comments

@brettcannon
Copy link
Member

If you have code in a module that wants to access a module's __spec__ attribute through the global namespace, mypy claims that error: Name '__spec__' is not defined. E.g. @unittest.skipIf(__spec__ is None, '__spec__ is None'). This same issue doesn't come up for __name__ or __path__.

@brettcannon brettcannon changed the title __spec__ defined in a module's namespace is claimed as not defined __spec__ incorrectly flagged as not existing in the global/module namespace Oct 20, 2017
@gvanrossum
Copy link
Member

gvanrossum commented Oct 20, 2017 via email

@ilevkivskyi
Copy link
Member

I think this is similar to #1422, should be not hard to fix, but this requires an addition to implicit_module_attrs in nodes.py depending on Python version (IIUC they are not present in all versions).

@ilevkivskyi ilevkivskyi added bug mypy got something wrong priority-1-normal labels Oct 20, 2017
@brettcannon
Copy link
Member Author

@ilevkivskyi You're right, __spec__ didn't show up until Python 3.4.

@AlexWaygood AlexWaygood added the topic-runtime-semantics mypy doesn't model runtime semantics correctly label Mar 27, 2022
@achimnol
Copy link
Contributor

achimnol commented Feb 16, 2023

I just bumped on this. Could we add support for __spec__?

ref) lablup/backend.ai#1064

achimnol added a commit to lablup/backend.ai that referenced this issue Feb 16, 2023
hauntsaninja added a commit to hauntsaninja/mypy that referenced this issue Feb 20, 2023
Fixes python#4145

It was too annoying to get the fixtures to work out here, so I didn't.
But you can see the tests will add the None for the non `__main__` case
hauntsaninja added a commit that referenced this issue May 21, 2024
Fixes #4145

Co-authored-by: Joongi Kim <me@daybreaker.info>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-1-normal topic-runtime-semantics mypy doesn't model runtime semantics correctly
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants