Fix lookup_default leaking UNSET sentinel instead of None#1
Open
veeceey wants to merge 1 commit into
Open
Conversation
Context.lookup_default() returned the internal UNSET sentinel when no default was found, which leaked an implementation detail to external callers—particularly subclasses of Context that override the method and check `if default is not None`. Introduce a private _lookup_default() that preserves the UNSET return for internal use (get_default and consume_value need to distinguish "no default" from "default is None"), and make the public lookup_default() convert UNSET to None before returning. Fixes pallets#3145 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 pallets#3145
Context.lookup_default()was returning the internalUNSETsentinel object instead ofNonewhen no default was found. This was a regression introduced in 8.3.0 that broke subclasses ofContextwhich overridelookup_default()and rely on the documented return type (Any | None)._lookup_default()method that preserves theUNSETreturn value for internal use byParameter.get_default()andParameter.consume_value(), which need to distinguish "no default" from "default is None".lookup_default()delegate to_lookup_default()and convertUNSETtoNonebefore returning, matching the documented return type and pre-8.3.0 behavior.Test plan
test_lookup_default_returns_none_not_sentinel-- verifieslookup_default()returnsNone(notUNSET) in all "no default found" scenariostest_lookup_default_subclass_no_sentinel_leak-- reproduces the exact pattern from the issue (subclass callingsuper().lookup_default()and checkingis not None)test_basic.pyis a pre-existing pytest compatibility issue unrelated to this change)