Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

we should not recommend using functools.cache on methods #104112

Closed
Labels
docsDocumentation in the Doc dir
@carljm

Description

@carljm

Documentation

Currentlythe documentation for functools.cached_property recommends stacking@property and@functools.cache decorators to "achieve an effect similar to"functools.cached_property. But this omits a critical problem with using@functools.cache on instance methods: it is an unbounded cache, and will useself as a cache key, so any instance on which this "cached property" is ever accessed will be kept alive by the cache forever (unless the cache is manually cleared), and the memory used by these cached instances can grow unboundedly.

TheFAQ entry on caching methods does not recommend (or even mention)functools.cache, and it explicitly recommends a boundedfunctools.lru_cache in order to avoid keeping alive all instances indefinitely.

Specific proposals:

  1. Thecached_property documentation should not recommend usingfunctools.cache on a method.
  2. It also doesn't need to give a full example of usinglru_cache for a method cache; it can instead just mention the possibility, and link to the FAQ entry for more detailed discussion.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp