Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False-positive "old-division" (W1619) on explicit float division #3039

Closed
obi1kenobi opened this issue Aug 2, 2019 · 2 comments
Closed

False-positive "old-division" (W1619) on explicit float division #3039

obi1kenobi opened this issue Aug 2, 2019 · 2 comments
Labels
Bug 🪲 Good first issue Friendly and approachable by new contributors

Comments

@obi1kenobi
Copy link

My understanding is that W1619 (old-division) is supposed to check for PEP238 safety, and help users avoid unfortunate surprises when division on integers becomes true division. However, I believe that if the number being divided is a float, PEP238 does not change the division semantics, and therefore the following code (call it repro.py) should run the same in both Python 2 and 3.

x = float(4) / 2
print(x)

Possibly related to #2887 and #2803

Steps to reproduce

  1. Create the repro.py file described above.
  2. Run pylint --reports=no --disable=all --enable=old-division repro.py

Current behavior

$ pylint --reports=no --disable=all --enable=old-division repro.py 
************* Module repro
repro.py:1:4: W1619: division w/o __future__ statement (old-division)

-----------------------------------
Your code has been rated at 5.00/10

Expected behavior

Since the division is explicitly on a float-typed number, pylint reports no issues.

pylint --version output

Both the newest 2.x and the newest 1.x seem to be affected:

$ pylint --version
pylint 2.3.1
astroid 2.2.5
Python 3.6.8 (default, Mar 14 2019, 21:00:19) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)]
$ pylint --version
No config file found, using default configuration
pylint 1.9.5, 
astroid 1.6.6
Python 3.6.8 (default, Mar 14 2019, 21:00:19) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)]
@PCManticore
Copy link
Contributor

Thanks for the report, it definitely makes sense.

@bojanbg
Copy link

bojanbg commented Feb 5, 2020

This still raises W1619 with pylint 2.4.4:

print(100 * float(5) / 10)

My mental model was that pylint can recognize that the numerator is a float.

cript0nauta added a commit to infobyte/faraday that referenced this issue Aug 11, 2020
Pylinyt documentation says: "This message can’t be emitted when using
Python >= 3.0." but we are using Python 3.7 and it stills present,
apparently because of a bug in pylint. See also:

https://docs.pylint.org/en/1.6.0/features.html
pylint-dev/pylint#3039
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Good first issue Friendly and approachable by new contributors
Projects
None yet
Development

No branches or pull requests

3 participants