Skip to content

Commit b5464b7

Browse files
Only try to set flag_value if is_flag is true (pallets#2829)
Co-authored-by: Andreas Backx <[email protected]>
1 parent 88328fc commit b5464b7

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

CHANGES.rst

+3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ Unreleased
9191
- Add a ``catch_exceptions`` parameter to :class:`CliRunner`. If
9292
``catch_exceptions`` is not passed to :meth:`CliRunner.invoke`,
9393
the value from :class:`CliRunner`. :issue:`2817` :pr:`2818`
94+
- ``Option.flag_value`` will no longer have a default value set based on
95+
``Option.default`` if ``Option.is_flag`` is ``False``. This results in
96+
``Option.default`` not needing to implement `__bool__`. :pr:`2829`
9497

9598
Version 8.1.8
9699
-------------

src/click/core.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -2597,11 +2597,10 @@ def __init__(
25972597
else:
25982598
self.default = False
25992599

2600-
if flag_value is None:
2601-
flag_value = not self.default
2602-
26032600
self.type: types.ParamType
26042601
if is_flag and type is None:
2602+
if flag_value is None:
2603+
flag_value = not self.default
26052604
# Re-guess the type from the flag value instead of the
26062605
# default.
26072606
self.type = types.convert_type(None, flag_value)

tests/test_info_dict.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"help": None,
5959
"prompt": None,
6060
"is_flag": False,
61-
"flag_value": False,
61+
"flag_value": None,
6262
"count": False,
6363
"hidden": False,
6464
},

0 commit comments

Comments
 (0)