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 disallows overriding a generic type attribute with a property #18189

Open
mmdanggg2 opened this issue Nov 25, 2024 · 0 comments
Open

Mypy disallows overriding a generic type attribute with a property #18189

mmdanggg2 opened this issue Nov 25, 2024 · 0 comments
Labels
bug mypy got something wrong topic-inheritance Inheritance and incompatible overrides topic-type-variables

Comments

@mmdanggg2
Copy link

Bug Report

If I have a generic class with an attribute of a generic type, when creating a concrete subclass, overriding that attribute with a correctly typed property raises an error. Similar to #4125

To Reproduce

from typing import TypeVar, Generic

T = TypeVar("T")

class A(Generic[T]):
    def __init__(self, val: T):
        self.member: T = val

class B(A[str]):
    @property
    def member(self) -> str:
        return "bar"
    
    @member.setter
    def member(self, val: str):
        pass

Actual Behavior

property_issue.py:10: error: Signature of "member" incompatible with supertype "A"  [override]
property_issue.py:10: note:      Superclass:
property_issue.py:10: note:          T
property_issue.py:10: note:      Subclass:
property_issue.py:10: note:          str

Your Environment

  • Mypy version used: 1.9.0
  • Mypy command-line flags: -
  • Mypy configuration options from mypy.ini (and other config files): -
  • Python version used: 3.9.13
@mmdanggg2 mmdanggg2 added the bug mypy got something wrong label Nov 25, 2024
@brianschubert brianschubert added topic-type-variables topic-inheritance Inheritance and incompatible overrides labels Nov 25, 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-inheritance Inheritance and incompatible overrides topic-type-variables
Projects
None yet
Development

No branches or pull requests

2 participants