#22691 closed New feature (fixed)

Allow cached_property to be used on other methods

Reported by: FunkyBob Owned by: nobody
Component: Utilities Version: master
Severity: Normal Keywords:
Cc: loic84 Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by loic84)

This adds an optional name property to cached_property, overriding where it stores its cached value.

class Foo(object):
    def get_bar(self):
        ...heavy work...

    bar = cached_property(get_bar, name='bar')

Without the name, it would save the result in __dict__['get_bar'], thus masking the method.

Change History (4)

comment:1 Changed 14 months ago by loic84

  • Cc loic84 added
  • Description modified (diff)
  • Has patch set
  • Needs documentation set
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to New feature
  • Version changed from 1.6 to master

Sounds good.

PR: https://github.com/django/django/pull/2707

Since cached_property is documented, it'll need docs update and release notes.

Last edited 14 months ago by loic84 (previous) (diff)

comment:2 Changed 14 months ago by timo

Actually, #22663 suggests to remove the documentation for cached_property. Second opinions welcome on that...

comment:3 Changed 13 months ago by timo

  • Needs documentation unset
  • Patch needs improvement unset

I added docs in a comment on the PR; will go ahead and commit this if they look okay.

comment:4 Changed 13 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 71461b14ab0c5a3801d85738fde3aedd407d7115:

Fixed #22691 -- Added aliasing to cached_property.

Note: See TracTickets for help on using tickets.
Back to Top