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 should fail if the first element of the type has the same name as the variable #17227

Open
userappgate opened this issue May 8, 2024 · 0 comments
Labels
bug mypy got something wrong topic-runtime-semantics mypy doesn't model runtime semantics correctly

Comments

@userappgate
Copy link

This example file.

import pathlib

class A:
    pathlib: pathlib.Path = pathlib.Path('/')
$ mypy test.py 
Success: no issues found in 1 source file

$ python3 test.py 
Traceback (most recent call last):
  File "/tmp/test.py", line 3, in <module>
    class A:
  File "/tmp/test.py", line 4, in A
    pathlib: pathlib.Path = pathlib.Path('/')
             ^^^^^^^^^^^^
AttributeError: 'PosixPath' object has no attribute 'Path'. Did you mean: 'match'?

Expected Behavior

I would expect mypy to fail, possibly explaining why.

Actual Behavior

It succeeds, even though the type annotations cause a failure.

Your Environment

  • Mypy version used: mypy 1.10.0 (compiled: yes)
  • Python version used: Python 3.11.9

I had thought incorrectly that it was an issue with attrs python-attrs/attrs#1282 but @euresti provided the example to re-create the problem.

@userappgate userappgate added the bug mypy got something wrong label May 8, 2024
@JelleZijlstra JelleZijlstra added the topic-runtime-semantics mypy doesn't model runtime semantics correctly label May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-runtime-semantics mypy doesn't model runtime semantics correctly
Projects
None yet
Development

No branches or pull requests

2 participants