[issue32145] Wrong ExitStack Callback recipe

Barry A. Warsaw report at bugs.python.org
Tue Dec 26 11:58:39 EST 2017


Barry A. Warsaw <barry at python.org> added the comment:

On Dec 25, 2017, at 18:51, Nick Coghlan <report at bugs.python.org> wrote:
> 
> 3. A for-subclasses-only "self._clone()" API could work as follows:
> 
>    def _clone(self, new_instance=None):
>        if new_instance is None:
>            new_instance = type(self)()
>        # Clone state here
>        return new_instance
> 
> Then subclasses could override *just* the instance creation part by doing:
> 
>    def _clone(self):
>        return super()._clone(self._make_instance())
> 
> While also being free to add their own additional state copying code if needed.

So _make_instance() wouldn’t be part of ExitStack’s API, but subclasses could implement it (and name it whatever they want of course)?

I’m not sure _clone() is the right name here since that implies to me state copy as well, and I totally agree with your other points.  That’s why I originally suggested _make_instance() would be the name and API in the base class.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32145>
_______________________________________


More information about the Python-bugs-list mailing list