Skip to content
Myr

remove deprecated callback parameter 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 9374365 · Browse files · 2 files+1 added−35 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+1 added−35 removed

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

2 files+1 added−35 removed

modified:src/click/core.py+1 added-19 removed
103 unmodified lines
104def batch(iterable, batch_size):105 return list(zip(*repeat(iter(iterable), batch_size)))106107108def invoke_param_callback(callback, ctx, param, value):109 code = getattr(callback, "__code__", None)110 args = getattr(code, "co_argcount", 3)111112 if args < 3:113 from warnings import warn114115 warn(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)124125108@contextmanager109def augment_usage_errors(ctx, param=None):110 """Context manager that attaches extra information to exceptions."""111 try:
1571 unmodified lines
1683 raise1684 value = None1685 if self.callback is not None:1686 try:1705 value = invoke_param_callback(self.callback, ctx, self, value)1687 value = self.callback(ctx, self, value)1688 except Exception:1689 if not ctx.resilient_parsing:1690 raise1691
396 unmodified lines
modified:tests/test_compat.py-16 removed
1import pytest23import click3from click._compat import should_strip_ansi4from click._compat import WIN568def test_legacy_callbacks(runner):9 def legacy_callback(ctx, value):10 return value.upper()1112 @click.command()13 @click.option("--foo", callback=legacy_callback)14 def cli(foo):15 click.echo(foo)1617 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.output21227def test_bash_func_name():8 from click._bashcomplete import get_completion_script910 script = get_completion_script("foo-bar baz_blah", "_COMPLETE_VAR", "bash").strip()
21 unmodified lines