Skip to content

Lazy-load restriction enzyme data#30

Merged
richarda23 merged 2 commits into
mainfrom
fix/lazy-load-restriction-enzymes
Mar 8, 2026
Merged

Lazy-load restriction enzyme data#30
richarda23 merged 2 commits into
mainfrom
fix/lazy-load-restriction-enzymes

Conversation

@richarda23

Copy link
Copy Markdown
Owner

Summary

  • Removes module-level from faker_biology.mol_biol.re import rest_dict, which was eagerly loading a 437KB / 21K-line dict on any import from faker_biology.mol_biol
  • Adds _rest_dict = None class variable and _get_rest_dict() classmethod to RestrictionEnzyme — data loaded at most once per process, on first use
  • Adds a test verifying the dict is None before first use and populated after

Test plan

  • test_rest_dict_not_loaded_until_first_use — confirms lazy-load behaviour
  • Existing 4 RE tests (test_random_re, test_random_redata, test_min_size, test_blunt) continue to pass
  • Full suite: poetry run python -m pytest faker_biology/tests/ — 35 passed

🤖 Generated with Claude Code

richardiw and others added 2 commits March 8, 2026 20:02
The 437KB rest_dict was loaded at module level, meaning any import from
faker_biology.mol_biol triggered the full parse. Now loaded on first use
via a class-level cache on RestrictionEnzyme.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Migrate [tool.poetry.dev-dependencies] to [tool.poetry.group.dev.dependencies]
and run poetry lock to sync the lock file with pyproject.toml.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@richarda23
richarda23 merged commit fa32d06 into main Mar 8, 2026
5 checks passed
@richarda23 richarda23 mentioned this pull request Mar 8, 2026
1 task
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