Message403109
I noticed some strange behaviour when calling `help` on a class inheriting from a class or having itself @classmethod @property decorated methods.
```python
from time import sleep
from abc import ABC, ABCMeta, abstractmethod
class MyMetaClass(ABCMeta):
@classmethod
@property
def expensive_metaclass_property(cls):
"""This may take a while to compute!"""
print("computing metaclass property"); sleep(3)
return "Phew, that was a lot of work!"
class MyBaseClass(ABC, metaclass=MyMetaClass):
@classmethod
@property
def expensive_class_property(cls):
"""This may take a while to compute!"""
print("computing class property .."); sleep(3)
return "Phew, that was a lot of work!"
@property
def expensive_instance_property(self):
"""This may take a while to compute!"""
print("computing instance property ..."); sleep(3)
return "Phew, that was a lot of work!"
class MyClass(MyBaseClass):
"""Some subclass of MyBaseClass"""
help(MyClass)
```
Calling `help(MyClass)` will cause `expensive_class_property` to be executed 4 times (!)
The other two properties, `expensive_instance_property` and `expensive_metaclass_property` are not executed.
Secondly, only `expensive_instance_property` is listed as a read-only property; `expensive_class_property` is listed as a classmethod and `expensive_metaclass_property` is unlisted.
The problem is also present in '3.10.0rc2 (default, Sep 28 2021, 17:57:14) [GCC 10.2.1 20210110]'
Stack Overflow thread: https://stackoverflow.com/questions/69426309 |
|
Date |
User |
Action |
Args |
2021-10-03 19:45:56 | randolf.scholz | set | recipients:
+ randolf.scholz |
2021-10-03 19:45:55 | randolf.scholz | set | messageid: <1633290355.98.0.210301350099.issue45356@roundup.psfhosted.org> |
2021-10-03 19:45:55 | randolf.scholz | link | issue45356 messages |
2021-10-03 19:45:55 | randolf.scholz | create | |
|