Author xitop
Recipients docs@python, xitop
Date 2021-09-14.16:40:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The object.__set_name__() function (introduced in Python 3.6 by PEP-487) is mentioned in the "what's new " summary as an extension to the descriptor protocol [1] and documented in the "implementing descriptors" section [2].

However, the PEP itself states that it "adds an __set_name__ initializer for class attributes, especially if they are descriptors.". And it indeed works for plain classes where the descriptor protocol is not used at all (no __get__ or __set__ or __delete__):

class NotDescriptor:
    def __set_name__(self, owner, name):
        print('__set_name__ called')
class SomeClass:
    attr = NotDescriptor()

It is clear that this method is helpful when used in descriptors and that is its intended use, but other valid use-cases probably exist.

I suggest to amend the documentation to clarify that (correct me if I'm wrong) the __set_name__ is called for every class used as an attribute in an other class, not only for descriptors.




Date User Action Args
2021-09-14 16:40:25xitopsetrecipients: + xitop, docs@python
2021-09-14 16:40:25xitopsetmessageid: <>
2021-09-14 16:40:25xitoplinkissue45198 messages
2021-09-14 16:40:24xitopcreate