Skip to content

0.981 @classmethod and @property can no longer be chained #13746

Closed as not planned

Description

@bzoracler

Class properties were introduced in Python 3.9, and used to be unanalysed in 0.971:

# mypy 0.971
class A:
    @property
    @classmethod
    def bad_class_property(cls) -> int:  # No mypy error
        return 8
    @classmethod
    @property
    def good_class_property(cls) -> int:  # No mypy error
        return 8
>>> A.bad_class_property
 <property at 0x...>
>>> A.good_class_property
8

Now, we have

# mypy 0.981
class A:
    @classmethod  # Only instance methods can be decorated with @property [misc]
    @property
    def good_class_property(cls) -> int:
        return 8

Activity

  1. erictraut commented on Sep 27, 2022

    @erictraut

    I don't know if this was related to the change in mypy 0.981, but chaining of property and classmethod has been deprecated in Python 3.11. More details can be found in the Python 3.11 release notes, but I'll quote the relevant part here:

    Chaining classmethod descriptors (introduced in bpo-19072) is now deprecated. It can no longer be used to wrap other descriptors such as property. The core design of this feature was flawed and caused a number of downstream problems.

  2. hauntsaninja commented on Sep 27, 2022

    @hauntsaninja
    Collaborator

    Yeah, this is from #13409. I don't think mypy should support property + classmethod, given that it's deprecated. But that can be discussed at #11619

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions