[issue9538] Replace confusing pseudoname 'object' in special methods section.
New submission from Terry J. Reedy <tjreedy@udel.edu>: In 3.3. Special method names, 'object' is used as a pseudo class name to prefix all the special method entries. This conflicts with the usual two Python meanings. 1. 'object' is the name of a specific class. So the entry for object.__getattribute__(self, name) says to avoid circularity by calling object.__getattribute__(self, name), which looks circular and requires a bit a mental work by the reader to properly understand. Ditto for object.__setattr__(self, name, value) calling object.__setattr__(self, name, value) 2. Non-specifically, 'object' is usually understood to mean any Python object, not just a class. But the signatures as written require that 'object' specifically be a class and 'object' does not convey that. So for both reasons, I propose that the pseudoname 'object' be replaces with 'class' or 'someclass' ---------- assignee: docs@python components: Documentation messages: 113194 nosy: docs@python, georg.brandl, terry.reedy priority: normal severity: normal stage: needs patch status: open title: Replace confusing pseudoname 'object' in special methods section. versions: Python 3.2 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9538> _______________________________________
Terry J. Reedy <tjreedy@udel.edu> added the comment: I also think that in "In order to avoid infinite recursion in this method, its implementation should always call the base class method with the same name to access any attributes it needs, for example, object.__getattribute__(self, name).", 'the base class' should be 'a base class' or 'a superclass' since there might be more than one base/super class. Ditto for __setattr__. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9538> _______________________________________
Terry J. Reedy <tjreedy@udel.edu> added the comment: I filed this because I just reread the __getattr(ibute)__ entries to respond to #8722 and found myself again stumbling over the 'object' confusion. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9538> _______________________________________
Éric Araujo <merwok@netwok.org> added the comment: Good catch! Names listed under language reference section 3.3.1 actually all exist on object, e.g. object.__new__¹. It is section 3.3.2 that lists names that *can* be defined but don’t have a default implementation on object, so +1 on using “someclass” here to be clear. Oh, and let’s change “class” to “someclass” too in the examples under 3.3.4, to use valid syntax and consistent naming. I think we should not change “the base class”, since even with multiple bases a class still has one most immediate parent, found in cls.__base__ (a.k.a. cls.__bases__[0]). ¹ with the exception of __bool__ and the lack of __reduce{_ex,}__ and __subclasshook__; I’ll open a bug about those. ---------- nosy: +merwok _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9538> _______________________________________
peter recore added the comment: Here is a patch that implements Eric's suggestion. I am a new contributor and would welcome feedback on if this is correct or not. ---------- keywords: +patch nosy: +peterrecore Added file: http://bugs.python.org/file29815/issue9538.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9538> _______________________________________
Georg Brandl added the comment: Note that Sphinx searches for "object.__foo__" when :meth:`__foo__` is used; this change will break all those links. For that reason I'm -1 to this change: I don't see the perceived issue as problematic anyway. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9538> _______________________________________
peter recore added the comment: George, When I build the docs with my changes, the links from the method names seem to work the same way as they do in the existing docs. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9538> _______________________________________
Terry J. Reedy added the comment: The problem, for me, is that in 3.3 Data Model, 'object' is being used with a 3rd meaning, 'generic class' (or possibly 'subclass of object', if indeed every 'class' must be 'object' subclass, in the strict sense of 'object'). This is in addition to 'object' the specific class and generic Python object (which in CPython is a PyObject structure instance). The normal two meanings are often differentiated by typography: normal type for plain old object, something else for *object*. To add a bit to the confusion, 3.3.4. Customizing instance and subclass checks changes the prefix to 'class' instead of 'object' (which is what I would do in the whole section...) class.__instancecheck__(self, instance) class.__subclasscheck__(self, subclass) It then goes on to explain that it does not really mean 'generic class' but 'type/metaclass'. So, to me, the prefix here should really be 'metaclass'. Peter, the patch applied fine to my copy of default. It is incomplete in that the replacement should be made everywhere or nowhere in 3.3, not just in 3.3.2(.0) and 3.3.2.1. However, do not bother making a new patch until there is more agreement on a change than there is now. A possible alternative to the given proposal is an explanation in the short 3.3 header of the special use of 'object' within the section. ---------- versions: +Python 3.3, Python 3.4 -Python 3.2 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue9538> _______________________________________
Change by Irit Katriel <iritkatriel@yahoo.com>: ---------- versions: +Python 3.10, Python 3.8, Python 3.9 -Python 3.3, Python 3.4 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue9538> _______________________________________
participants (5)
-
Georg Brandl
-
Irit Katriel
-
peter recore
-
Terry J. Reedy
-
Éric Araujo