LazyProxy(..., enable_cache=True) repeatedly invokes its function when the result is None. For example, two reads of .value, a boolean conversion and a string conversion invoke a None-returning function four times, despite caching being enabled.
Track whether a result has been cached separately from the result value. This lets None be cached and preserves repeated evaluation when enable_cache=False. The regression covers both cache settings and verifies that initialization stays lazy.
Validation on macOS / CPython 3.12.11, with CLDR 48.2 data imported using the repository script:
Before the fix: the cache-enabled regression fails with 4 calls instead of 1; the cache-disabled control passes.
After the fix: python -m pytest tests/test_support_lazy_proxy.py -q --tb=short: 8 passed, including existing copying and exception tests.
Full suite: TZ=UTC python -X utf8 -m pytest -q --tb=short: 7833 passed, 7 skipped, 2 xfailed. One pytest deprecation warning remains in the existing TOML tests.
Ruff 0.14.10 and the repository's configured pre-commit checks pass for both changed files; git diff --check passes.
AI assistance: Codex investigated the bug, wrote the patch and regression tests, and ran the checks. No independent human review is claimed. The supported Python/OS CI matrix was not run locally; upstream CI and maintainer review remain outstanding.
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
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.
LazyProxy(..., enable_cache=True) repeatedly invokes its function when the result is None. For example, two reads of .value, a boolean conversion and a string conversion invoke a None-returning function four times, despite caching being enabled.
Track whether a result has been cached separately from the result value. This lets None be cached and preserves repeated evaluation when enable_cache=False. The regression covers both cache settings and verifies that initialization stays lazy.
Validation on macOS / CPython 3.12.11, with CLDR 48.2 data imported using the repository script:
AI assistance: Codex investigated the bug, wrote the patch and regression tests, and ran the checks. No independent human review is claimed. The supported Python/OS CI matrix was not run locally; upstream CI and maintainer review remain outstanding.