Skip to content

Fix lookup_default return None#3212

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

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

Conversation

@StevOti
Copy link
Copy Markdown
Contributor

@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
Copy Markdown
Contributor 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.

@davidism davidism closed this Feb 17, 2026
@kdeldycke kdeldycke added this to the 8.3.2 milestone Feb 20, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Mar 7, 2026
@Rowlando13 Rowlando13 removed this from the 8.3.2 milestone Mar 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lookup_default returns Sentinel.UNSET instead of None

4 participants