Opened 13 years ago

Closed 13 years ago

#16514 closed Bug (fixed)

Classic integer division used in django.template.defaultfilters

Reported by: blume.mike@… Owned by: Kiran Busi
Component: Template system Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

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.

Attachments (3)

classic_division_fix.diff (515 bytes ) - added by blume.mike@… 13 years ago.
Use explicit floored division instead
tests.diff (556 bytes ) - added by Kiran Busi 13 years ago.
Test to check if a number is nan
float_nan.diff (464 bytes ) - added by Kiran Busi 13 years ago.
nan_equals_float_nan

Download all attachments as: .zip

Change History (13)

by blume.mike@…, 13 years ago

Attachment: classic_division_fix.diff added

Use explicit floored division instead

comment:1 by Jannis Leidel, 13 years ago

Triage Stage: UnreviewedAccepted

comment:2 by teraom, 13 years ago

Has patch: set

comment:3 by Kiran Busi, 13 years ago

Owner: changed from nobody to Kiran Busi

comment:4 by Kiran Busi <kiran.busi@…>, 13 years ago

Owner: changed from Kiran Busi to anonymous

comment:5 by Kiran Busi, 13 years ago

Needs tests: set
Owner: changed from anonymous to Kiran Busi

by Kiran Busi, 13 years ago

Attachment: tests.diff added

Test to check if a number is nan

comment:6 by Kiran Busi, 13 years ago

Needs tests: unset

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

comment:7 by Simon Meers, 13 years ago

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.

by Kiran Busi, 13 years ago

Attachment: float_nan.diff added

nan_equals_float_nan

comment:8 by Kiran Busi, 13 years ago

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')

comment:9 by Simon Meers, 13 years ago

Triage Stage: AcceptedReady for checkin

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.

comment:10 by Malcolm Tredinnick, 13 years ago

Resolution: fixed
Status: newclosed

In [16649]:

Silenced a "classic division" warning in floatformat template filter.

Fixes #16514. Thanks, Mike Blume.

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