Opened 3 hours ago
Closed 2 hours ago
#35937 closed Cleanup/optimization (wontfix)
Refactor very similar code of internal dec function for simple_tag, simple_block_tag and inclusion_tag
Reported by: | Emma Delescolle | Owned by: | |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Normal | Keywords: | decorator, tag, simple_tag |
Cc: | Emma Delescolle | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The internal dec
function used by simple_tag
, simple_block_tag
and inclusion_tag
are very similar. There are also similarities in the process of determining the return value of these methods (the decorated function or the decorator itself). These similarities should be refactored.
- https://github.com/django/django/blob/main/django/template/library.py#L111
- https://github.com/django/django/blob/main/django/template/library.py#L165
- https://github.com/django/django/blob/main/django/template/library.py#L250
Refactoring this function to be either a method of the Library
class they are defined in or as a completely separate function would:
- reduce the amount of code to maintain
- render change easier if anything ever has to change inside those
- allow the end-user to use that function/method to create their own complex template tags
Note:
See TracTickets
for help on using tickets.
Hi & thanks for your interest in helping out with Django.
The Django codebase usually tends to follow the WET (Write Everything Twice/Thrice) and in the case you've highlighted there doesn't appear to be a major advantage in modifying code to risk reducing readability and/or introduce regressions.
Will close the ticket for now but if you disagree feel free to head over to the Django Forum to start a discussion 👍