[Python-Dev] Submitting PEP 422 (Simple class initialization hook) for pronouncement

Antoine Pitrou solipsis at pitrou.net
Sun Feb 10 15:28:14 CET 2013


On Mon, 11 Feb 2013 00:09:55 +1000
Nick Coghlan <ncoghlan at gmail.com> wrote:
> 
> As far as the maintenance burden goes, the patch to enable PEP 422 for
> types.new_class() is trivial:
> 
> -    return meta(name, bases, ns, **kwds)
> +    cls = meta(name, bases, ns, **kwds)
> +    try:
> +        initcl = cls.__init_class__
> +    except AttributeError:
> +        pass
> +    else:
> +        initcl()
> +    return cls

I didn't know types.new_class(). I suppose that's because I'm not part
of the top half dozen people on the planet :-) I've stopped trying to
understand when I saw about the __build_class__ additions and whatnot.
I now consider that part of the language totally black magic.

I'm not sure it's a good thing when even some maintainers of the
language don't understand some of its (important) corners.

> The change in the builtin.__build_class__ implementation is similarly
> trivial (and has the same semantics), it's just more verbose due to
> its being written in C.

Sure, every little addition is "trivial". At the end you have a scary
monster made of many little trivial additions along the years, and
everyone has to take care not to break it.

Regards

Antoine.


More information about the Python-Dev mailing list