Skip to content
Myr

Do not warn about callback changes until 3.0

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 56e68e2 · Browse files · 2 files+18 added−16 removed
This commit

State

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

Diff stats

2 files+18 added−16 removed

  • tests:+12 added−11 removed
  • other:+6 added−5 removed

2 files+18 added−16 removed

modified:click/core.py+6 added-5 removed
36 unmodified lines
37 code = getattr(callback, '__code__', None)38 args = getattr(code, 'co_argcount', 3)3940 if args < 3:41 # This will become a warning in Click 3.041 from warnings import warn42 warn(Warning('Invoked legacy parameter callback "%s". The new '43 'signature for such callbacks starting with '44 'Click 2.0 is (ctx, param, value).'45 % callback), stacklevel=3)42 ##from warnings import warn43 ##warn(Warning('Invoked legacy parameter callback "%s". The new '44 ## 'signature for such callbacks starting with '45 ## 'Click 2.0 is (ctx, param, value).'46 ## % callback), stacklevel=3)47 return callback(ctx, value)48 return callback(ctx, param, value)4950
1203 unmodified lines
modified:tests/test_compat.py+12 added-11 removed
1import click234if click.__version__ >= '3.0':4def test_legacy_callbacks(runner):5 def legacy_callback(ctx, value):6 return value.upper()5 def test_legacy_callbacks(runner):6 def legacy_callback(ctx, value):7 return value.upper()88 @click.command()9 @click.option('--foo', callback=legacy_callback)10 def cli(foo):11 click.echo(foo)9 @click.command()10 @click.option('--foo', callback=legacy_callback)11 def cli(foo):12 click.echo(foo)1313 result = runner.invoke(cli, ['--foo', 'wat'])14 assert result.exit_code == 015 assert 'WAT' in result.output16 assert 'Invoked legacy parameter callback' in result.output14 result = runner.invoke(cli, ['--foo', 'wat'])15 assert result.exit_code == 016 assert 'WAT' in result.output17 assert 'Invoked legacy parameter callback' in result.output