Feature request: String-inferred names
Bruno Desthuilliers
bruno.42.desthuilliers at websiteburo.invalid
Mon Nov 30 11:35:24 EST 2009
Lie Ryan a écrit :
> On 11/28/2009 3:08 PM, The Music Guy wrote:
(snip the part about the proposed feature - which I don't like but
that's not the point)
>> My
>> projects rely on a lot of metaclassing for the automatic generation of
>> properties and methods, which saves tremendous amounts of coding.
>
> If you use it a lot, it is likely 1) you have abused class syntax for
> what should have been a dict or 2) what you need is to override
> __getattr__/__getattribute__ and __setattr__
I have to totally disagree here. The way the OP uses metaprogramming is
a really common and handy solution in lots of frameworks, and
drastically reduces the need for boilerplate (and the potential for
bugs). It's *WAY* cleaner (readability, introspection, doc etc) and far
less error-prone than going the __getattr(ibute)__ / __setattr__, and
also way more efficient (from execution time POV).
Using __getattr__ and __setattr__ to emulate attributes (usually
descriptors) that can be built at class creation time is IMHO what
should be labeled as an "abuse" (at best).
More information about the Python-list
mailing list