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

False negative when narrowing attribute type in subclass #12942

Closed
LeeeeT opened this issue Jun 5, 2022 · 1 comment
Closed

False negative when narrowing attribute type in subclass #12942

LeeeeT opened this issue Jun 5, 2022 · 1 comment
Labels
bug mypy got something wrong topic-inheritance Inheritance and incompatible overrides

Comments

@LeeeeT
Copy link

LeeeeT commented Jun 5, 2022

Bug Report

Mypy doesn't complain about redefining an attribute in a subclass with a narrower type. I expect the following code to produce a static type checking error:

class A:
    f: object

class B(A):
    f: float

Since this will fail:

b = B()

a: A = b
a.f = "abc"

b.f.is_integer()

Your Environment

  • Mypy version used: 0.960
  • Mypy configuration options: strict=true
  • Python version used: 3.10
@LeeeeT LeeeeT added the bug mypy got something wrong label Jun 5, 2022
@AlexWaygood AlexWaygood added the topic-inheritance Inheritance and incompatible overrides label Jun 5, 2022
@hauntsaninja
Copy link
Collaborator

Thanks, duplicate of #3208

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-inheritance Inheritance and incompatible overrides
Projects
None yet
Development

No branches or pull requests

3 participants