Skip to content
Myr

Add `cls` to signature of `argument` and `option`

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

authored by Gianluca Gippetto · committed by David Lord · parent 2a7543e · Browse files · 2 files+14 added−8 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+14 added−8 removed

  • other:+14 added−8 removed

2 files+14 added−8 removed

modified:src/click/decorators.py+12 added-8 removed
327 unmodified lines
328329 f.__click_params__.append(param) # type: ignore330331332def argument(*param_decls: str, **attrs: t.Any) -> _Decorator[FC]:332def argument(333 *param_decls: str, cls: t.Optional[t.Type[Argument]] = None, **attrs: t.Any334) -> _Decorator[FC]:335 """Attaches an argument to the command. All positional arguments are336 passed as parameter declarations to :class:`Argument`; all keyword337 arguments are forwarded unchanged (except ``cls``).338 This is equivalent to creating an :class:`Argument` instance manually
7 unmodified lines
346 :param param_decls: Passed as positional arguments to the constructor of347 ``cls``.348 :param attrs: Passed as keyword arguments to the constructor of ``cls``.349 """350 if cls is None:351 cls = Argument352353 def decorator(f: FC) -> FC:350 ArgumentClass = attrs.pop("cls", None) or Argument351 _param_memo(f, ArgumentClass(param_decls, **attrs))354 _param_memo(f, cls(param_decls, **attrs))355 return f356357 return decorator358359357def option(*param_decls: str, **attrs: t.Any) -> _Decorator[FC]:360def option(361 *param_decls: str, cls: t.Optional[t.Type[Option]] = None, **attrs: t.Any362) -> _Decorator[FC]:363 """Attaches an option to the command. All positional arguments are364 passed as parameter declarations to :class:`Option`; all keyword365 arguments are forwarded unchanged (except ``cls``).366 This is equivalent to creating an :class:`Option` instance manually
7 unmodified lines
374 :param param_decls: Passed as positional arguments to the constructor of375 ``cls``.376 :param attrs: Passed as keyword arguments to the constructor of ``cls``.377 """378 if cls is None:379 cls = Option380381 def decorator(f: FC) -> FC:375 # Issue 926, copy attrs, so pre-defined options can re-use the same cls=376 option_attrs = attrs.copy()377 OptionClass = option_attrs.pop("cls", None) or Option378 _param_memo(f, OptionClass(param_decls, **option_attrs))382 _param_memo(f, cls(param_decls, **attrs))383 return f384385 return decorator386
184 unmodified lines
modified:CHANGES.rst+2 added
22 unmodified lines
23- ``@group.command`` does not fail if the group was created with a custom24 ``command_class``. :issue:`2416`25- ``multiple=True`` is allowed for flag options again and does not require26 setting ``default=()``. :issue:`2246, 2292, 2295`27- Make the decorators returned by ``@argument()`` and ``@option()`` reusable when the28 ``cls`` parameter is used. :issue:`2294`293031Version 8.1.332-------------
1040 unmodified lines