[Python-3000] Ambiguity in PEP 3115 and the args to prepare (original) (raw)

Guido van Rossum guido at python.org
Sun Sep 2 17:07:55 CEST 2007


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.

The only example defining prepare later in the PEP takes two positional arguments (name and bases again).

-- --Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-3000 mailing list