[issue16048] Tutorial-classes-remarks: replace paragragh

New submission from Terry J. Reedy: (from python-list thread "data attributes override method attributes?") "9.4. Random Remarks Data attributes override method attributes with the same name; to avoid accidental name conflicts, which may cause hard-to-find bugs in large programs, it is wise to use some kind of convention that minimizes the chance of conflicts. Possible conventions include capitalizing method names, prefixing data attribute names with a small unique string (perhaps just an underscore), or using verbs for methods and nouns for data attributes." The first semi-sentence is wrong. Within a class or instance attribute space, later assignments replace earlier ones. Between them, instance attributes (usually) override class attributes. The exceptions are (some? all?) special methods. One suggestion on the thread is to replace the clause with 'Instance attributes override class attributes', as that is the apparent intent, but the exception needs to be noted. The suggested Method and _data conventions are wrong in that they contradict PEP8 style. Peter Otten suggested that the convention suggestion be shortened to "To avoid name conflicts consider using verbs for methods and nouns for data attributes". ---------- assignee: docs@python components: Documentation messages: 171316 nosy: docs@python, terry.reedy priority: normal severity: normal status: open title: Tutorial-classes-remarks: replace paragragh versions: Python 2.7, Python 3.2, Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16048> _______________________________________

Terry J. Reedy added the comment: Peter Otten thought the first clause should instead be ""Data attributes and method attributes share the same namespace.", which is also true for a given object. This is a different intepretation of what the original author was getting at. The convention remark applies both within the class namespace and between class and instance namespaces. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16048> _______________________________________

Terry J. Reedy added the comment: Ian Kelly reminds me that instance.__xxx__ is only skipped by the internal machinery and not by direct accesses in user code. In the other hand, docs, official or otherwise, are filled with things like 'len(a) calls a.__len__', so I think something should be said that giving instances special method attributes does not have the effect one might expect. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16048> _______________________________________

Changes by Ezio Melotti <ezio.melotti@gmail.com>: ---------- nosy: +ezio.melotti type: -> enhancement _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16048> _______________________________________

Changes by Chris Rebert <pybugs@rebertia.com>: ---------- nosy: +cvrebert _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16048> _______________________________________

Éric Araujo added the comment: Well there is http://docs.python.org/reference/datamodel.html#special-method-names (even thought we have a lot of evidence people miss that). ---------- nosy: +eric.araujo _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16048> _______________________________________

Changes by Berker Peksag <berker.peksag@gmail.com>: ---------- title: Tutorial-classes-remarks: replace paragragh -> Tutorial-classes-remarks: replace paragraph _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16048> _______________________________________

Changes by Yongzhi Pan <fossilet@users.sourceforge.net>: ---------- nosy: +fossilet _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16048> _______________________________________

Ezio Melotti added the comment: This seems to be a duplicate of #12634. ---------- resolution: -> duplicate stage: -> committed/rejected status: open -> closed superseder: -> Random Remarks in class documentation _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16048> _______________________________________

Terry J. Reedy added the comment: Peter Otten thought the first clause should instead be ""Data attributes and method attributes share the same namespace.", which is also true for a given object. This is a different intepretation of what the original author was getting at. The convention remark applies both within the class namespace and between class and instance namespaces. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16048> _______________________________________

Terry J. Reedy added the comment: Ian Kelly reminds me that instance.__xxx__ is only skipped by the internal machinery and not by direct accesses in user code. In the other hand, docs, official or otherwise, are filled with things like 'len(a) calls a.__len__', so I think something should be said that giving instances special method attributes does not have the effect one might expect. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16048> _______________________________________

Changes by Ezio Melotti <ezio.melotti@gmail.com>: ---------- nosy: +ezio.melotti type: -> enhancement _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16048> _______________________________________

Changes by Chris Rebert <pybugs@rebertia.com>: ---------- nosy: +cvrebert _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16048> _______________________________________

Éric Araujo added the comment: Well there is http://docs.python.org/reference/datamodel.html#special-method-names (even thought we have a lot of evidence people miss that). ---------- nosy: +eric.araujo _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16048> _______________________________________

Changes by Berker Peksag <berker.peksag@gmail.com>: ---------- title: Tutorial-classes-remarks: replace paragragh -> Tutorial-classes-remarks: replace paragraph _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16048> _______________________________________

Changes by Yongzhi Pan <fossilet@users.sourceforge.net>: ---------- nosy: +fossilet _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16048> _______________________________________

Ezio Melotti added the comment: This seems to be a duplicate of #12634. ---------- resolution: -> duplicate stage: -> committed/rejected status: open -> closed superseder: -> Random Remarks in class documentation _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16048> _______________________________________
participants (6)
-
Berker Peksag
-
Chris Rebert
-
Ezio Melotti
-
Terry J. Reedy
-
Yongzhi Pan
-
Éric Araujo