Skip to content

Abstract readable/writable properties support #11601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sobolevn opened this issue Nov 23, 2021 · 3 comments
Closed

Abstract readable/writable properties support #11601

sobolevn opened this issue Nov 23, 2021 · 3 comments
Labels
bug mypy got something wrong topic-descriptors Properties, class vs. instance attributes

Comments

@sobolevn
Copy link
Member

sobolevn commented Nov 23, 2021

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

@sobolevn sobolevn added the bug mypy got something wrong label Nov 23, 2021
@AlexWaygood
Copy link
Member

This is #1362, no?

@sobolevn
Copy link
Member Author

It is related, but we have one more extra warning: Overloaded method has both abstract and non-abstract variants

@AlexWaygood AlexWaygood added the topic-descriptors Properties, class vs. instance attributes label Mar 24, 2022
@AlexWaygood
Copy link
Member

Closing as a duplicate of #4165

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-descriptors Properties, class vs. instance attributes
Projects
None yet
Development

No branches or pull requests

2 participants