[Django] #30864: Please document and endorse django.utils.decorators.classproperty

33 views
Skip to first unread message

Django

unread,
Oct 10, 2019, 6:07:23 AM10/10/19
to django-...@googlegroups.com
#30864: Please document and endorse django.utils.decorators.classproperty
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
jgonggrijp |
Type: New | Status: new
feature |
Component: | Version: 2.2
Documentation |
Severity: Normal | Keywords: utils classproperty
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
django.utils.decorators.classproperty is really useful. Please document
it, encourage its use and make it a stable feature.

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

Django

unread,
Oct 10, 2019, 10:21:33 AM10/10/19
to django-...@googlegroups.com
#30864: Please document and endorse django.utils.decorators.classproperty
-------------------------------------+-------------------------------------
Reporter: jgonggrijp | Owner: nobody
Type: New feature | Status: new
Component: Documentation | Version: 2.2
Severity: Normal | Resolution:

Keywords: utils classproperty | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz):

Personally, I'd love having `cached_classproperty`…

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

Django

unread,
Oct 10, 2019, 10:43:33 AM10/10/19
to django-...@googlegroups.com
#30864: Document and endorse django.utils.decorators.classproperty
-------------------------------------+-------------------------------------

Reporter: jgonggrijp | Owner: nobody
Type: New feature | Status: new
Component: Documentation | Version: 2.2
Severity: Normal | Resolution:
Keywords: utils classproperty | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

> Personally, I'd love having `cached_classproperty`…

That would be hard to implement without some metaclass mockery or relying
on some naive `if not hasattr(cls, '_cached_foo')` constructs.

`cached_property` is efficient because it relies on the descriptor
protocol to cache its return value into `__dict__` and avoid class level
attribute lookups. We can't achieve similar things without defining the
attribute on the class of the class (metaclass) and use the class's
`__dict__` as a cache store.

I guess the following could work.


{{{#!python
class cached_classproperty:
NOT_SET = object()

def __init__(self, method):
self.method = method
self.cached_value = self.NOT_SET

def __get__(self, instance, owner):
if self.cached_value is not self.NOT_SET:
return self.cached_value

self.cached_value = self.method(owner)
return self.cached_value

def __set__(self, instance, value):
self.cached_value = value

def __delete__(self, instance):
self.cached_value = self.NOT_SET
}}}

But this wouldn't be as efficient as `cached_property` because `__get__`
would always be called.

Anyway the `cached_classproperty` case should probably be discussed in
another ticket or on the mailing list.

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

Django

unread,
Oct 11, 2019, 5:36:58 AM10/11/19
to django-...@googlegroups.com
#30864: Document and endorse django.utils.decorators.classproperty
-------------------------------------+------------------------------------
Reporter: Julian Gonggrijp | Owner: nobody

Type: New feature | Status: new
Component: Documentation | Version: 2.2
Severity: Normal | Resolution:
Keywords: utils classproperty | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by Carlton Gibson):

* stage: Unreviewed => Accepted


Comment:

I don't see any harm in promoting this to ''public''.

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

Django

unread,
Oct 11, 2019, 5:44:19 AM10/11/19
to django-...@googlegroups.com
#30864: Document and endorse django.utils.decorators.classproperty
-------------------------------------+------------------------------------
Reporter: Julian Gonggrijp | Owner: nobody
Type: New feature | Status: new
Component: Documentation | Version: 2.2
Severity: Normal | Resolution:
Keywords: utils classproperty | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+------------------------------------

Comment (by felixxm):

I can only add that it's already tested
`utils_tests.test_decorators.ClassPropertyTest`. Documentation should land
in `docs/ref/utils.txt`.

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

Django

unread,
Oct 11, 2019, 8:12:35 AM10/11/19
to django-...@googlegroups.com
#30864: Document and endorse django.utils.decorators.classproperty
-------------------------------------+------------------------------------
Reporter: Julian Gonggrijp | Owner: nobody
Type: New feature | Status: new
Component: Documentation | Version: 2.2
Severity: Normal | Resolution:
Keywords: utils classproperty | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+------------------------------------

Comment (by Claude Paroz):

Shouldn't it be moved to `django.utils.functional`?

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

Django

unread,
Oct 11, 2019, 8:28:03 AM10/11/19
to django-...@googlegroups.com
#30864: Document and endorse django.utils.decorators.classproperty
-------------------------------------+------------------------------------
Reporter: Julian Gonggrijp | Owner: nobody
Type: New feature | Status: new
Component: Documentation | Version: 2.2
Severity: Normal | Resolution:
Keywords: utils classproperty | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+------------------------------------

Comment (by felixxm):

Yes, good idea.

--
Ticket URL: <https://code.djangoproject.com/ticket/30864#comment:6>

Django

unread,
Oct 13, 2019, 11:21:43 AM10/13/19
to django-...@googlegroups.com
#30864: Document and endorse django.utils.decorators.classproperty
-------------------------------------+------------------------------------
Reporter: Julian Gonggrijp | Owner: nobody
Type: New feature | Status: new
Component: Documentation | Version: 2.2
Severity: Normal | Resolution:
Keywords: utils classproperty | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+------------------------------------

Comment (by André Ericson):

Replying to [comment:5 Claude Paroz]:


> Shouldn't it be moved to `django.utils.functional`?

I've created a ticket for that https://code.djangoproject.com/ticket/30876
I think it makes more sense to address it first. I will go ahead and do it
once it's accepted.

--
Ticket URL: <https://code.djangoproject.com/ticket/30864#comment:7>

Django

unread,
Oct 29, 2019, 3:52:02 PM10/29/19
to django-...@googlegroups.com
#30864: Document and endorse django.utils.decorators.classproperty
-------------------------------------+-------------------------------------
Reporter: Julian Gonggrijp | Owner: André
| Ericson
Type: New feature | Status: assigned

Component: Documentation | Version: 2.2
Severity: Normal | Resolution:
Keywords: utils classproperty | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by André Ericson):

* owner: nobody => André Ericson
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/30864#comment:8>

Django

unread,
Mar 13, 2020, 1:56:55 AM3/13/20
to django-...@googlegroups.com
#30864: Document and endorse django.utils.decorators.classproperty
-------------------------------------+------------------------------------
Reporter: Julian Gonggrijp | Owner: (none)

Type: New feature | Status: new
Component: Documentation | Version: 2.2
Severity: Normal | Resolution:
Keywords: utils classproperty | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by felixxm):

* owner: André Ericson => (none)
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/30864#comment:9>

Django

unread,
Mar 26, 2020, 3:41:31 PM3/26/20
to django-...@googlegroups.com
#30864: Document and endorse django.utils.decorators.classproperty
-------------------------------------+-------------------------------------
Reporter: Julian Gonggrijp | Owner:
| sumitpatra6

Type: New feature | Status: assigned
Component: Documentation | Version: 2.2
Severity: Normal | Resolution:
Keywords: utils classproperty | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by sumitpatra6):

* owner: (none) => sumitpatra6


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/30864#comment:10>

Django

unread,
Mar 26, 2020, 3:43:52 PM3/26/20
to django-...@googlegroups.com
#30864: Document and endorse django.utils.decorators.classproperty
-------------------------------------+------------------------------------
Reporter: Julian Gonggrijp | Owner: (none)
Type: New feature | Status: new
Component: Documentation | Version: 2.2
Severity: Normal | Resolution:
Keywords: utils classproperty | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by sumitpatra6):

* owner: sumitpatra6 => (none)


* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/30864#comment:11>

Django

unread,
Mar 27, 2020, 9:20:32 AM3/27/20
to django-...@googlegroups.com
#30864: Document and endorse django.utils.decorators.classproperty
-------------------------------------+-------------------------------------
Reporter: Julian Gonggrijp | Owner: Deep
| Sukhwani

Type: New feature | Status: assigned
Component: Documentation | Version: 2.2
Severity: Normal | Resolution:
Keywords: utils classproperty | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Deep Sukhwani):

* owner: (none) => Deep Sukhwani


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/30864#comment:12>

Django

unread,
Mar 28, 2020, 10:51:12 AM3/28/20
to django-...@googlegroups.com
#30864: Document and endorse django.utils.decorators.classproperty
-------------------------------------+-------------------------------------

Reporter: Julian Gonggrijp | Owner: Deep
| Sukhwani
Type: New feature | Status: assigned
Component: Documentation | Version: 2.2
Severity: Normal | Resolution:
Keywords: utils classproperty | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Deep Sukhwani):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/12637 PR#12637]

--
Ticket URL: <https://code.djangoproject.com/ticket/30864#comment:13>

Django

unread,
Mar 28, 2020, 11:03:35 AM3/28/20
to django-...@googlegroups.com
#30864: Document and endorse django.utils.decorators.classproperty
-------------------------------------+-------------------------------------

Reporter: Julian Gonggrijp | Owner: Deep
| Sukhwani
Type: New feature | Status: assigned
Component: Documentation | Version: 2.2
Severity: Normal | Resolution:
Keywords: utils classproperty | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Deep Sukhwani):

For reviewers: Slightly confused since this is my first trac ticket in
Django project. Please guide.

**Three questions:**

- The version on this ticket says 2.2 however the change, i.e. move from
`django.utils.decorators` to `django.utils.functional` was made in Django
3.1 (current ongoing development version) as a result of which, I added
`versionchanged` text to the submitted code change. Should I remove
`versionchanged`?
- If the answer for above question is **yes**, does this mean this change
needs to be backported to 2.2?
- If the answer for above question is **yes**, then does this also need to
be backported to every other version release since 2.2? i.e. all Versions:
in 2.x.y series and versions in 3.0.x series?

--
Ticket URL: <https://code.djangoproject.com/ticket/30864#comment:14>

Django

unread,
Mar 28, 2020, 2:48:11 PM3/28/20
to django-...@googlegroups.com
#30864: Document and endorse django.utils.decorators.classproperty
-------------------------------------+-------------------------------------

Reporter: Julian Gonggrijp | Owner: Deep
| Sukhwani
Type: New feature | Status: assigned
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: utils classproperty | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* version: 2.2 => master


Comment:

Replying to [comment:14 Deep Sukhwani]:


> - The version on this ticket says 2.2 however the change, i.e. move from
`django.utils.decorators` to `django.utils.functional` was made in Django
3.1 (current ongoing development version) as a result of which, I added
`versionchanged` text to the submitted code change. Should I remove
`versionchanged`?

This is a new feature so it goes only to the current master and should be
targeted to the Django 3.1. `versionchanged` annotation is not necessary,
you should add `versionadded` instead.

--
Ticket URL: <https://code.djangoproject.com/ticket/30864#comment:15>

Django

unread,
Mar 28, 2020, 6:34:02 PM3/28/20
to django-...@googlegroups.com
#30864: Document and endorse django.utils.decorators.classproperty
-------------------------------------+-------------------------------------

Reporter: Julian Gonggrijp | Owner: Deep
| Sukhwani
Type: New feature | Status: assigned
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: utils classproperty | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Deep Sukhwani):

Replying to [comment:15 felixxm]:

> This is a new feature so it goes only to the current master and should
be targeted to the Django 3.1. `versionchanged` annotation is not
necessary, you should add `versionadded` instead.

This feature (`classproperty` decorator) did exist in previous version,
however it was part of a different module `django.utils.decorators` and in
version 3.1 it is moved to `django.utils.functional`

Ref: https://docs.djangoproject.com/en/dev/releases/3.1/#id1, it says
> `django.utils.decorators.classproperty()` decorator is moved to
`django.utils.functional.classproperty()`

--
Ticket URL: <https://code.djangoproject.com/ticket/30864#comment:16>

Django

unread,
Mar 30, 2020, 1:17:09 AM3/30/20
to django-...@googlegroups.com
#30864: Document and endorse django.utils.decorators.classproperty
-------------------------------------+-------------------------------------

Reporter: Julian Gonggrijp | Owner: Deep
| Sukhwani
Type: New feature | Status: assigned
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: utils classproperty | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by felixxm):

I know that, but it doesn't change anything, IMO. We've added this note in
case someone uses this unsupported API. `classproperty` docs doesn't need
to contain it.

--
Ticket URL: <https://code.djangoproject.com/ticket/30864#comment:17>

Django

unread,
Mar 30, 2020, 2:33:32 AM3/30/20
to django-...@googlegroups.com
#30864: Document and endorse django.utils.decorators.classproperty
-------------------------------------+-------------------------------------

Reporter: Julian Gonggrijp | Owner: Deep
| Sukhwani
Type: New feature | Status: assigned
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: utils classproperty | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/30864#comment:18>

Django

unread,
Mar 31, 2020, 12:51:11 AM3/31/20
to django-...@googlegroups.com
#30864: Document and endorse django.utils.decorators.classproperty
-------------------------------------+-------------------------------------

Reporter: Julian Gonggrijp | Owner: Deep
| Sukhwani
Type: New feature | Status: assigned
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: utils classproperty | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/30864#comment:19>

Django

unread,
Mar 31, 2020, 4:47:51 AM3/31/20
to django-...@googlegroups.com
#30864: Document and endorse django.utils.decorators.classproperty
-------------------------------------+-------------------------------------

Reporter: Julian Gonggrijp | Owner: Deep
| Sukhwani
Type: New feature | Status: closed
Component: Documentation | Version: master
Severity: Normal | Resolution: fixed

Keywords: utils classproperty | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"4b146e0c83891fc67a422aa22f846bb7654c4d38" 4b146e0c]:
{{{
#!CommitTicketReference repository=""
revision="4b146e0c83891fc67a422aa22f846bb7654c4d38"
Fixed #30864 -- Doc'd classproperty decorator.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30864#comment:20>

Reply all
Reply to author
Forward
0 new messages