You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Setters should be able to accept a broader range of types than the getter as coercion or other conversions may take place.
Actual Behavior
It is not allowed:
main.py:6: error: Incompatible types in assignment (expression has type "str | int", variable has type "int") [assignment]
main.py:15: error: Name "myprop" is not defined [name-defined]
Found 2 errors in 1 file (checked 1 source file)
Your Environment
Mypy playground using version 1.11.2 and Python version 3.12. No options were set.
The text was updated successfully, but these errors were encountered:
See #3004, this is quite an old issue. One workaround you can do is to create a custom descriptor class, that will allow different types for get and set.
Bug Report
If you use the
@property
decorator and give your getter and setter different types, then mypy complains about it.To Reproduce
https://mypy-play.net/?mypy=latest&python=3.12&gist=3e608374fa0ce9363a3c22d015642d4b
Expected Behavior
Setters should be able to accept a broader range of types than the getter as coercion or other conversions may take place.
Actual Behavior
It is not allowed:
Your Environment
Mypy playground using version 1.11.2 and Python version 3.12. No options were set.
The text was updated successfully, but these errors were encountered: