Skip to content

Replace lazyproperty with functools.cached_property#4282

Open
KRRT7 wants to merge 3 commits intoUnstructured-IO:mainfrom
KRRT7:replace-lazyproperty-with-cached-property
Open

Replace lazyproperty with functools.cached_property#4282
KRRT7 wants to merge 3 commits intoUnstructured-IO:mainfrom
KRRT7:replace-lazyproperty-with-cached-property

Conversation

@KRRT7
Copy link
Collaborator

@KRRT7 KRRT7 commented Mar 10, 2026

Summary

  • Replace custom lazyproperty descriptor with stdlib functools.cached_property
  • Fix bug where 26 properties returning None were re-evaluated on every access instead of caching — lazyproperty.__get__ uses if value is None to detect a cache miss, so any property that legitimately returns None re-runs on every access
  • Slight performance improvement on cached reads — cached_property is a non-data descriptor, so after first access the __dict__ entry shadows the descriptor directly (plain dict lookup vs __get__ call)
  • Nothing in the codebase ever assigns to a lazyproperty-decorated attribute, so dropping the write-protection from the data descriptor has no behavioral impact

KRRT7 added 3 commits March 9, 2026 19:46
lazyproperty had a bug where methods returning None would re-evaluate
on every access instead of caching, affecting 26 properties across the
codebase. cached_property also provides faster subsequent reads as a
non-data descriptor (bypasses __get__ after first access).
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.

1 participant