#18964: defaultfilters test passes unexpectedly under Python 3
---------------------------------+-------------------------------------
Reporter: russellm | Owner: aaugustin
Type: Bug | Status: new
Component: Uncategorized | Version: master
Severity: Release blocker | Resolution:
Keywords: python3 | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+-------------------------------------
Comment (by aaugustin):
The test that unexpectedly passes is:
{{{
self.assertEqual(floatformat(1.00000000000000015, 16),
'1.0000000000000002')
}}}
Under Python 2, it returns `'1.0000000000000000'`.
----
The explanation is pretty simple.
The first step of the `floatformat` template filter is to coerce its input
as text, and this step introduces the difference between Python 2 and
Python 3.
{{{
% python2.6
>>> 1.00000000000000015
1.0000000000000002
>>> str(_)
'1.0'
}}}
{{{
% python3.2
>>> 1.00000000000000015
1.0000000000000002
>>> str(_)
'1.0000000000000002'
}}}
I think it's related to this paragraph of
[http://docs.python.org/3.1/whatsnew/3.1.html Python 3.1's release notes]:
> Python now uses David Gay’s algorithm for finding the shortest floating
point representation that doesn’t change its value.
----
Arguably, this is a bug in Python 2 that was fixed in Python 3. I'm going
to mark the test as an expected failure only on Python 2.
--
Ticket URL: <https://code.djangoproject.com/ticket/18964#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.