Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

False positives when overriding attributes in superclasses defined with function definitions #17513

Open
bzoracler opened this issue Jul 10, 2024 · 0 comments
Labels
bug mypy got something wrong

Comments

@bzoracler
Copy link
Contributor

bzoracler commented Jul 10, 2024

Bug Report, To Reproduce, & Actual Behaviour

When overriding an attribute created with a function definition statement in the superclass, subclasses complain about type mismatch of the function definition type itself, instead of the entire statement (that is, with all the decorators applied). See mypy Playground:

class A:
    @str
    def attr(self, /) -> None: ...

class B(A):
    attr: str  # mypy: Incompatible types in assignment (expression has type "str", base class "A" defined the type as "Callable[[A], None]")  [assignment]

This is an artificial but minimum example; the actual use case is for a custom descriptor which has similar flexibility to builtins.property, allowing declaration & definition with both decorators (like @property) and assignments (like attr = property(...)).

Expected Behavior

No issues

Your Environment

  • Mypy version used: 1.10.1, master
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.10, 3.12
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant