summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lord <davidism@gmail.com>2022-02-20 09:00:13 -0800
committerGitHub <noreply@github.com>2022-02-20 09:00:13 -0800
commitc9c406bebdf2b027864216fb881278a8bfa14bb8 (patch)
tree13b84b2c729bdce5877a84fb131c70332332523b
parent166b31261f55ba3126456bbc2ff9e16142115e56 (diff)
parentf85a35daa401b1aa2e9303e092890884fd11a890 (diff)
downloadclick-c9c406bebdf2b027864216fb881278a8bfa14bb8.tar.gz
Merge pull request #1965 from janluke/fix/handle-none
Across the codebase, handle the case a keyword argument is provided but set to `None`
-rw-r--r--CHANGES.rst3
-rw-r--r--src/click/core.py4
-rw-r--r--src/click/decorators.py9
3 files changed, 10 insertions, 6 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 93db491..c11361c 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -24,6 +24,9 @@ Version 8.1.0
:issue:`1961`
- ``Command.show_default`` overrides ``Context.show_default``, instead
of the other way around. :issue:`1963`
+- Parameter decorators and ``@group`` handles ``cls=None`` the same as
+ not passing ``cls``. ``@option`` handles ``help=None`` the same as
+ not passing ``help``. :issue:`#1959`
Version 8.0.4
diff --git a/src/click/core.py b/src/click/core.py
index 4b96767..604d8ba 100644
--- a/src/click/core.py
+++ b/src/click/core.py
@@ -1819,7 +1819,7 @@ class Group(MultiCommand):
"""
from .decorators import command
- if self.command_class is not None and "cls" not in kwargs:
+ if self.command_class and kwargs.get("cls") is None:
kwargs["cls"] = self.command_class
func: t.Optional[t.Callable] = None
@@ -1863,7 +1863,7 @@ class Group(MultiCommand):
func = args[0]
args = args[1:]
- if self.group_class is not None and "cls" not in kwargs:
+ if self.group_class is not None and kwargs.get("cls") is None:
if self.group_class is type:
kwargs["cls"] = type(self)
else:
diff --git a/src/click/decorators.py b/src/click/decorators.py
index a8c6d2d..a2fbadd 100644
--- a/src/click/decorators.py
+++ b/src/click/decorators.py
@@ -244,7 +244,8 @@ def group(
.. versionchanged:: 8.1
This decorator can be applied without parentheses.
"""
- attrs.setdefault("cls", Group)
+ if attrs.get("cls") is None:
+ attrs["cls"] = Group
if callable(name):
grp: t.Callable[[F], Group] = t.cast(Group, command(**attrs))
@@ -275,7 +276,7 @@ def argument(*param_decls: str, **attrs: t.Any) -> t.Callable[[FC], FC]:
"""
def decorator(f: FC) -> FC:
- ArgumentClass = attrs.pop("cls", Argument)
+ ArgumentClass = attrs.pop("cls", None) or Argument
_param_memo(f, ArgumentClass(param_decls, **attrs))
return f
@@ -297,9 +298,9 @@ def option(*param_decls: str, **attrs: t.Any) -> t.Callable[[FC], FC]:
# Issue 926, copy attrs, so pre-defined options can re-use the same cls=
option_attrs = attrs.copy()
- if "help" in option_attrs:
+ if option_attrs.get("help"):
option_attrs["help"] = inspect.cleandoc(option_attrs["help"])
- OptionClass = option_attrs.pop("cls", Option)
+ OptionClass = option_attrs.pop("cls", None) or Option
_param_memo(f, OptionClass(param_decls, **option_attrs))
return f