classification
Title: Tutorial-classes-remarks: replace paragraph
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Random Remarks in class documentation
View: 12634
Assigned To: docs@python Nosy List: cvrebert, docs@python, eric.araujo, ezio.melotti, fossilet, terry.reedy
Priority: normal Keywords:

Created on 2012-09-25 20:05 by terry.reedy, last changed 2012-11-04 04:36 by ezio.melotti. This issue is now closed.

Messages (5)
msg171316 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012-09-25 20:05
(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".
msg171317 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012-09-25 20:15
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.
msg171318 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012-09-25 20:33
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.
msg171500 - (view) Author: √Čric Araujo (eric.araujo) * (Python committer) Date: 2012-09-28 16:24
Well there is http://docs.python.org/reference/datamodel.html#special-method-names (even thought we have a lot of evidence people miss that).
msg174752 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-11-04 04:36
This seems to be a duplicate of #12634.
History
Date User Action Args
2012-11-04 04:36:42ezio.melottisetstatus: open -> closed
superseder: Random Remarks in class documentation
messages: + msg174752

resolution: duplicate
stage: resolved
2012-11-03 15:59:26fossiletsetnosy: + fossilet
2012-09-29 17:06:42berker.peksagsettitle: Tutorial-classes-remarks: replace paragragh -> Tutorial-classes-remarks: replace paragraph
2012-09-28 16:24:44eric.araujosetnosy: + eric.araujo
messages: + msg171500
2012-09-27 04:32:17cvrebertsetnosy: + cvrebert
2012-09-26 13:08:43ezio.melottisetnosy: + ezio.melotti
type: enhancement
2012-09-25 20:33:27terry.reedysetmessages: + msg171318
2012-09-25 20:15:43terry.reedysetmessages: + msg171317
2012-09-25 20:05:41terry.reedycreate