[New-bugs-announce] [issue33265] contextlib.ExitStack abuses __self__
report at bugs.python.org
Thu Apr 12 01:24:51 EDT 2018
New submission from Jeroen Demeyer <J.Demeyer at UGent.be>:
In contextlib, there is code which roughly looks like
def _exit_wrapper(exc_type, exc, tb):
return cm_exit(cm, exc_type, exc, tb)
_exit_wrapper.__self__ = cm
This creates a new function _exit_wrapper from a given function cm_exit by prepending the __self__ attribute to *args. Now this is exactly what a method does too.
It would be better to use an actual method for this: it's cleaner, faster and it doesn't abuse a double-underscore attribute. The latter will actually break with PEP 575, as __self__ will become a special name instead of an arbitrary attribute.
components: Library (Lib)
title: contextlib.ExitStack abuses __self__
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce