Type stub for a property setter that is supposed to normalise its input into but is unsafe #861
-
I'm trying to figure out how best to type the https://github.com/aws/aws-xray-sdk-python/blob/master/aws_xray_sdk/core/recorder.py#L544 Its intention looks to be to allow the user to pass in either:
BUT because it does a positive check for a [This stack overflow question/answer[(https://stackoverflow.com/questions/66595278/what-should-the-type-annotation-for-a-python-property-setters-argument-be) covers this scenario but from the perspective of the code owner. As I'm writing a stub I have no ability to change the internals of the method. I want to type it as the compatible types ( Should I just type the setter |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This is a known mypy bug: python/mypy#3004 A decent workaround would be |
Beta Was this translation helpful? Give feedback.
This is a known mypy bug: python/mypy#3004
A decent workaround would be
Any | DefaultDynamicNaming
. It's not great for the setter, because it means that any object is accepted. But for the getter, it is not same as justAny
like you might expect: if you dovalue_from_getter.foo
for example, mypy will complain thatDefaultDynamicNaming
has no attributefoo
, because it would be valid only if both union members had that attribute.