Skip to content
Myr

inline command decorator code

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 4a88877 · Browse files · 1 file+19 added−28 removed
This commit

State

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

Diff stats

1 file+19 added−28 removed

  • other:+19 added−28 removed

1 file+19 added−28 removed

modified:src/click/decorators.py+19 added-28 removed
119 unmodified lines
120 )121 return decorator122123124def _make_command(125 f: F,126 name: t.Optional[str],127 attrs: t.MutableMapping[str, t.Any],128 cls: t.Type[Command],129) -> Command:130 if isinstance(f, Command):131 raise TypeError("Attempted to convert a callback into a command twice.")132133 try:134 params = f.__click_params__ # type: ignore135 params.reverse()136 del f.__click_params__ # type: ignore137 except AttributeError:138 params = []139140 if attrs.get("help") is None:141 attrs["help"] = inspect.getdoc(f)142143 return cls(144 name=name or f.__name__.lower().replace("_", "-"),145 callback=f,146 params=params,147 **attrs,148 )149150124@t.overload125def command(126 name: t.Optional[str] = None,127 cls: t.Optional[t.Type[Command]] = None,
47 unmodified lines
175 func = name176 name = None177178 def decorator(f: t.Callable[..., t.Any]) -> Command:206 cmd = _make_command(f, name, attrs, cls) # type: ignore179 if isinstance(f, Command):180 raise TypeError("Attempted to convert a callback into a command twice.")181182 try:183 params = f.__click_params__ # type: ignore184 params.reverse()185 del f.__click_params__ # type: ignore186 except AttributeError:187 params = []188189 if attrs.get("help") is None:190 attrs["help"] = inspect.getdoc(f)191192 cmd = cls( # type: ignore[misc]193 name=name or f.__name__.lower().replace("_", "-"), # type: ignore[arg-type]194 callback=f,195 params=params,196 **attrs,197 )198 cmd.__doc__ = f.__doc__199 return cmd200201 if func is not None:
275 unmodified lines