Skip to content

Comments

Fix #3145: lookup_default returns Sentinel.UNSET instead of None#3215

Closed
rodionsteshenko wants to merge 1 commit intopallets:mainfrom
rodionsteshenko:fix-issue-3145
Closed

Fix #3145: lookup_default returns Sentinel.UNSET instead of None#3215
rodionsteshenko wants to merge 1 commit intopallets:mainfrom
rodionsteshenko:fix-issue-3145

Conversation

@rodionsteshenko
Copy link

Fix lookup_default returning the internal Sentinel.UNSET value instead of None when the parameter name is not found in default_map (or when default_map is None). This is a regression introduced in 8.3.0.

Changes

  • Context.lookup_default() now returns None instead of UNSET when the name is not in the default map or when there is no default map
  • Updated internal callers in Parameter.get_default() and Parameter.consume_value() to check for None instead of UNSET since lookup_default no longer leaks the sentinel

Test

Added 4 test cases in test_context.py:

  • test_lookup_default_returns_none_when_not_in_map — verifies None is returned for missing keys
  • test_lookup_default_returns_none_when_no_default_map — verifies None when default_map is None
  • test_lookup_default_returns_value_when_in_map — verifies correct value retrieval
  • test_lookup_default_calls_callable_when_call_true — verifies callable defaults are called

The 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).

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants