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

mypy does not recognize __qualname__ #6473

Closed
jtmoon79 opened this issue Feb 24, 2019 · 10 comments · Fixed by #16215
Closed

mypy does not recognize __qualname__ #6473

jtmoon79 opened this issue Feb 24, 2019 · 10 comments · Fixed by #16215
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-runtime-semantics mypy doesn't model runtime semantics correctly

Comments

@jtmoon79
Copy link

jtmoon79 commented Feb 24, 2019

  1. Given Python file test1.py
class A(object):
    NAME = __qualname__
  1. run mypy checking

    mypy test1.py
    
  2. BUG: mypy reports not defined

    test1.py:2: error: Name '__qualname__' is not defined
    

The Python interpreter runs the code without error.

__qualname__ has been available since Python 3.3.

Tested on Python 3.7.1, using mpypy 0.670.

@ilevkivskyi
Copy link
Member

Such kind of issues are typically easy to fix. You can look at how implicit_module_attrs() are implemented, and do the same for classes. Note however that we are currently migrating to a new semantic analyzer, so the fix should apply to both.

@ilevkivskyi ilevkivskyi added bug mypy got something wrong priority-1-normal good-first-issue false-positive mypy gave an error on correct code labels Feb 24, 2019
@jtmoon79
Copy link
Author

Thanks @ilevkivskyi . I'm curious, why was this Issue labeled "false-positive"?

@gvanrossum
Copy link
Member

The label "false-positive" refers to the fact that mypy gives an error where it shouldn't. It doesn't mean there's anything wrong with your bug report!

@aaalex5
Copy link

aaalex5 commented Apr 5, 2019

If no one is working on this issue, I'd like to give it a shot if possible. :)

@ilevkivskyi
Copy link
Member

Go ahead! But please be aware that we are currently working on big refactoring on semantic analyzer, so you will need to copy your fix to the newsemanal as well.

@aaalex5
Copy link

aaalex5 commented Apr 12, 2019

So I believe I fixed the issue within the normal mypy directory, but I'm not sure where in newsemanal it would be necessary to make a change? The only place I can think to make additions or changes would be in newsemanal/semanal_pass1.py, otherwise it doesn't look like there would be a change needed other than the one in mypy/mypy/nodes.py where implicit_module_attrs() is

@ilevkivskyi
Copy link
Member

I don't think using/changing implicit_module_attrs is the best solution. __qualname__ is only defined at class scope, at module scope it is a NameError. Probably we should have something like implicit_class_attrs.

@aaalex5
Copy link

aaalex5 commented Apr 20, 2019

Any tips on implementing that? implicit_module_attrs uses a set with 'module name attributes' keys and 'type' values so for an implicit_class_attrs would there be even be a 'type'? I'm just wondering if a set would even be the correct solution. Also, what other classes, if any, would you recommend I add?

@forrestchang
Copy link

@aaalex5 I started a pull request #7683.

@AlexWaygood AlexWaygood added the topic-runtime-semantics mypy doesn't model runtime semantics correctly label Apr 4, 2022
@asottile
Copy link
Contributor

asottile commented Oct 2, 2023

#10570 is a duplicate with slightly more details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-runtime-semantics mypy doesn't model runtime semantics correctly
Projects
None yet
8 participants