[Django] #32306: Add decorator django.utils.functional.cached_classproperty

1 view
Skip to first unread message

Django

unread,
Dec 30, 2020, 2:03:33 AM12/30/20
to django-...@googlegroups.com
#32306: Add decorator django.utils.functional.cached_classproperty
-------------------------------------+-------------------------------------
Reporter: Boris | Owner: nobody
Type: New | Status: new
feature |
Component: Utilities | Version: 3.1
Severity: Normal | Keywords: cached
Triage Stage: | classproperty
Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Hello,
I propose new decorator "cached_classproperty".
Django has a lot of methods for caching, like cached_page and
cached_property.
Сaching improves response times.
It was useful for me. I needed to cache the class property because the
calculation needed to be done on the value.
What do you think about it?
https://github.com/django/django/pull/13813

--
Ticket URL: <https://code.djangoproject.com/ticket/32306>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 30, 2020, 2:12:23 AM12/30/20
to django-...@googlegroups.com
#32306: Add decorator django.utils.functional.cached_classproperty
--------------------------------------+------------------------------------
Reporter: chessmaster04 | Owner: nobody
Type: New feature | Status: new
Component: Utilities | Version: 3.1
Severity: Normal | Resolution:
Keywords: cached classproperty | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* cc: Claude Paroz, Simon Charette (added)
* needs_docs: 0 => 1
* needs_tests: 0 => 1
* stage: Unreviewed => Accepted


Comment:

Tentatively accepted, but I'm not sure if it's feasible, see Simon's
[https://code.djangoproject.com/ticket/30864#comment:2 comment].

--
Ticket URL: <https://code.djangoproject.com/ticket/32306#comment:1>

Django

unread,
Dec 30, 2020, 3:29:12 AM12/30/20
to django-...@googlegroups.com
#32306: Add decorator django.utils.functional.cached_classproperty
--------------------------------------+------------------------------------
Reporter: Boris | Owner: nobody

Type: New feature | Status: new
Component: Utilities | Version: master

Severity: Normal | Resolution:
Keywords: cached classproperty | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Boris):

* cc: Boris (added)
* version: 3.1 => master


--
Ticket URL: <https://code.djangoproject.com/ticket/32306#comment:2>

Django

unread,
Dec 30, 2020, 3:30:28 AM12/30/20
to django-...@googlegroups.com
#32306: Add decorator django.utils.functional.cached_classproperty
-------------------------------------+-------------------------------------
Reporter: Boris | Owner: Boris
| Trubin
Type: New feature | Status: assigned

Component: Utilities | Version: master
Severity: Normal | Resolution:
Keywords: cached | Triage Stage: Accepted
classproperty |
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Boris):

* owner: nobody => Boris Trubin
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/32306#comment:3>

Django

unread,
Dec 30, 2020, 2:44:49 PM12/30/20
to django-...@googlegroups.com
#32306: Add decorator django.utils.functional.cached_classproperty
-------------------------------------+-------------------------------------
Reporter: Boris | Owner: Boris
| Trubin
Type: New feature | Status: assigned
Component: Utilities | Version: master
Severity: Normal | Resolution:
Keywords: cached | Triage Stage: Accepted
classproperty |
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by David Smith):

* Attachment "test.py" added.

Django

unread,
Dec 30, 2020, 2:52:32 PM12/30/20
to django-...@googlegroups.com
#32306: Add decorator django.utils.functional.cached_classproperty
-------------------------------------+-------------------------------------
Reporter: Boris | Owner: Boris
| Trubin
Type: New feature | Status: assigned
Component: Utilities | Version: master
Severity: Normal | Resolution:
Keywords: cached | Triage Stage: Accepted
classproperty |
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by David Smith):

I fear I misunderstand the issue here, if so I am sorry. Can one of the
existing Python caches be used here?

I've attached a small example where `lru_cache` is used stacked under the
`classproperty` decorator.

{{{
class TestClass:
@classproperty
@lru_cache
def test_property(self):
time.sleep(2)
}}}

In my test case, I see the output as.

{{{
python test.py
0:00:02.002166
0:00:00.000037
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32306#comment:4>

Django

unread,
Dec 30, 2020, 2:58:47 PM12/30/20
to django-...@googlegroups.com
#32306: Add decorator django.utils.functional.cached_classproperty
-------------------------------------+-------------------------------------
Reporter: Boris | Owner: Boris
| Trubin
Type: New feature | Status: closed
Component: Utilities | Version: master
Severity: Normal | Resolution: wontfix

Keywords: cached | Triage Stage: Accepted
classproperty |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: assigned => closed
* needs_docs: 1 => 0
* resolution: => wontfix
* needs_tests: 1 => 0


Comment:

Closing as "wontfix" since it looks unnecessary per
[https://groups.google.com/g/django-developers/c/EY1uHOMqoYk discussion]
and David's [https://code.djangoproject.com/ticket/32306#comment:4
comment]. We can reopen after reaching a strong consensus on
DevelopersMailingList. Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/32306#comment:5>

Reply all
Reply to author
Forward
0 new messages