Skip to content

Using getattr() does not prevent attr-defined error #11348

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
jolaf opened this issue Oct 17, 2021 · 1 comment
Closed

Using getattr() does not prevent attr-defined error #11348

jolaf opened this issue Oct 17, 2021 · 1 comment
Labels
bug mypy got something wrong

Comments

@jolaf
Copy link
Contributor

jolaf commented Oct 17, 2021

The following code:

class A:
    pass

a = A()

if hasattr(a, 'v'):
    print(a.v)

print("OK")

produces the following ouput:

$ python3 test.py
OK

$ mypy test.py
test.py:7:11: error: "A" has no attribute "v"  [attr-defined]
        print(a.v)
              ^
Found 1 error in 1 file (checked 1 source file)

$ mypy --version
mypy 0.910

$ python3 --version
Python 3.8.10

$ cat /etc/issue
Ubuntu 20.04.3 LTS \n \l

$ uname -a
Linux ubuntu 5.4.0-88-generic #99-Ubuntu SMP Thu Sep 23 17:29:00 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
@jolaf jolaf added the bug mypy got something wrong label Oct 17, 2021
@emmatyping
Copy link
Member

Duplicate of #1424

@emmatyping emmatyping marked this as a duplicate of #1424 Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants