fix(lint): remove functools.cache from methods#1684
Merged
Conversation
Codecov Report❌ Patch coverage is
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
80960b9 to
37f122f
Compare
67a9379 to
36b652c
Compare
dlovell
reviewed
Mar 11, 2026
dlovell
requested changes
Mar 11, 2026
…property (B019)
- Replace `@property @functools.cache` combos with `@functools.cached_property`
to fix B019 violations and eliminate memory leaks from instance-keyed caches
- Convert standalone `@functools.cache` methods (`copy_sdist`) to
`@functools.cached_property` and update call sites accordingly
- Replace class-level `cached_property` aliases (`popened = _uv_build_popened`)
with explicit `@property` delegates (Python 3.13 disallows reusing the same
`cached_property` object under two names)
- Add `# noqa: B019` for `make_deferred_other`, which takes extra arguments
and cannot be converted to a `cached_property`
Fix a latent bug in `SdistBuilder.maybe_packager`: the field had
`converter=toolz.curried.excepts(Exception, Path)`, which silently converted
a `Sdister` object to `None` because `Path(sdister_instance)` raises
`TypeError`. This caused the `Sdister` to be garbage-collected immediately
after `SdistBuilder.from_script_path` returned, cleaning up its
`TemporaryDirectory` and deleting the sdist file that `SdistBuilder.sdist_path`
pointed to. Subsequent access to `sdist_path` in `_uv_tool_run_xorq_build`
then failed with `FileNotFoundError`. The fix removes the broken converter so
`maybe_packager` holds the `Sdister` directly, keeping it alive for the
lifetime of the `SdistBuilder`.
Proof that `@frozen` (attrs) works with `@cached_property`:
from attrs import frozen
from functools import cached_property
@Frozen
class Circle:
radius: float
@cached_property
def area(self):
print("computing...")
return 3.14159 * self.radius ** 2
c = Circle(radius=5.0)
print(c.area) # computing... → 78.53975
print(c.area) # cached → 78.53975
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
6d41455 to
cbcf087
Compare
dlovell
approved these changes
Mar 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@property @functools.cachecombos with@functools.cached_propertyto fix B019 violations and eliminate memory leaks from instance-keyed caches@functools.cachemethods (copy_sdist) to@functools.cached_propertyand update call sites accordinglycached_propertyaliases (popened = _uv_build_popened) with explicit@propertydelegates (Python 3.13 disallows reusing the samecached_propertyobject under two names)# noqa: B019formake_deferred_other, which takes extra arguments and cannot be converted to acached_propertyFix a latent bug in
SdistBuilder.maybe_packager: the field hadconverter=toolz.curried.excepts(Exception, Path), which silently converted aSdisterobject toNonebecausePath(sdister_instance)raisesTypeError. This caused theSdisterto be garbage-collected immediately afterSdistBuilder.from_script_pathreturned, cleaning up itsTemporaryDirectoryand deleting the sdist file thatSdistBuilder.sdist_pathpointed to. Subsequent access tosdist_pathin_uv_tool_run_xorq_buildthen failed withFileNotFoundError. The fix removes the broken converter, somaybe_packagerholds theSdisterdirectly, keeping it alive for the lifetime of theSdistBuilder.Proof that
@frozen(attrs) works with@cached_property: