[Python-Dev] PEP 359: The "make" Statement

Steven Bethard steven.bethard at gmail.com
Thu Apr 13 21:47:41 CEST 2006


On 4/13/06, Ian D. Bollinger <ian.bollinger at gmail.com> wrote:
> I guess I fail to see how this syntax is a significant improvement over
> metaclasses (though __metaclass__ = xyz may not be the most aesthetic
> construct.)

It doesn't seem strange to you to have to use a *class* statement and
a __meta*class*__ hook to create something that's not a class at all? 
Consider
 >>> def get_dict(name, args, kwargs):
 ... return kwargs
 ...
 >>> class C(object):
 ... __metaclass__ = get_dict
 ... x = 1
 ... y = 2
 ...
 >>> C
 {'y': 2, 'x': 1, '__module__': '__main__', '__metaclass__':
<function get_dict at 0x00DB9F70>}
When I read a class statement, even if it specifies __metaclass__, I
assume that it will create a class object. I believe the average
reader of Python code will make similar assumptions. Sure, we can
abuse class/__metaclass__ to do something similar[1], but is that
really a good idea?
[1] Minor issue - you have to be okay with the class statement adding
__module__ and __metaclass__ to your dict.
Steve
--
Grammar am for people who can't think for myself.
 --- Bucky Katt, Get Fuzzy


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /