Closed
Description
Example code
The following code contains an old style division.
(x / 2 * 3.0)
The expected result
The result running the above code with arbitrary values assigned to x should be the following, where the parentheses explicitly show the order of the operations (x / 2) * 3.0
. Or written in another order the result should be evaluated as x * (3.0 / 2)
.
The issue
Once we run futurize
on the code above, an old_div
gets inserted by the fix_division_safe
fixture. However as one can see in the diff below, the function gets called with a wrong order of arguments.
$ futurize --stage2 src/example.py
RefactoringTool: Refactored src/example.py
--- src/example.py (original)
+++ src/example.py (refactored)
@@ -1 +1,3 @@
-(x / 2 * 3.0)
+from __future__ import division
+from past.utils import old_div
+(old_div(x, 2 * 3.0))
RefactoringTool: Files that need to be modified:
RefactoringTool: src/example.py
Expected conversion
As already stated in the section 'expected result' the correct conversion should have been: (old_div(x, 2) * 3.0)