Skip to content

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

Description

@mmdanggg2

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

fromtypingimportTypeVar, GenericT=TypeVar("T")
classA(Generic[T]):
def__init__(self, val: T):
self.member: T=valclassB(A[str]):
@propertydefmember(self) ->str:
return"bar"@member.setterdefmember(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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions