Skip to content

@property hides multiple type errors #11892

Closed
@Dreamsorcerer

Description

@Dreamsorcerer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-descriptorsProperties, class vs. instance attributes

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions