[Django] #32990: Test the tag_re regex in template/base.py instead of evaluating it every time

11 views
Skip to first unread message

Django

unread,
Aug 5, 2021, 12:43:13 PM8/5/21
to django-...@googlegroups.com
#32990: Test the tag_re regex in template/base.py instead of evaluating it every
time
------------------------------------------------+------------------------
Reporter: Chris Jerdonek | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Template system | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
------------------------------------------------+------------------------
I noticed that `template/base.py` has a somewhat complicated regex string
at the top involving six calls to `re.escape()` that it needs to evaluate
every time:
https://github.com/django/django/blob/4fe3774c729f3fd5105b3001fe69a70bdca95ac3/django/template/base.py#L90-L93

A more efficient approach would be to define a hard-coded `_TAG_RE_REGEX`
regex at the top that is the result of that substitution, and add a test
checking that it matches the result of calling `re.escape()` six times,
etc. That would eliminate the need to do the substitution at runtime.

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

Django

unread,
Aug 5, 2021, 2:01:58 PM8/5/21
to django-...@googlegroups.com
#32990: Test the tag_re regex in template/base.py instead of evaluating it every
time
--------------------------------------+------------------------------------

Reporter: Chris Jerdonek | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Template system | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* stage: Unreviewed => Accepted


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

Django

unread,
Aug 6, 2021, 2:30:00 AM8/6/21
to django-...@googlegroups.com
#32990: Test the tag_re regex in template/base.py instead of evaluating it every
time
--------------------------------------+------------------------------------
Reporter: Chris Jerdonek | Owner: gtwohig
Type: Cleanup/optimization | Status: assigned

Component: Template system | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by gtwohig):

* owner: nobody => gtwohig
* status: new => assigned


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

Django

unread,
Aug 6, 2021, 7:01:49 AM8/6/21
to django-...@googlegroups.com
#32990: Test the tag_re regex in template/base.py instead of evaluating it every
time
--------------------------------------+------------------------------------
Reporter: Chris Jerdonek | Owner: gtwohig
Type: Cleanup/optimization | Status: assigned
Component: Template system | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


Comment:

Submitted [https://github.com/django/django/pull/14748 PR]

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

Django

unread,
Aug 9, 2021, 2:23:51 AM8/9/21
to django-...@googlegroups.com
#32990: Test the tag_re regex in template/base.py instead of evaluating it every
time
-------------------------------------+-------------------------------------

Reporter: Chris Jerdonek | Owner: gtwohig
Type: | Status: assigned
Cleanup/optimization |

Component: Template system | Version: dev
Severity: Normal | Resolution:
Keywords: | 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):

* stage: Accepted => Ready for checkin


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

Django

unread,
Aug 9, 2021, 3:29:42 AM8/9/21
to django-...@googlegroups.com
#32990: Test the tag_re regex in template/base.py instead of evaluating it every
time
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: gtwohig
Type: | Status: assigned
Cleanup/optimization |
Component: Template system | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"c99aaf14eef2a18b27bc7c2f2b17ae425ca2be49" c99aaf14]:
{{{
#!CommitTicketReference repository=""
revision="c99aaf14eef2a18b27bc7c2f2b17ae425ca2be49"
Refs #32990 -- Added tests for DebugLexer/Lexer.tokenize().
}}}

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

Django

unread,
Aug 9, 2021, 3:29:42 AM8/9/21
to django-...@googlegroups.com
#32990: Test the tag_re regex in template/base.py instead of evaluating it every
time
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: gtwohig
Type: | Status: closed
Cleanup/optimization |

Component: Template system | Version: dev
Severity: Normal | Resolution: fixed

Keywords: | 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:"fc2bd40fc76996306efc1f8de581708d8c5a2943" fc2bd40f]:
{{{
#!CommitTicketReference repository=""
revision="fc2bd40fc76996306efc1f8de581708d8c5a2943"
Fixed #32990 -- Simplified and optimized tag regex.

Thanks Chris Jerdonek for the review.
}}}

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

Reply all
Reply to author
Forward
0 new messages