[New-bugs-announce] [issue45356] Calling `help` executes @classmethod @property decorated methods
Randolf Scholz
report at bugs.python.org
Sun Oct 3 15:45:55 EDT 2021
New submission from Randolf Scholz <randolf.scholz at gmail.com>:
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
----------
files: classmethod_property.py
messages: 403109
nosy: randolf.scholz
priority: normal
severity: normal
status: open
title: Calling `help` executes @classmethod @property decorated methods
type: behavior
versions: Python 3.10, Python 3.9
Added file: https://bugs.python.org/file50325/classmethod_property.py
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45356>
_______________________________________
More information about the New-bugs-announce
mailing list