[Python-Dev] PEP 487 vs 422 (dynamic class decoration) (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Fri Apr 3 17:04:38 CEST 2015
- Previous message (by thread): [Python-Dev] PEP 487 vs 422 (dynamic class decoration)
- Next message (by thread): [Python-Dev] PEP 487 vs 422 (dynamic class decoration)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 4 Apr 2015 00:29, "Martin Teichmann" <lkb.teichmann at gmail.com> wrote:
> When I first wrote PEP 422 I was of the view that "Python 2 allows > class definition postprocessing injection, we should allow it in > Python 3 as well". I've since changed my view to "Having to declare > post-processing of a class definition up front as a decorator, base > class or metaclass is a good thing for readability, as otherwise > there's nothing obvious when reading a class definition that tells you > whether or not postprocessing may happen, so you have to assume its > possible for every class definition". Nick, I couldn't agree more with you, yet I think PJ actually brought up a very interesting point. Post-processing is a very common thing these days, and has been re-written so many times that I think it is about time that something like it should be in the standard library. I'm less thinking about decorated methods, more about descriptors. They always have the problem that they don't know which attribute they belong to, so every author of a framework that defines descriptors writes a metaclass which goes through all the descriptors and tells them their attribute name.
Extending the descriptor protocol to include a per-descriptor hook that's called at class definition time sounds like a potentially nice way to go to me. While you could still use it to arbitrarily mutate the class object, it's much clearer that's not the intended purpose, so I don't see it as a major problem.
Cheers, Nick. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20150404/5df72b2b/attachment.html>
- Previous message (by thread): [Python-Dev] PEP 487 vs 422 (dynamic class decoration)
- Next message (by thread): [Python-Dev] PEP 487 vs 422 (dynamic class decoration)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]