Issue1921
Created on 2008-01-24 13:35 by arsatiki, last changed 2008-01-24 20:39 by christian.heimes.
| msg61631 (view) |
Author: Antti Rasinen (arsatiki) |
Date: 2008-01-24 13:35 |
|
Guido's document "Unifying types and classes in Python 2.2" (descrintro)
contains a confusing example for metaclass newbies.
<http://www.python.org/download/releases/2.2.3/descrintro/#metaclass_examples>
The example in question is autoprop, which uses the variable "name" in
three different contexts. First, it is the name of the class being
created. Second, it is used in a for loop to denote the keys of the
class dict. And thirdly, it is used to denote substrings of a subset of
those keys.
Upon my first encounter with the example, I found myself staring at the
getattr and setattr lines in disbelief. I associated "name" as the
parameter given to the __init__ function.
I'd propose changing the first for-loop name to "member" or similar
and the second to "propname" or "prop".
Furthermore, a modern version of the same example could use sets and set
comprehensions instead of dict.keys():
props = {member[5:] for member in dict if member.startswith...}
|
|
| Date |
User |
Action |
Args |
| 2008-01-24 20:39:56 | christian.heimes | set | priority: low keywords:
+ easy versions:
- Python 2.5, Python 2.4, Python 2.3, Python 2.2.3, Python 2.2.2, Python 2.2.1, Python 2.2, Python 2.1.2, Python 2.1.1 |
| 2008-01-24 13:35:46 | arsatiki | create | |
|