On 4/13/06, Phillip J. Eby <[EMAIL PROTECTED]> wrote: > At 01:51 PM 4/13/2006 -0600, Steven Bethard wrote: > >Sorry, I'm not clear on exactly what you're suggesting. Are you > >suggesting I try to implement the make-statement using context > >managers? Or that I use a context manager to address Martin's > >problem? > > Yes. :) Both. Or neither. What I'm suggesting is that you implement the > *use cases* for the make statement using 'with' and a bit of getframe > hackery. Then, your PEP can be clearer as to whether there's actually any > significant advantage to having a "make" statement. > > IOW, if "make" isn't anything more than yet another way to spell class > decorators, metaclasses, or "with" statements, it's probably not a good > idea to add it to the language.
I'm against using anything with getframe hackery but here are the use cases written with the class/__metaclass__ abuse: class C(object): ... class x: __metaclass__ = property def get(self): ... def set(self): class ns: """This creates a namespace named ns with a badger attribute and a spam function""" __metaclass__ = namespace badger = 42 def spam(): ... class C(...): __metaclass__ = iterface ... Those should be mostly equivalent[1], except that all of the namespaces created will have additional __metaclass__ and __module__ attributes. The question is, is the intent still clear? When reading these, especially for the "namespace" example, I expect the result to be a class. The fact that it's not will be thoroughly confusing for anyone who doesn't know that metaclasses don't have to create class objects, and at least mildly misleading even for those who do understand metaclasses. Generally, the make statement has the advantage of not totally confusing your reader when your "class" statement creates something which is not a class at all. ;-) [1] So you don't have to check the PEP, here's what the make-statement versions look like: class C(object): ... make property x: def get(self): ... def set(self): ... make namespace ns: """This creates a namespace named ns with a badger attribute and a spam function""" badger = 42 def spam(): ... make interface C(...): ... STeVe -- Grammar am for people who can't think for myself. --- Bucky Katt, Get Fuzzy _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com