Fix #3145: lookup_default returns Sentinel.UNSET instead of None#3215
Closed
rodionsteshenko wants to merge 1 commit intopallets:mainfrom
Closed
Fix #3145: lookup_default returns Sentinel.UNSET instead of None#3215rodionsteshenko wants to merge 1 commit intopallets:mainfrom
rodionsteshenko wants to merge 1 commit intopallets:mainfrom
Conversation
When lookup_default is called and the parameter name is not found in the default_map (or when default_map is None), the method returned the internal Sentinel.UNSET value instead of None. This is a regression introduced in 8.3.0 that breaks downstream code which checks the return value against None. Also updated internal callers (get_default, consume_value) to check for None instead of UNSET since lookup_default no longer leaks the sentinel. Fixes pallets#3145
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.
Fix
lookup_defaultreturning the internalSentinel.UNSETvalue instead ofNonewhen the parameter name is not found indefault_map(or whendefault_mapisNone). This is a regression introduced in 8.3.0.Changes
Context.lookup_default()now returnsNoneinstead ofUNSETwhen the name is not in the default map or when there is no default mapParameter.get_default()andParameter.consume_value()to check forNoneinstead ofUNSETsincelookup_defaultno longer leaks the sentinelTest
Added 4 test cases in
test_context.py:test_lookup_default_returns_none_when_not_in_map— verifiesNoneis returned for missing keystest_lookup_default_returns_none_when_no_default_map— verifiesNonewhendefault_mapisNonetest_lookup_default_returns_value_when_in_map— verifies correct value retrievaltest_lookup_default_calls_callable_when_call_true— verifies callable defaults are calledThe first two tests reproduce the original bug (fail without the fix, pass with it).
Tested locally on macOS ARM (Apple Silicon). Full test suite passes (1323 passed).