Skip to content
Myr

deprecate old param callback style

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

authored by David Lord · committed by David Lord · parent 38ba2e6 · 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
1310 unmodified lines
1437 in which case it's invoked when the default is needed1438 without any arguments.1439 :param callback: a callback that should be executed after the parameter1440 was matched. This is called as ``fn(ctx, param,1443 value)`` and needs to return the value. Before Click1444 2.0, the signature was ``(ctx, value)``.1441 value)`` and needs to return the value.1442 :param nargs: the number of arguments to match. If not ``1`` the return1443 value is a tuple instead of single value. The default for1444 nargs is ``1`` (except if the type is a tuple, then it's1445 the arity of the tuple).
585 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
64 unmodified lines
65- ZSH completion escapes special characters in values. :pr:`1418`66- Add completion support for Fish shell. :pr:`1423`67- Decoding bytes option values falls back to UTF-8 in more cases.68 :pr:`1468`69- Make the warning about old 2-arg parameter callbacks a deprecation70 warning, to be removed in 8.0. This has been a warning since Click71 2.0. :pr:`1492`727374Version 7.075-----------
540 unmodified lines