Fix lookup_default returning UNSET sentinel instead of None#3202
Closed
veeceey wants to merge 2 commits intopallets:mainfrom
Closed
Fix lookup_default returning UNSET sentinel instead of None#3202veeceey wants to merge 2 commits intopallets:mainfrom
veeceey wants to merge 2 commits intopallets:mainfrom
Conversation
Fixes pallets#3145. Since 8.3.0 Context.lookup_default leaked the internal UNSET sentinel to callers instead of returning None when no default was found. This broke subclasses and external code that relied on the documented return type (Any | None). Extract a private _lookup_default method that returns UNSET for internal callers that need to distinguish "not set" from None, and have the public lookup_default convert UNSET to None before returning. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
Fixes #3145.
Since Click 8.3.0,
Context.lookup_defaultreturns the internalSentinel.UNSETobject instead ofNonewhen a parameter has no entry in the default map. This is a regression from the pre-8.3.0 behavior, whereNonewas returned. The leak of the internal sentinel breaks:Contextthat overridelookup_defaultand checkif default is not Nonelookup_defaultdirectly and expectsNonefor missing defaultsChanges
_lookup_default(private): contains the original logic and returnsUNSETfor internal callers (Parameter.get_defaultandParameter.consume_value) that need to distinguish "not set" from an explicitNonevalue.lookup_default(public): delegates to_lookup_defaultand convertsUNSETtoNonebefore returning, restoring the documentedAny | Nonereturn type contract.Contextsubclass matching the pattern from the issue report.All 1320 existing tests continue to pass.
Test plan
test_lookup_default_returns_none_not_sentinelpassesAssertionError🤖 Generated with Claude Code