Skip to content

Comments

Fix lookup_default return None#3212

Closed
StevOti wants to merge 1 commit intopallets:mainfrom
StevOti:fix-lookup-default
Closed

Fix lookup_default return None#3212
StevOti wants to merge 1 commit intopallets:mainfrom
StevOti:fix-lookup-default

Conversation

@StevOti
Copy link

@StevOti StevOti commented Feb 17, 2026

Fixes #3145

Problem

In Click >= 8.3, Context.lookup_default() returns the internal
Sentinel.UNSET object when a key is missing. Historically (<= 8.2.1),
the public API returned None.

Reproduction

  • main: ctx.lookup_default("missing_key") -> Sentinel.UNSET
  • Click 8.2.1: ctx.lookup_default("missing_key") -> None

Root Cause

Regression introduced by 1c20dc6 (“Fix default handling to defer UNSET normalization ”)
Let the internal sentinel leak through the public API.

Solution

  • Add internal _lookup_default() that returns UNSET for internal use
  • Normalize public lookup_default() to return None
  • Update internal call sites to use _lookup_default()
  • Add regression tests covering missing keys, callable defaults, and internal behavior

Safety

  • Internal sentinel semantics preserved
  • Regression tests added
  • Full test suite run locally (see note below)

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.
@StevOti
Copy link
Author

StevOti commented Feb 17, 2026

I verified the regression and historical behaviour:

  • main: lookup_default("missing_key") -> Sentinel.UNSET
  • Click 8.2.1: lookup_default("missing_key") -> None

Full test suite on Windows/Python 3.14.2: 1 failure in tests/test_imports.py::test_light_imports
because ctypes._layout is imported (not in ALLOWED_IMPORTS). This seems unrelated
to the lookup_default change; happy to rerun in a different env if preferred.

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.

lookup_default returns Sentinel.UNSET instead of None

3 participants