Skip to content
Myr

fix ParamType.to_info_dict() with no name

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

authored by Matthew Martin · committed by David Lord · parent 19be092 · Browse files · 4 files+19 added−1 removed
This commit

State

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

Diff stats

4 files+19 added−1 removed

  • tests:+7 added−0 removed
  • other:+12 added−1 removed

4 files+19 added−1 removed

modified:docs/shell-completion.rst+2 added
130 unmodified lines
131132.. code-block:: python133134 class EnvVarType(ParamType):135 name = "envvar"136137 def shell_complete(self, ctx, param, incomplete):138 return [139 CompletionItem(name)140 for name in os.environ if name.startswith(incomplete)
147 unmodified lines
modified:src/click/types.py+8 added-1 removed
61 unmodified lines
62 """63 # The class name without the "ParamType" suffix.64 param_type = type(self).__name__.partition("ParamType")[0]65 param_type = param_type.partition("ParameterType")[0]66 return {"param_type": param_type, "name": self.name}6667 # Custom subclasses might not remember to set a name.68 if hasattr(self, "name"):69 name = self.name70 else:71 name = param_type7273 return {"param_type": param_type, "name": name}7475 def __call__(76 self,77 value: t.Any,78 param: t.Optional["Parameter"] = None,
995 unmodified lines
modified:tests/test_info_dict.py+7 added
264 unmodified lines
265 "allow_interspersed_args": True,266 "ignore_unknown_options": False,267 "auto_envvar_prefix": None,268 }269270271def test_paramtype_no_name():272 class TestType(click.ParamType):273 pass274275 assert TestType().to_info_dict()["name"] == "TestType"
modified:CHANGES.rst+2 added
46 unmodified lines
47 a ``cls`` argument is used. :issue:`2211`48- A ``Group`` with ``invoke_without_command=True`` and ``chain=False``49 will invoke its result callback with the group function's return50 value. :issue:`2124`51- ``to_info_dict`` will not fail if a ``ParamType`` doesn't define a52 ``name``. :issue:`2168`535455Version 8.0.456-------------
948 unmodified lines