Skip to content

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

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
bzoracler opened this issue Sep 27, 2022 · 2 comments
Closed

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

bzoracler opened this issue Sep 27, 2022 · 2 comments

Comments

@bzoracler
Copy link
Contributor

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
@erictraut
Copy link

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.

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

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Sep 27, 2022
thozza added a commit to thozza/osbuild that referenced this issue Apr 11, 2023
Fix the following errors:

```
osbuild/util/lvm2.py:117: error: Only instance methods can be decorated with @Property
osbuild/api.py:50: error: Only instance methods can be decorated with @Property
osbuild/sources.py:85: error: Only instance methods can be decorated with @Property
```

Chaining of `@classmethod` and `@property` has been deprecated since
Python 3.11 with a note that chaining didn't work correctly in some
cases.

Relevant links:
python/mypy#13746
https://docs.python.org/3.11/whatsnew/3.11.html#language-builtins

Signed-off-by: Tomáš Hozza <[email protected]>
thozza added a commit to thozza/osbuild that referenced this issue Apr 11, 2023
Fix the following errors:

```
osbuild/util/lvm2.py:117: error: Only instance methods can be decorated with @Property
osbuild/api.py:50: error: Only instance methods can be decorated with @Property
osbuild/sources.py:85: error: Only instance methods can be decorated with @Property
```

Chaining of `@classmethod` and `@property` has been deprecated since
Python 3.11 with a note that chaining didn't work correctly in some
cases.

Relevant links:
python/mypy#13746
https://docs.python.org/3.11/whatsnew/3.11.html#language-builtins

Signed-off-by: Tomáš Hozza <[email protected]>
thozza added a commit to osbuild/osbuild that referenced this issue Apr 12, 2023
Fix the following errors:

```
osbuild/util/lvm2.py:117: error: Only instance methods can be decorated with @Property
osbuild/api.py:50: error: Only instance methods can be decorated with @Property
osbuild/sources.py:85: error: Only instance methods can be decorated with @Property
```

Chaining of `@classmethod` and `@property` has been deprecated since
Python 3.11 with a note that chaining didn't work correctly in some
cases.

Relevant links:
python/mypy#13746
https://docs.python.org/3.11/whatsnew/3.11.html#language-builtins

Signed-off-by: Tomáš Hozza <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants