I saw a tweet from Raymond Hettinger yesterday. He used __set_name__.
When I define __set_name__ method for my Class, the name becomes the instance's name. The owner became Foo, which is also expected but I couldn't figure out when and how this is useful.
class Bar:
def __set_name__(self, owner, name):
print(f'{self} was named {name} by {owner}')
class Foo:
x = Bar()
y = Bar()
That prints
<__main__.Bar object at 0x7f48f2968820> was named x by <class '__main__.Foo'>
<__main__.Bar object at 0x7f48f2968c70> was named y by <class '__main__.Foo'>
x = Bar('x')for example. This is a just a convenience for that.