[Python-3000] PEP for Metaclasses in Python 3000
ncoghlan at gmail.com
Tue Mar 13 10:16:42 CET 2007
Guido van Rossum wrote:
> On 3/9/07, Steven Bethard <steven.bethard at gmail.com> wrote:
>> I'd rather __metacreate__ be called something like __createdict__,
>> __creationdict__, __metadict__, __getmetadict__, etc. where it's
>> clearer that the purpose is to create a dict object.
> Agreed; there's no need that the attribute name contains the word
> 'meta' again, that's already implied in it being an attribute of the
Along similar lines, I'd be marginally happier with:
class Bob(meta=Planet): pass
over what is currently proposed in the PEP. Repeating the 'class' part
within a single line feels redundant.
> On 3/9/07, Brett Cannon <brett at python.org> wrote:
>> Do the keywords have to follow the metaclass keyword, or is order
>> irrelevant? While order makes sense, it would be a new precedent for
>> keyword arguments to have an important order.
> I'd like the syntax between () to be identical to that for a function
> call, i.e. including *args and **kwds. That way the cognitive load for
> the user is the smallest. Sorting out the semantics of the keywords is
> purely a runtime activity anywaty.
I like this idea.
I think the signature of the method that creates the namespace
dictionary requires some further thought though:
- is it intended to typically be a static method or a class method of
the metaclass? (as it will be called before __new__, an instance method
of the metaclass wouldn't make sense)
- is the metaclass passed in to the namespace creation function as a
normal keyword argument, or is it automatically removed by the
interpreter? (note that implementing it as a class method would still
allow access to the actual metaclass)
- if the metaclass is derived rather than passed in explicitly, is the
'meta' argument still passed in to the namespace creation function?
- what's the actual signature of the new function?
The answers to these will be somewhat intertwined - if the 'meta'
keyword argument is always going to be passed in to the function, then
it makes more sense to use a static method in the typical case. If the
meta keyword is stripped (or only provided when passed in explicitly),
then a class method is needed in order to reliably get at the metaclass
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-3000