Visitar URL original
Fix lazyproperty re-evaluating getters that return None by jipeng6036-del · Pull Request #1626 · python-openxml/python-docx · GitHub
Skip to content

Fix lazyproperty re-evaluating getters that return None - #1626

Open
jipeng6036-del wants to merge 1 commit into
python-openxml:masterfrom
jipeng6036-del:fix/1600-lazyproperty-none-cache
Open

jipeng6036-del wants to merge 1 commit into
python-openxml:masterfrom
jipeng6036-del:fix/1600-lazyproperty-none-cache

Conversation

@jipeng6036-del

Copy link
Copy Markdown

Fixes #1600.

lazyproperty treated a cached None the same as "not computed yet", so a getter that legitimately returns None ran again on every access. That contradicts the documented "evaluated only on first access" behavior.

The lookup now uses key presence in the instance __dict__ instead of comparing the stored value to None.

Testing

  • uv run pytest tests/test_shared.py — 23 passed
  • New None-returning case fails on unmodified master (call_count 3 vs 1) and passes with this change
  • Existing non-None caching still holds
  • ruff check / ruff format --check on the changed files
  • Full uv run pytest on Windows: 1555 passed, 56 failed. The failures are existing XML snippet / SHA-1 fixtures (tests/oxml/test_table.py, tests/opc/test_phys_pkg.py, header/footer templates) from CRLF checkout; they are outside the files in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lazyproperty re-evaluates its getter on every access when the cached value is None

1 participant