[Python-3000] Ambiguity in PEP 3115 and the args to __prepare__
Brett Cannon
brett at python.org
Sun Sep 2 19:43:34 CEST 2007
On 9/2/07, Guido van Rossum <guido at python.org> wrote:
> On 9/2/07, Brett Cannon <brett at python.org> wrote:
> > PEP 3115 says a metaclass' __prepare__ takes two positional arguments,
> > name and bases. But the example has it actually accept an arbitrary
> > number of arguments: name and then everything else is bound to bases.
> >
> > Which happens to be true? I'm too tired to even fully trust that I am
> > reading the PEP correctly, so I am not about to try to write an
> > example to see which is correct and come up with a coherent rewording
> > if I am right about what is wrong. =)
>
> I think you're misreading what you think is an example. I'm assuming
> you're referring to this code:
>
> def prepare_class(name, *bases, metaclass=None, **kwargs):
> if metaclass is None:
> metaclass = compute_default_metaclass(bases)
> prepare = getattr(metaclass, '__prepare__', None)
> if prepare is not None:
> return prepare(name, bases, **kwargs)
> else:
> return dict()
>
> This indeed *defines* a function with a *bases argument, but it is not
> called __prepare__! It *calls* __prepare__ passing it name and bases,
> i.e. the 2nd argument to prepare is a tuple of bases.
Ah, OK, that is the issue (that and type.__prepare__ takes any
arguments and just always returns a new dictionary). So it was the
lack of sleep. =)
-Brett
More information about the Python-3000
mailing list