Closed
Conversation
Add an internal _lookup_default helper for UNSET handling and use it in internal call sites. Update the public lookup_default to normalize UNSET to None and add regression tests covering missing keys, callable defaults, and internal behavior.
Author
|
I verified the regression and historical behaviour:
Full test suite on Windows/Python 3.14.2: 1 failure in tests/test_imports.py::test_light_imports |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3145
Problem
In Click >= 8.3,
Context.lookup_default()returns the internalSentinel.UNSETobject when a key is missing. Historically (<= 8.2.1),the public API returned
None.Reproduction
ctx.lookup_default("missing_key") -> Sentinel.UNSETctx.lookup_default("missing_key") -> NoneRoot Cause
Regression introduced by 1c20dc6 (“Fix default handling to defer UNSET normalization ”)
Let the internal sentinel leak through the public API.
Solution
_lookup_default()that returnsUNSETfor internal uselookup_default()to returnNone_lookup_default()Safety