Skip to content
Myr

Pop the context after closing and not before. This fixes #412

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 7f1d70c · Browse files · 3 files+21 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+21 added−1 removed

  • tests:+19 added−0 removed
  • other:+2 added−1 removed

3 files+21 added−1 removed

modified:click/core.py+1 added-1 removed
316 unmodified lines
317 push_context(self)318 return self319320 def __exit__(self, exc_type, exc_value, tb):321 pop_context()321 self._depth -= 1322 if self._depth == 0:323 self.close()324 pop_context()325326 @contextmanager327 def scope(self, cleanup=True):328 """This helper method can be used with the context object to promote
1393 unmodified lines
modified:tests/test_context.py+19 added
182 unmodified lines
183184 result = runner.invoke(cli, ['test'])185 assert not result.exception186 assert result.output == 'test\n'187188189def test_close_before_pop(runner):190 called = []191192 @click.command()193 @click.pass_context194 def cli(ctx):195 ctx.obj = 'test'196 @ctx.call_on_close197 def foo():198 assert click.get_current_context().obj == 'test'199 called.append(True)200 click.echo('aha!')201202 result = runner.invoke(cli, [])203 assert not result.exception204 assert result.output == 'aha!\n'205 assert called == [True]
modified:CHANGES+1 added
12 unmodified lines
13- Actively reject multi commands within chained multi commands. This14 cannot be supported with the current setup of how the invocation for15 subcommands works.16- Explicitly disallow nargs=-1 with a set default.17- The context is now closed before it's popped from the stack.1819Version 5.120-----------21
251 unmodified lines