Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Wrong conversion of division to old_div #434

Copy link
Copy link
@wagnerpeer

Description

@wagnerpeer
Issue body actions

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)

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.