[Python-ideas] A way out of Meta-hell (was: A (meta)class algebra)
Nick Coghlan
ncoghlan at gmail.com
Sun Feb 22 15:54:45 CET 2015
On 23 February 2015 at 00:25, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On 22 Feb 2015 21:36, "Martin Teichmann" <lkb.teichmann at gmail.com> wrote:
>> Another detail: I think it could be useful if the additional
>> **kwargs to the class statement were forwarded to
>> __(sub)class_init__.
>
> No, that kind of variable signature makes cooperative multiple inheritance a
> nightmare to implement. The PEP 422 hook is deliberately designed to act
> like an inheritable class decorator that gets set from within the body of
> the class definition.
>
> It's *not* intended to provide the full power and flexibility offered by a
> metaclass - it's designed to let folks that understand class decorators and
> class methods combine the two concepts to define a class decorator that gets
> called implicitly for both the current class and all subclasses.
Ah, thank you: this discussion kicked a new naming idea lose in my
brain, so I just pushed an update to PEP 422 that renames the proposed
__init_class__ hook to be called __autodecorate__ instead.
"It's an implicitly invoked class decorator that gets inherited by
subclasses" is really the best way to conceive of the proposed hook,
so having "init" as part of the name not only made it hard to remember
whether the hook was __init_class__ or __class_init__, it also got
people thinking along completely the wrong lines.
By contrast, the "auto" in "autodecorate" only makes sense as a
prefix, and the inclusion of the word "decorate" in the name means it
should be far more effective at triggering the reader's "class
decorator" mental model rather than their "class initialisation" one.
Regards,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list