Skip to content
Myr

Merge branch '4.x-maintenance'

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

authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parents e62366f, 3ddc556 · Browse files · 3 files+26 added−4 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+26 added−4 removed

  • tests:+13 added−0 removed
  • other:+13 added−4 removed

3 files+26 added−4 removed

modified:click/types.py+12 added-4 removed
431 unmodified lines
432 def __init__(self, types):433 self.types = [convert_type(ty) for ty in types]434435 @property436 def name(self):437 return "<" + " ".join(ty.name for ty in self.types) + ">"438439 @property440 def arity(self):441 return len(self.types)442443 def convert(self, value, param, ctx):
6 unmodified lines
450def convert_type(ty, default=None):451 """Converts a callable or python ty into the most appropriate param452 ty.453 """454 guessed_type = False455 if ty is None and default is not None:456 if isinstance(default, tuple):457 ty = tuple(map(type, default))458 else:459 ty = type(default)460 guessed_type = True461462 if isinstance(ty, tuple):463 return Tuple(ty)464 if isinstance(ty, ParamType):465 return ty454 guessed_type = False455 if ty is None and default is not None:456 ty = type(default)457 guessed_type = True466 if ty is text_type or ty is str or ty is None:467 return STRING468 if ty is int:469 return INT
54 unmodified lines
modified:tests/test_options.py+13 added
154 unmodified lines
155 assert not result.exception156 assert "foo, bar" in result.output157 assert "1, 2" in result.output158159def test_multiple_default_type(runner):160 @click.command()161 @click.option("--arg1", multiple=True, default=('foo', 'bar'))162 @click.option("--arg2", multiple=True, default=(1, "a"))163 def cmd(arg1, arg2):164 assert all(isinstance(e[0],str) for e in arg1)165 assert all(isinstance(e[1],str) for e in arg1)166167 assert all(isinstance(e[0],int) for e in arg2)168 assert all(isinstance(e[1],str) for e in arg2)169170 result = runner.invoke(cmd, "--arg1 a b --arg1 test 1 --arg2 2 two --arg2 4 four".split())171 assert not result.exception172173def test_nargs_envvar(runner):174 @click.command()175 @click.option('--arg', nargs=2)176 def cmd(arg):
130 unmodified lines
modified:CHANGES+1 added
25 unmodified lines
26 a better error.27- Handle ^C in less-pager properly.28- Handle return value of `None` from `sys.getfilesystemencoding`29- Fix crash when writing to unicode files with `click.echo`.30- Fix type inference with multiple options.3132Version 4.033-----------34
207 unmodified lines