[Python-3000] PEP 3115: Actual use cases for odd metaclasses? Alternate syntax.

Michele Simionato michele.simionato at gmail.com
Mon Jan 14 06:17:21 CET 2008


On Jan 13, 2008 7:55 PM, Charles Merriam <charles.merriam at gmail.com> wrote:
> Sorry, if my Italian is non-existent.  Code is code however.
>
> Could you verify that the article covers:
>
> 1.   Complaints that __metaclass__ will be silently ignored in PEP 3115.
>
> My understanding from the last line of the Rational section is that
> this is undecided.

I dunno, in Python 3.0a2 the __metaclass__ hook is silently ignored.
In Python 3.0 final there could be a warning, or the warning  could be
at the level of the 2to3 code convention tool. In any case Python 3.0
is expected to break with the past, I am not complaining much here.

> 2.  Complaints that, without _prepare_, the __new__ operation will not
> know which order the items were declared, and that everyone will write
> ordered hash implementations.

Ordered dictionaries are useful for a variety of purposes, and there are already
lots of implementations out there. The use case for them in __prepare__
is very *very* minor. My complaint about the lack of an ordered dictionary
in the standard library stands on its own, independently of metaclasses.

> You have a legitimate counter-argument that grouping the
> implementations of __add__ in the metaclass is cleaner than having
> them stand alone and be referenced in.   Is this your argument?

I am not sure if I understand you correctly.
In the paper I have a metaclass definining the methods
__new__, __eq__, __call__, __add__ and __repr__ in the class body.
In Python, the ability to define methods in the class body is purely
syntactic sugar. One
could just define the methods externally and attach them to the class
dictionary later on.
Or one could just have a single __new__ method taking a dictionary as argument
(even for ordinary classes) and setting all the methods, possibly with
a memoization mechanism,
since you don't want to reset all the methods at each instantiation.
However, everybody basically agrees that it is nicer to define the
methods in the class body
for ordinary classes, so why it should be different in metaclasses?
Special cases are not
special enough.

 Michele Simionato


More information about the Python-3000 mailing list