[Python-ideas] An even simpler customization of class creation

Martin Teichmann lkb.teichmann at gmail.com
Sun Mar 1 10:27:43 CET 2015


> Aye, I like this design, it just wasn't until I saw it written out
> fully that it finally clicked why restricting it to subclasses let
> both zero-argument super() and explicit namespace access to the
> defining class both work. Getting the latter to also work is a
> definite strength of your approach over mine.

That said, I would love if it was just possible to use super() in
classmethods called from the __init__ of a metaclass. Until
now, the __class__ of a method is only initialized after
the metaclasses __init__ has run.

Fortunately, this is easily changeable: it is possible to move the
initialization of __class__ into type.__new__. As the class is
(typically) created there, that is about as early as possible.

I put the necessary changes to github:
https://github.com/tecki/cpython/commits/cell

> That leaves my one concern being the "namespace" keyword parameter.
> I'd started reconsidering that for PEP 422, and I think the argument
> holds at least as strongly for your improved design:
> https://www.python.org/dev/peps/pep-0422/#is-the-namespace-concept-worth-the-extra-complexity
>
> Since speed usually isn't a critical concern for class definitions,
> it's likely better to just make them ordered by default, which can be
> its own PEP, rather than being part of this one.

I feel the same way as you, so I am happy to drop the namespace
idea from PEP 487, but I agree that then ordered namespaces
would simply be great, but reading Eric's comment, that seems
just around the corner.

Greetings

Martin


More information about the Python-ideas mailing list