Message403699
Some thoughts from me, as an unqualified but interested party:
Like Randolph, I very much like having class properties in the language, and have used them in several projects since their introduction in 3.9. I find they're especially useful with Enums. However, while the bug in doctest, for example, is relatively trivial to fix (see my PR in #44904), it seems to me plausible that bugs might crop up in other standard library modules as well. As such, leaving class properties in the language might mean that several more bugfixes relating to this feature would have to be made in the future. So, I can see the argument for removing them.
It seems to me that Randolph's idea of changing `classmethod` from a class into a function would break a lot of existing code. As an alternative, one small adjustment that could be made would be to special-case `isinstance()` when it comes to class properties. In pure Python, you could achieve this like this:
```
oldproperty = property
class propertymeta(type):
def __instancecheck__(cls, obj):
return super().__instancecheck__(obj) or (
isinstance(obj, classmethod)
and super().__instancecheck__(obj.__func__)
)
class property(oldproperty, metaclass=propertymeta): pass
```
This would at least mean that `isinstance(classmethod(property(lambda cls: 42)), property)` and `isinstance(classmethod(property(lambda cls: 42)), classmethod)` would both evaluate to `True`. This would be a bit of a lie (an instance of `classmethod` isn't an instance of `property`), but would at least warn the caller that the object they were dealing with had some propertylike qualities to it.
Note that this change wouldn't fix the bugs in abc and doctest, nor does it fix the issue with class-property setter logic that Randolph identified.
With regards to the point that `@staticmethod` cannot be stacked on top of `@property`: it strikes me that this feature isn't really needed. You can achieve the same effect just by stacking `@classmethod` on top of `@property` and not using the `cls` parameter. |
|
Date |
User |
Action |
Args |
2021-10-11 22:43:14 | AlexWaygood | set | recipients:
+ AlexWaygood, rhettinger, terry.reedy, berker.peksag, serhiy.storchaka, wim.glenn, corona10, randolf.scholz |
2021-10-11 22:43:14 | AlexWaygood | set | messageid: <1633992194.85.0.611012456713.issue45356@roundup.psfhosted.org> |
2021-10-11 22:43:14 | AlexWaygood | link | issue45356 messages |
2021-10-11 22:43:14 | AlexWaygood | create | |
|