[Python-ideas] Define a method or function attribute outside of a class with the dot operator

Kyle Lahnakoski klahnakoski at mozilla.com
Fri Feb 10 09:59:03 EST 2017


On 2017-02-10 05:44, Markus Meskanen wrote:
>
>
> On Fri, Feb 10, 2017 at 12:29 PM, Stephan Houben <stephanh42 at gmail.com
> <mailto:stephanh42 at gmail.com>> wrote:
>
>     What about using a simple decorator instead?
>
>     def monkey_patch(cls):
>         return lambda func: setattr(cls, func.__name__, func)
>

I suggest naming the decorator with something less generic than
"monkey_patch", like "extension_method".





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170210/a45e2ce9/attachment.html>


More information about the Python-ideas mailing list