-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Closed
Labels
3.11only security fixesonly security fixestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = 'https://github.com/rhettinger'
closed_at = None
created_at = <Date 2021-10-03.19:45:55.963>
labels = ['type-bug', '3.11']
title = 'Calling `help` executes @classmethod @property decorated methods'
updated_at = <Date 2022-02-17.20:03:40.349>
user = 'https://github.com/randolf-scholz'
bugs.python.org fields:
activity = <Date 2022-02-17.20:03:40.349>
actor = 'rhettinger'
assignee = 'rhettinger'
closed = False
closed_date = None
closer = None
components = []
creation = <Date 2021-10-03.19:45:55.963>
creator = 'randolf.scholz'
dependencies = []
files = ['50325', '50326', '50344']
hgrepos = []
issue_num = 45356
keywords = ['patch']
message_count = 23.0
messages = ['403109', '403110', '403111', '403504', '403505', '403578', '403582', '403611', '403613', '403653', '403699', '403713', '405100', '405115', '405121', '405142', '405143', '406600', '406605', '406606', '407493', '407499', '413451']
nosy_count = 13.0
nosy_names = ['rhettinger', 'terry.reedy', 'grahamd', 'lukasz.langa', 'berker.peksag', 'serhiy.storchaka', 'wim.glenn', 'corona10', 'pablogsal', 'andrei.avk', 'sirosen0', 'randolf.scholz', 'AlexWaygood']
pr_nums = ['29239']
priority = 'normal'
resolution = None
stage = 'patch review'
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue45356'
versions = ['Python 3.11']
Linked PRs
Metadata
Metadata
Assignees
Labels
3.11only security fixesonly security fixestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
randolf-scholz commentedon Oct 3, 2021
I noticed some strange behaviour when calling
help
on a class inheriting from a class or having itself @classmethod @Property decorated methods.Calling
help(MyClass)
will causeexpensive_class_property
to be executed 4 times (!)The other two properties,
expensive_instance_property
andexpensive_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 andexpensive_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
randolf-scholz commentedon Oct 3, 2021
I updated the script with dome more info. The class-property gets actually executed 5 times when calling
help(MyClass)
AlexWaygood commentedon Oct 3, 2021
See also: https://bugs.python.org/issue44904
terryjreedy commentedon Oct 8, 2021
Randolf, what specific behaviors do you consider to be bugs that should be fixed. What would a test of the the changed behavior look like?
This should perhaps be closed as a duplicate of bpo-44904. Randolf, please check and say what you thing.
terryjreedy commentedon Oct 8, 2021
On current 3.9, 3.10, 3.11, on Windows running in IDLE, I see
computing class property ..
computing class property ..
computing class property ..
computing class property ..
computing class property ..
Help ...
randolf-scholz commentedon Oct 10, 2021
@terry I think the problem boils down to the fact that
@classmethod @property
decorated methods end up not being real properties.Calling
MyBaseClass.__dict__
reveals:Two main issues:
isinstance(func, property)
. Of course, this could be fixed by the tool-makers by doing a conditional check:expensive_class_property
does not implementgetter
,setter
,deleter
. This seems to be the real dealbreaker, for example, if we doThen the first line erroneously executes, such that MyBaseClass.dict['expensive_class_property'] is now
int
instead ofclassmethod
, while the second line correctly raisesAttributeError: can't set attribute
since the setter method is not implemented.randolf-scholz commentedon Oct 10, 2021
If fact, in the current state it seem that it is impossible to implement real class-properties, for a simple reason:
descriptor.__set__ is only called when setting the attribute of an instance, but not of a class!!
rhettinger commentedon Oct 10, 2021
I'm merging bpo-44904 into this one because they are related.
87 remaining items