[Django] #16514: Classic integer division used in django.template.defaultfilters

28 views
Skip to first unread message

Django

unread,
Jul 25, 2011, 7:21:09 PM7/25/11
to django-...@googlegroups.com
#16514: Classic integer division used in django.template.defaultfilters
--------------------------+---------------------------------
Reporter: blume.mike@… | Owner: nobody
Type: Bug | Status: new
Milestone: | Component: Template system
Version: SVN | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Easy pickings: 1
UI/UX: 0 |
--------------------------+---------------------------------
In defaultfilters.py line 93 we have

nan = (1e200 * 1e200) / (1e200 * 1e200)

When running python with -Qwarnall this triggers a warning:

defaultfilters.py:93: DeprecationWarning: classic float division
nan = (1e200 * 1e200) / (1e200 * 1e200)

Functionally, this is not really a problem -- the expression results in
nan whether the '/' is interpreted as 'floored' or 'true' division. It
just produces a bit of terminal noise for those of us who habitually keep
the warnings on.

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

Django

unread,
Jul 26, 2011, 3:18:38 AM7/26/11
to django-...@googlegroups.com
#16514: Classic integer division used in django.template.defaultfilters
----------------------------------------+---------------------------------
Reporter: blume.mike@… | Owner: nobody
Type: Bug | Status: new
Milestone: | Component: Template system
Version: SVN | 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 jezdez):

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


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

Django

unread,
Jul 29, 2011, 12:48:07 AM7/29/11
to django-...@googlegroups.com
#16514: Classic integer division used in django.template.defaultfilters
----------------------------------------+---------------------------------
Reporter: blume.mike@… | Owner: nobody
Type: Bug | Status: new
Milestone: | Component: Template system
Version: SVN | 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 teraom):

* has_patch: 0 => 1


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

Django

unread,
Aug 21, 2011, 8:57:00 PM8/21/11
to django-...@googlegroups.com
#16514: Classic integer division used in django.template.defaultfilters
----------------------------------------+---------------------------------
Reporter: blume.mike@… | Owner: kman
Type: Bug | Status: new
Milestone: | Component: Template system
Version: SVN | 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 kman):

* owner: nobody => kman


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

Django

unread,
Aug 21, 2011, 9:17:20 PM8/21/11
to django-...@googlegroups.com
#16514: Classic integer division used in django.template.defaultfilters
----------------------------------------+---------------------------------
Reporter: blume.mike@… | Owner: anonymous
Type: Bug | Status: new
Milestone: | Component: Template system
Version: SVN | 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 Kiran Busi <kiran.busi@…>):

* owner: kman => anonymous


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

Django

unread,
Aug 21, 2011, 9:49:19 PM8/21/11
to django-...@googlegroups.com
#16514: Classic integer division used in django.template.defaultfilters
----------------------------------------+---------------------------------
Reporter: blume.mike@… | Owner: kman
Type: Bug | Status: new
Milestone: | Component: Template system
Version: SVN | Severity: Normal
Resolution: | Keywords:
Triage Stage: Accepted | Has patch: 1
Needs documentation: 0 | Needs tests: 1
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
----------------------------------------+---------------------------------
Changes (by kman):

* owner: anonymous => kman
* needs_tests: 0 => 1


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

Django

unread,
Aug 22, 2011, 12:53:55 AM8/22/11
to django-...@googlegroups.com
#16514: Classic integer division used in django.template.defaultfilters
----------------------------------------+---------------------------------
Reporter: blume.mike@… | Owner: kman
Type: Bug | Status: new
Milestone: | Component: Template system
Version: SVN | 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 kman):

* needs_tests: 1 => 0


Comment:

Not sure how to test for warnings, but I think important thing is to test
for nan; Created the test

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

Django

unread,
Aug 22, 2011, 2:06:19 AM8/22/11
to django-...@googlegroups.com
#16514: Classic integer division used in django.template.defaultfilters
----------------------------------------+---------------------------------
Reporter: blume.mike@… | Owner: kman
Type: Bug | Status: new
Milestone: | Component: Template system
Version: SVN | 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 |
----------------------------------------+---------------------------------

Comment (by DrMeers):

Wouldn't `float('nan')` be better than the magical fomula? kman's test
could be useful to ensure this works across all versions -- though it
shouldn't be nested inside the `test_floatformat` method.

--
Ticket URL: <https://code.djangoproject.com/ticket/16514#comment:7>

Django

unread,
Aug 22, 2011, 3:19:12 AM8/22/11
to django-...@googlegroups.com
#16514: Classic integer division used in django.template.defaultfilters
----------------------------------------+---------------------------------
Reporter: blume.mike@… | Owner: kman
Type: Bug | Status: new
Milestone: | Component: Template system
Version: SVN | 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 |
----------------------------------------+---------------------------------

Comment (by kman):

Removed the test completely (b/c it's nested ) and it seems a bit
superflous. Modified defaultFilters.py line 91 to be: nan = float('nan')

--
Ticket URL: <https://code.djangoproject.com/ticket/16514#comment:8>

Django

unread,
Aug 22, 2011, 3:37:00 AM8/22/11
to django-...@googlegroups.com
#16514: Classic integer division used in django.template.defaultfilters
-------------------------------------+-------------------------------------
Reporter: | Owner: kman
blume.mike@… | Status: new
Type: Bug | Component: Template system
Milestone: | Severity: Normal
Version: SVN | Keywords:
Resolution: | Has patch: 1
Triage Stage: Ready for | Needs tests: 0
checkin | Easy pickings: 1
Needs documentation: 0 |
Patch needs improvement: 0 |
UI/UX: 0 |
-------------------------------------+-------------------------------------
Changes (by DrMeers):

* stage: Accepted => Ready for checkin


Comment:

Ah; see the notes in defaultfilter.py regarding "Python Issue757815 and
Issue1080440" -- let's just go with the '''classic_division_fix.diff'''
for now until we get past python 2.5/2.6.

--
Ticket URL: <https://code.djangoproject.com/ticket/16514#comment:9>

Django

unread,
Aug 22, 2011, 4:06:53 AM8/22/11
to django-...@googlegroups.com
#16514: Classic integer division used in django.template.defaultfilters
-------------------------------------+-------------------------------------
Reporter: | Owner: kman
blume.mike@… | Status: closed
Type: Bug | Component: Template system
Milestone: | Severity: Normal
Version: SVN | Keywords:
Resolution: fixed | Has patch: 1
Triage Stage: Ready for | Needs tests: 0
checkin | Easy pickings: 1
Needs documentation: 0 |
Patch needs improvement: 0 |
UI/UX: 0 |
-------------------------------------+-------------------------------------
Changes (by mtredinnick):

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


Comment:

In [16649]:
{{{
#!CommitTicketReference repository="" revision="16649"
Silenced a "classic division" warning in floatformat template filter.

Fixes #16514. Thanks, Mike Blume.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/16514#comment:10>

Reply all
Reply to author
Forward
0 new messages