[New-bugs-announce] [issue45198] __set_name__ documentation not clear about its usage with non-descriptor classes
report at bugs.python.org
Tue Sep 14 12:40:25 EDT 2021
New submission from xitop <reg.bugs at poti.sk>:
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  and documented in the "implementing descriptors" section .
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__):
def __set_name__(self, owner, name):
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.
assignee: docs at python
nosy: docs at python, xitop
title: __set_name__ documentation not clear about its usage with non-descriptor classes
versions: Python 3.6, Python 3.7, Python 3.8, Python 3.9
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce