Skip to content

Commit ec9a4e9

Browse files
sirosenkdeldycke
andcommitted
Update comments on UNSET handling during parse_args
Per review feedback: - Remove an extraneous comment - Expand another, more significant comment Co-authored-by: Kevin Deldycke <159718+kdeldycke@users.noreply.github.com>
1 parent 2182da8 commit ec9a4e9

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/click/core.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,8 +1216,15 @@ def parse_args(self, ctx: Context, args: list[str]) -> list[str]:
12161216
for param in iter_params_for_processing(param_order, self.get_params(ctx)):
12171217
_, args = param.handle_parse_result(ctx, opts, args)
12181218

1219-
# after handling *all* parameters, do a pass over the params to rewrite
1220-
# `UNSET`
1219+
# We now have all parameters' values into `ctx.params`, but the data may contain
1220+
# the `UNSET` sentinel.
1221+
# Convert `UNSET` to `None` to ensure that the user doesn't see `UNSET`.
1222+
#
1223+
# Waiting until after the initial parse to convert allows us to treat `UNSET`
1224+
# more like a missing value when multiple params use the same name.
1225+
# Refs:
1226+
# https://github.com/pallets/click/issues/3071
1227+
# https://github.com/pallets/click/pull/3079
12211228
for name, value in ctx.params.items():
12221229
if value is UNSET:
12231230
ctx.params[name] = None
@@ -2541,9 +2548,6 @@ def handle_parse_result(
25412548
assert self.name is not None, (
25422549
f"{self!r} parameter's name should not be None when exposing value."
25432550
)
2544-
# Do not normalize UNSET values to None at this point
2545-
# It needs to be done, but doing so too early impacts multiple parameters
2546-
# targeting the same variable name
25472551
ctx.params[self.name] = value
25482552

25492553
return value, args

0 commit comments

Comments
 (0)