[Django] #35937: Refactor very similar code of internal dec function for simple_tag, simple_block_tag and inclusion_tag

7 views
Skip to first unread message

Django

unread,
Nov 25, 2024, 10:11:19 AM11/25/24
to django-...@googlegroups.com
#35937: Refactor very similar code of internal dec function for simple_tag,
simple_block_tag and inclusion_tag
-------------------------------------+-------------------------------------
Reporter: Emma Delescolle | Type:
| Cleanup/optimization
Status: new | Component: Template
| system
Version: dev | Severity: Normal
Keywords: | Triage Stage:
decorator,tag,simple_tag | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
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
--
Ticket URL: <https://code.djangoproject.com/ticket/35937>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 25, 2024, 10:33:03 AM11/25/24
to django-...@googlegroups.com
#35937: Refactor very similar code of internal dec function for simple_tag,
simple_block_tag and inclusion_tag
-------------------------------------+-------------------------------------
Reporter: Emma Delescolle | Owner: (none)
Type: | Status: closed
Cleanup/optimization |
Component: Template system | Version: dev
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
decorator,tag,simple_tag | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by David Sanders):

* resolution: => wontfix
* status: new => closed

Comment:

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 👍
--
Ticket URL: <https://code.djangoproject.com/ticket/35937#comment:1>
Reply all
Reply to author
Forward
0 new messages