[docs] [issue16048] Tutorial-classes-remarks: replace paragragh
Terry J. Reedy
report at bugs.python.org
Tue Sep 25 22:06:02 CEST 2012
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 at python
nosy: docs at python, terry.reedy
title: Tutorial-classes-remarks: replace paragragh
versions: Python 2.7, Python 3.2, Python 3.3
Python tracker <report at bugs.python.org>
More information about the docs