Wednesday, June 27, 2018

Why do we need @cached_property behave like property when access from class?

Hi, I'm reading the django's source code, and I am quite confused by https://github.com/django/django/pull/812/files and https://code.djangoproject.com/ticket/19872#no2

Why @cached_property need to return self when access from class? https://docs.djangoproject.com/zh-hans/2.0/_modules/django/utils/functional/#cached_property

I see this PR for sure can make @cached_property behave like python's @property, I have tested by myself here: https://gist.github.com/laixintao/f1114d964c19679c973c2c3c3f1fa8ba#gistcomment-2631456 , but still I can think out one useful situation.

Can somebody provide a condition that @cached_problem will cause problems without return self when access from class?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMv51WRWmVkFDAB%2ByVNawSeECHu50LeyKWMi1WjtF1C7j9k7%3DA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment