Skip to content

Add support for classmethod property from python3.9 #11619

Closed as not planned
Closed as not planned

Description

@YaN-3k
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.

Activity

  1. AlexWaygood commented on Nov 25, 2021

    @AlexWaygood
    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

  2. added
    topic-descriptorsProperties, class vs. instance attributes
    and removed
    bugmypy got something wrong
    on Mar 24, 2022
  3. AlexWaygood commented on May 29, 2022

    @AlexWaygood
    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)

  4. headtr1ck commented on Sep 29, 2022

    @headtr1ck

    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?

  5. added a commit that references this issue on Oct 20, 2022
  6. karlicoss commented on Mar 20, 2023

    @karlicoss

    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

  7. hauntsaninja commented on Apr 27, 2023

    @hauntsaninja
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions