__set_name__ equivalent for instance

Dieter Maurer dieter at handshake.de
Thu Nov 16 14:30:28 EST 2023


Dom Grigonis wrote at 2023-11-16 21:11 +0200:
> ...
>> On 16 Nov 2023, at 21:00, Dieter Maurer <dieter at handshake.de> wrote:
>> ...
>> Methods are not bound during instance creation, they are bound during
>> access.
>
>Good to know. What is the criteria for binding then? Does it check if its type is `vanilla` function? If yes, is there any way to simulate it for arbitrary object?

Attribute access (including method binding) is documented in the
language reference.

Functions and descriptors accessed via an instance but found in a class (i.e.
not directly in the instance) are handled specially;
functions are bound. Other objects are returned as is.

`__getattribute__` can be used to take over control over the attribute
access.


More information about the Python-list mailing list