Opened 4 years ago

Closed 4 years ago

#16514 closed Bug (fixed)

Classic integer division used in django.template.defaultfilters

Reported by: blume.mike@… Owned by: kman
Component: Template system Version: master
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@… 4 years ago.
Use explicit floored division instead
tests.diff (556 bytes) - added by kman 4 years ago.
Test to check if a number is nan
float_nan.diff (464 bytes) - added by kman 4 years ago.
nan_equals_float_nan

Download all attachments as: .zip

Change History (13)

Changed 4 years ago by blume.mike@…

Use explicit floored division instead

comment:1 Changed 4 years ago by jezdez

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 4 years ago by teraom

  • Has patch set

comment:3 Changed 4 years ago by kman

  • Owner changed from nobody to kman

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

  • Owner changed from kman to anonymous

comment:5 Changed 4 years ago by kman

  • Needs tests set
  • Owner changed from anonymous to kman

Changed 4 years ago by kman

Test to check if a number is nan

comment:6 Changed 4 years ago by kman

  • 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 Changed 4 years ago 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.

Changed 4 years ago by kman

nan_equals_float_nan

comment:8 Changed 4 years ago 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')

comment:9 Changed 4 years ago by DrMeers

  • Triage Stage changed from Accepted to Ready 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 Changed 4 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

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