Skip to content
Myr

Merge pull request #1492 from pallets/deprecate-legacy-callback

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

deprecate old param callback style

authored by David Lord · committed by GitHub · parents 7239794, f605f95 · Browse files · 3 files+9 added−9 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+9 added−9 removed

  • tests:+1 added−1 removed
  • other:+8 added−8 removed

3 files+9 added−9 removed

modified:src/click/core.py+5 added-8 removed
108 unmodified lines
109 code = getattr(callback, "__code__", None)110 args = getattr(code, "co_argcount", 3)111112 if args < 3:113 # This will become a warning in Click 3.0:113 from warnings import warn114115 warn(117 Warning(118 "Invoked legacy parameter callback '{}'. The new"119 " signature for such callbacks starting with Click 2.0"120 " is (ctx, param, value).".format(callback)121 ),116 "Parameter callbacks take 3 args, (ctx, param, value). The"117 " 2-arg style is deprecated and will be removed in 8.0.".format(callback),118 DeprecationWarning,119 stacklevel=3,120 )121 return callback(ctx, value)122123 return callback(ctx, param, value)124125126@contextmanager
1377 unmodified lines
1504 in which case it's invoked when the default is needed1505 without any arguments.1506 :param callback: a callback that should be executed after the parameter1507 was matched. This is called as ``fn(ctx, param,1510 value)`` and needs to return the value. Before Click1511 2.0, the signature was ``(ctx, value)``.1508 value)`` and needs to return the value.1509 :param nargs: the number of arguments to match. If not ``1`` the return1510 value is a tuple instead of single value. The default for1511 nargs is ``1`` (except if the type is a tuple, then it's1512 the arity of the tuple). If ``nargs=-1``, all remaining
593 unmodified lines
modified:tests/test_compat.py+1 added-1 removed
12 unmodified lines
13 @click.option("--foo", callback=legacy_callback)14 def cli(foo):15 click.echo(foo)1617 with pytest.warns(Warning, match="Invoked legacy parameter callback"):17 with pytest.warns(DeprecationWarning, match="2-arg style"):18 result = runner.invoke(cli, ["--foo", "wat"])19 assert result.exit_code == 020 assert "WAT" in result.output21
26 unmodified lines
modified:CHANGES.rst+3 added
77 unmodified lines
78- ZSH completion escapes special characters in values. :pr:`1418`79- Add completion support for Fish shell. :pr:`1423`80- Decoding bytes option values falls back to UTF-8 in more cases.81 :pr:`1468`82- Make the warning about old 2-arg parameter callbacks a deprecation83 warning, to be removed in 8.0. This has been a warning since Click84 2.0. :pr:`1492`858687Version 7.088-----------
541 unmodified lines