Closed
Labels
bugmypy got something wrongmypy got something wrongtopic-descriptorsProperties, class vs. instance attributesProperties, class vs. instance attributes
Description
Bug Report
This code defines self._body as Optional[bytes] and does not produce any type errors: https://github.com/aio-libs/aiohttp/blob/f1eb09b3756f4ed378a25f8a634f734952d2da35/aiohttp/web_response.py#L589
If I instead define the type on the class, like:
class Response(StreamResponse):
_body: Optional[bytes]
Then I get a type error: Incompatible types in assignment (expression has type "Optional[bytes]", base class "StreamResponse" defined the type as "None") [assignment]
To Reproduce
See next comment.
Your Environment
- Mypy version used: 0.930 (but, those type errors must have been there for months already)
- Mypy configuration options from
mypy.ini: https://github.com/aio-libs/aiohttp/blob/master/.mypy.ini
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-descriptorsProperties, class vs. instance attributesProperties, class vs. instance attributes
Activity
Dreamsorcerer commentedon Jan 3, 2022
OK, seems to be a problem with
@property, managed to create a minimal reproducer. This produces no type errors, but there are actually 2 issues in this code:[-]Incompatible types not recognised in some situations[/-][+]@property hides mulitple type errors[/+][-]@property hides mulitple type errors[/-][+]@property hides multiple type errors[/+]Dreamsorcerer commentedon Jan 4, 2022
It also causes incorrect type errors. If I try to assign to a property, it will give a type error if the type does not match the return type, when it should be checking the parameter type in the setter:
hauntsaninja commentedon Jan 5, 2022
mypy doesn't do setters that take different types particularly well, see #3004 There's been some movement on that issue recently, so hopefully gets fixed soon
AlexWaygood commentedon Mar 27, 2022
On 0.941, mypy now does report one of these errors (but still not the other one):
Support properties with setter type different from getter type (pytho…
Support properties with setter type different from getter type (pytho…