Skip to content

Replace lazyproperty with functools.cached_property#4282

Merged
KRRT7 merged 6 commits intoUnstructured-IO:mainfrom
KRRT7:replace-lazyproperty-with-cached-property
Mar 27, 2026
Merged

Replace lazyproperty with functools.cached_property#4282
KRRT7 merged 6 commits intoUnstructured-IO:mainfrom
KRRT7:replace-lazyproperty-with-cached-property

Conversation

@KRRT7
Copy link
Copy Markdown
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 4 commits March 26, 2026 18:11
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).
@KRRT7 KRRT7 force-pushed the replace-lazyproperty-with-cached-property branch from 98445a0 to 6db80e2 Compare March 26, 2026 23:13
KRRT7 added 2 commits March 26, 2026 21:31
…y-with-cached-property

# Conflicts:
#	CHANGELOG.md
#	unstructured/__version__.py
@KRRT7 KRRT7 enabled auto-merge March 27, 2026 02:49
@KRRT7 KRRT7 added this pull request to the merge queue Mar 27, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 27, 2026
@KRRT7 KRRT7 added this pull request to the merge queue Mar 27, 2026
Merged via the queue into Unstructured-IO:main with commit 7c5855b Mar 27, 2026
51 of 52 checks passed
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.

2 participants