-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Open
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
When inserting a class member during some other class member's __set_name__
call, the __set_name__
method of the newly-inserted member doesn't get called as expected.
As an example, take this snippet:
class I_Am_Altering_The_Deal:
def __set_name__(self, owner, name):
print(f"__set_name__({self.__class__.__name__}, {owner.__name__}, {name!r}")
owner.han_solo = Pray_I_Dont_Alter_It_Any_Further()
class Pray_I_Dont_Alter_It_Any_Further:
def __set_name__(self, owner, name):
print(f"__set_name__({self.__class__.__name__}, {owner.__name__}, {name!r}")
class Cloud_City:
luke_skywalker = I_Am_Altering_The_Deal()
I would expect both __set_name__
functions to be called, resulting in the output:
__set_name__(I_Am_Altering_The_Deal, Cloud_City, 'luke_skywalker')
__set_name__(Pray_I_Dont_Alter_It_Any_Further, Cloud_City, 'han_solo')
But what is actually output, is:
__set_name__(I_Am_Altering_The_Deal, Cloud_City, 'luke_skywalker')
Discovered while testing a PEP-487 implementation for Micropython: micropython/micropython#15503.
Maybe be related to #72983.
CPython versions tested on:
3.8, 3.10, 3.12
Operating systems tested on:
Linux
Metadata
Metadata
Assignees
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error