[issue1921] Confusing Descrintro example

Guido van Rossum report at bugs.python.org
Sat Jul 11 18:45:56 CEST 2009


Guido van Rossum <guido at python.org> added the comment:

I'm guessing you weren't ready for learning about metaclasses if you
didn't get the fact that 'name' was the loop control variable in the two
different loops.  The example is only 11 lines long!

Still, I'm fine with the two suggested renames.

I'm not fine with rewriting the example using modern constructs, since
it is part of the docs for Python 2.2.  Perhaps the doc is still useful
but then it should be first moved into the regular doc tree and *then*
adapted to modern times (and we can't really release that version until
2.7 and 3.2 are released).

Unfortunately I do not have a checkout of the website handy any more (or
I can't remember where I put it).  Maybe one of the webmasters can make
the suggested fixes?

The fixed code that I agree with is:

class autoprop(type):
    def __init__(cls, name, bases, dict):
	super(autoprop, cls).__init__(name, bases, dict)
	props = {}
	for member in dict.keys():
            if member.startswith("_get_") or member.startswith("_set_"):
		props[member[5:]] = 1
	for prop in props.keys():
            fget = getattr(cls, "_get_%s" % prop, None)
            fset = getattr(cls, "_set_%s" % prop, None)
            setattr(cls, prop, property(fget, fset))

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1921>
_______________________________________


More information about the Python-bugs-list mailing list