[Python-ideas] A way out of Meta-hell (was: A (meta)class algebra)

Nick Coghlan ncoghlan at gmail.com
Mon Feb 23 14:16:24 CET 2015


On 23 February 2015 at 01:15, Joao S. O. Bueno <jsbueno at python.org.br> wrote:
> On 22 February 2015 at 11:54, Nick Coghlan <ncoghlan at gmail.com> wrote:
>>
>> 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.
>
> Why not just "__decorate__" instead?

The first reason is because the immediate question that springs to
mind for me with that name is "decorate what?". The "auto" prefix
hints at the implicit nature of the decoration, as well as the fact
the decoration is inherited.

The second is because the hook is only relevant to the new implicit
decoration proposal, and not to decorators in general. Calling the
hook by the more general name __decorate__ suggests that it may also
play a role in explicit decorator invocation, and that's not the case.

Regards,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list