Open sterliakov opened 1 year ago
I think that asymmetric properties sound very based and I have personally voted for that issue. I'd totally add support for them if that's what the community is asking for.
The current functionality of basedmypy is that the types on setter
s and deleter
s are inferred from the type of the getter
. This is not enforced and is only a convenience feature, you are free to override the inference by manually specifying the annotations:
class A:
_foo = 0
@property
def foo(self) -> int:
return self._foo
@foo.setter
def(self, value: object):
self._foo = value if isinstance(value, int) else 0
Obviously you will currently see the same error as you would with mypy.
Currently asymmetric properties are not supported by
mypy
. Itmypy
this is considered a bug with high priority (issue).basemypy
decided to go this way further and assume that properties are symmetric even without annotations on setter. To quote docs:I suggest to think about this solution and consider allowing asymmetric properties, because cases like below with value normalization are quire common.
Code sample: