On 14 September 2016 at 05:46, Ralph Broenink <ra...@ralphbroenink.net> wrote:
> Hi all,
>
> On Tue, 13 Sep 2016 at 18:30 Chris Angelico <ros...@gmail.com> wrote:
>>
>> Did you know that you can actually abuse decorators to do this with
>> existing syntax? Check out this collection of evil uses of decorators:
>>
>> https://github.com/Rosuav/Decorators/blob/master/evil.py
>
> There's also this  post from Guido a few years back in python-dev, which
> does something similar using metaclasses:
>
> https://mail.python.org/pipermail/python-dev/2008-January/076194.html
>
> I'm not sure it does exactly the same, but it is also an interesting
> approach. (Although I like the decorator syntax more.) The discussion that
> follows in that thread may also be of interest for this discussion.

PEP 422 and its reference implementation had a more fleshed out
implementation of that concept:
https://www.python.org/dev/peps/pep-0422/#new-ways-of-using-classes

With class namespaces becoming ordered by default, I ended up
withdrawing PEP 422 in favour of the simpler PEP 487 that's actually
in 3.6: https://www.python.org/dev/peps/pep-0487/

I do think Pim's proposal is an excellent exemplar of what a PEP
should be, and if we *did* want to make class extension easier than it
already is, then the suggested "continue class ..." syntax would be an
elegant way of spelling it.

However, I also believe the proposal founders on:

1. Class extensions are a fundamentally bad idea from a
maintainability perspective, as they make the original class
definition incomplete with no local indicator of its lack of
completeness (hence the "don't do this" caveat on the relevant example
in PEP 422)
2. There are already ways to do this using metaclasses that provide a
local indicator at the point of definition that the affected class is
extensible (i.e. the use of the custom metaclass, or inheritance from
a base class that uses it) and hence that the given definition may be
incomplete

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to