Skip to content

Commit d4b658f

Browse files
Do not set flag_value as None in click Option
From click 8.3.0 flag_value is set as a sentinel value UNSET instead of None, and since we maintain a PluggableCommanLineOption subclass, we need to maintain the same default values for an Option to avoid issues. Reference: https://github.com/pallets/click/releases/tag/8.3.0 Reference: aboutcode-org/scancode-toolkit#4572 Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
1 parent 30869cb commit d4b658f

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/commoncode/cliutils.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@
2222
# Tracing flags
2323
TRACE = False
2424

25+
try:
26+
# Introduced in click 8.3.0 to have a sentinel value
27+
# (https://peps.python.org/pep-0661/) for flag values
28+
# and default values instead of None to differentiate
29+
# between explicitly setting a `None` value and
30+
# not setting and value.
31+
# See https://github.com/pallets/click/pull/3030 and
32+
# https://github.com/pallets/click/releases/tag/8.3.0
33+
from click.core import UNSET
34+
except ImportError:
35+
# to maintain compatibility with click < 8.3.0
36+
UNSET = None
37+
2538

2639
def logger_debug(*args):
2740
pass
@@ -429,7 +442,7 @@ def __init__(
429442
confirmation_prompt=False,
430443
hide_input=False,
431444
is_flag=None,
432-
flag_value=None,
445+
flag_value=UNSET,
433446
multiple=False,
434447
count=False,
435448
allow_from_autoenv=True,

0 commit comments

Comments
 (0)