This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2012年09月25日 20:05 by terry.reedy, last changed 2022年04月11日 14:57 by admin. 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 |
| 2022年04月11日 14:57:36 | admin | set | github: 60252 |
| 2012年11月04日 04:36:42 | ezio.melotti | set | status: open -> closed superseder: Random Remarks in class documentation messages: + msg174752 resolution: duplicate stage: resolved |
| 2012年11月03日 15:59:26 | fossilet | set | nosy:
+ fossilet |
| 2012年09月29日 17:06:42 | berker.peksag | set | title: Tutorial-classes-remarks: replace paragragh -> Tutorial-classes-remarks: replace paragraph |
| 2012年09月28日 16:24:44 | eric.araujo | set | nosy:
+ eric.araujo messages: + msg171500 |
| 2012年09月27日 04:32:17 | cvrebert | set | nosy:
+ cvrebert |
| 2012年09月26日 13:08:43 | ezio.melotti | set | nosy:
+ ezio.melotti type: enhancement |
| 2012年09月25日 20:33:27 | terry.reedy | set | messages: + msg171318 |
| 2012年09月25日 20:15:43 | terry.reedy | set | messages: + msg171317 |
| 2012年09月25日 20:05:41 | terry.reedy | create | |