Skip to content

agent: cache IO-intensive private helpers with @functools.cache and register in conftest #1806

@nathanjmcdougall

Description

@nathanjmcdougall

When adding a private helper function that performs file I/O (or other expensive operations) and is called multiple times per invocation, it should be decorated with @functools.cache to avoid redundant work.\n\nThe function _get_current_python_version() in src/usethis/_integrations/environ/python.py was added without caching, even though it reads from disk and can be called up to three times per call to get_supported_minor_python_versions().\n\nWhen applying @functools.cache, the function must also be added to the clear_functools_caches autouse fixture in tests/conftest.py so the cache is cleared between tests.

We should explain this in the agent skills

Metadata

Metadata

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions