Skip to content

Abstract readable/writable properties support #11601

Closed
@sobolevn

Description

@sobolevn

This code is not considered valid by mypy:

from abc import abstractmethod

class Array(object):
    @property
    @abstractmethod
    def _length_(self) -> int: ...

    @_length_.setter
    @abstractmethod
    def _length_(self, value: int) -> None: ...

Output:

out/ex.py:4: error: Overloaded method has both abstract and non-abstract variants
out/ex.py:7: error: Decorated property not supported

But, this code is valid:

  1. It works in runtime
  2. It is documented here: https://docs.python.org/3/library/abc.html#abc.abstractproperty
  3. It has clear semantics: we need subclasses of this type to have a read/write property implementation

Refs python/typeshed#6361

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