[issue32145] Wrong ExitStack Callback recipe

2018-01-01 Thread Nick Coghlan
Nick Coghlan added the comment: As per the comment at https://bugs.python.org/issue32445#msg309356, there's a bug in my suggested changes to `ExitStack.pop_all()`: the right method to call is ExitStack.push(), *not* ExitStack.callback() (the latter adds a wrapper function

[issue32145] Wrong ExitStack Callback recipe

2017-12-29 Thread Barry A. Warsaw
Barry A. Warsaw added the comment: On Dec 29, 2017, at 08:40, Nick Coghlan wrote: > > I'm not clear on what you mean about allowing arbitrary names for the > instance creation function - What I meant was that I don’t see `def _make_instance()`

[issue32145] Wrong ExitStack Callback recipe

2017-12-29 Thread Nick Coghlan
Nick Coghlan added the comment: I'm not clear on what you mean about allowing arbitrary names for the instance creation function - at that point we're back to subclasses not being able to use the default `pop_all()` implementation at all, and needing to duplicate the

[issue32145] Wrong ExitStack Callback recipe

2017-12-26 Thread Barry A. Warsaw
Barry A. Warsaw added the comment: On Dec 25, 2017, at 18:51, Nick Coghlan wrote: > > 3. A for-subclasses-only "self._clone()" API could work as follows: > >def _clone(self, new_instance=None): >if new_instance is None: >

[issue32145] Wrong ExitStack Callback recipe

2017-12-25 Thread Nick Coghlan
Nick Coghlan added the comment: Regarding super().__init__(): I added ExitStack to contextlib2 first, so I was thinking in the Py2/3 compatible subset when I wrote the original docs. We can freely change that for the standard library recipes. Regarding the "how to create

[issue32145] Wrong ExitStack Callback recipe

2017-12-10 Thread Barry A. Warsaw
Barry A. Warsaw added the comment: I wasn't even aware that pop_all() tries to create the concrete subtype. I wonder how common subclassing ExitStack is in practice. (Of course, the answer is that we'll never know.) For 3.7, we should probably delegate instance creation

[issue32145] Wrong ExitStack Callback recipe

2017-11-30 Thread Nick Coghlan
Nick Coghlan added the comment: Hmm, I think that may actually qualify as a bug in the `pop_all()` implementation: https://docs.python.org/3/library/contextlib.html#contextlib.ExitStack.pop_all states that it returns an ExitStack instance, not an instance of the current

[issue32145] Wrong ExitStack Callback recipe

2017-11-30 Thread Berker Peksag
Change by Berker Peksag : -- nosy: +ncoghlan type: crash -> behavior ___ Python tracker ___

[issue32145] Wrong ExitStack Callback recipe

2017-11-27 Thread Maurizio Zucchelli
New submission from Maurizio Zucchelli : The documentation for contextlib.ExitStack (https://docs.python.org/3.7/library/contextlib.html#replacing-any-use-of-try-finally-and-flag-variables) shows an helper class (Callback) to perform cleanup using a callback. Problem is,