On 4 Apr 2015 00:29, "Martin Teichmann" <[email protected]> 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.
_______________________________________________ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
