Opened 9 months ago

Last modified 9 months ago

#30949 new Cleanup/optimization

Use functools.cached_property instead of django.utils.functional.cached_property.

Reported by: Thomas Grainger Owned by: nobody
Component: Utilities Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Someday/Maybe
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Adam (Chainz) Johnson)

functools gains cached_property in Python 3.8:

django.utils.functional.cached_property should import it and deprecate its own implementation

Change History (4)

comment:1 Changed 9 months ago by Adam (Chainz) Johnson

Description: modified (diff)

comment:2 Changed 9 months ago by Simon Charette

FWIW functools.cached_property adds a RLock acquisition overhead for thread safety which is not something needed by most internal Django's usage and third party ones from my personal experience.

If we were to proceed with this patch we should measure the impact of this thread safety mechanism first and also document it.

comment:3 Changed 9 months ago by Claude Paroz

I don't think we should do anything until Python 3.8 becomes the minimal Python supported by Django.

comment:4 Changed 9 months ago by felixxm

Component: UncategorizedUtilities
Summary: use functools.cached_property over django.utils.functional.cached_property where available (py3.8+)Use functools.cached_property instead of django.utils.functional.cached_property.
Triage Stage: UnreviewedSomeday/Maybe
Type: UncategorizedCleanup/optimization

I agree with Claude, we can reconsider this ticket when Python 3.8 becomes the minimal Python supported by Django.

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