[issue1921] Confusing Descrintro example

Antti Rasinen report at bugs.python.org
Thu Jan 24 14:35:47 CET 2008


New submission from Antti Rasinen:

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...}

----------
components: Documentation
messages: 61631
nosy: arsatiki
severity: minor
status: open
title: Confusing Descrintro example
type: rfe
versions: Python 2.1.1, Python 2.1.2, Python 2.2, Python 2.2.1, Python 2.2.2, Python 2.2.3, Python 2.3, Python 2.4, Python 2.5, Python 2.6, Python 3.0

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1921>
__________________________________


More information about the Python-bugs-list mailing list