Skip to content

Mypy disallows overriding an attribute with a property #4125

Description

@rowillia

For example:

classFoo:
def__init__(self) ->None:
self.x=42classBar(Foo):
def__init__(self) ->None:
self.y=9000@propertydefx(self) ->int:
print('got x!!!')
returnself.y@x.setterdefx(self, value: int) ->None:
print('set x!!!')
self.y=value

This should be allowed as it doesn't violate LSP as long as x implements both a getter and a setter of the correct type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongfalse-positivemypy gave an error on correct codepriority-0-highrefactoringChanging mypy's internalstopic-descriptorsProperties, class vs. instance attributes

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions