Skip to content

What to do about setters of a different type than their property? #3004

Description

@sixolet

Consider this code:

importtypingclassA:
@propertydeff(self) ->int:
return1@f.setter# Possible error for defining a setter that doesn't accept the type the @property returnsdeff(self, x: str) ->None:
passa=A()
a.f=''# Possibly not an error, but currently mypy gives an errora.f=1# Certainly should be an error, unless we disallowed # defining the setter this way in the first place.reveal_type(a.f) # E: Revealed type is 'builtins.int'

Whatever we decide, I'm happy to build a PR; I have this code loaded into my head.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions