Skip to content
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

Add support for classmethod property from python3.9 #11619

Closed
YaN-3k opened this issue Nov 25, 2021 · 5 comments
Closed

Add support for classmethod property from python3.9 #11619

YaN-3k opened this issue Nov 25, 2021 · 5 comments
Labels
feature topic-descriptors Properties, class vs. instance attributes

Comments

@YaN-3k
Copy link

YaN-3k commented Nov 25, 2021

class Foo:
    @classmethod
    @property
    def bar(cls) -> str:
        return cls.__name__ 


def foo_bar(msg: str) -> None:
    print(msg)

foo_bar(Foo.bar)

mypy --python-version 3.9 test.py
test.py:11: error: Argument 1 to "foo_bar" has incompatible type "Callable[[], str]"; expected "str"
Found 1 error in 1 file (checked 1 source file)

As stated in https://docs.python.org/3.9/library/functions.html#classmethod this new classmethod property is completely valid so mypy shouldn't report an error.

@YaN-3k YaN-3k added the bug mypy got something wrong label Nov 25, 2021
@AlexWaygood
Copy link
Member

AlexWaygood commented Nov 25, 2021

It might be worth noting that there are currently active discussions on whether to deprecate the ability to stack @classmethod on top of @property, as it's responsible for a lot of bugs in cpython

@AlexWaygood
Copy link
Member

It might be worth noting that there are currently active discussions on whether to deprecate the ability to stack @classmethod on top of @property, as it's responsible for a lot of bugs in cpython

To update: this behaviour has now been deprecated in 3.11 (python/cpython#92379)

@headtr1ck
Copy link

This has been deprecated in python 3.11 it is still correct syntax in python <3.11.
However, it is still semantically incorrent and mypy is right in complaining (the property decorator is not returning what you think it returns).

Maybe one could simply improve the error message for this case?

HippocampusGirl added a commit to HALFpipe/HALFpipe that referenced this issue Oct 20, 2022
- Unsupported syntax for Python 3.11
  python/mypy#11619
@karlicoss
Copy link

Would it be possible to change the error category from misc to something more specific? Then it would be easy to suppress it on older python versions

@hauntsaninja
Copy link
Collaborator

This behaviour has been deprecated in CPython, so mypy will not be adding support for it.

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

No branches or pull requests

5 participants