Reputation: 20244
Pylint is complaining round built-in referenced but what is the alternative?
The answers I've seen thus far are simply to quiet Pylint with regards to built-in functions. There must be some other way to call round()
, perhaps in a standard import library? Is there something potentially wrong about using the built-in function?
My searches for these answers have only come up with dozens of tutorials on using the built-in function.
Usage is anything to with round()
. This triggers the warning:
n = 0.05
n = round(n)
The exact warning only shows up in VS Code, it's:
{
"resource": "/C:/Users/neil.obremski/project/file.py",
"owner": "python",
"code": "round-builtin",
"severity": 4,
"message": "round built-in referenced",
"source": "pylint",
"startLineNumber": 434,
"startColumn": 9,
"endLineNumber": 434,
"endColumn": 9
}
UPDATE: This shows up when --enable=W
is set in the Pylint arguments. It shows up for absolutely any use of the round()
function, including specifying the second argument.
Here's what the Pylint output looks like for pylint file.py --enable=W
:
file.py:435:18: W1633: round built-in referenced (round-builtin)
Upvotes: 4
Views: 4907
Reputation: 67
If you need the code to be both Python 2 and 3 compatible and cannot change your lint settings, use this import
from builtins import round
Upvotes: 4
Reputation: 43495
Given Kevin's comment and the fact that Python2 is almost obsolete, it's best to ignore this warning.
Linters and even PEP8 give stylistic advice. Often very useful advice. But sometimes there are solid reasons for ignoring that advice.
What I would suggest is to use your preferred linter on all your projects. Then make a list of all errors and warnings that (in your opinion) are false positives, too pedantic or otherwise not helpful. Disable those globally in your linter's configuration file.
If you don't want to disable an error or warning globally, several linters accept the # noqa
comment as a notice not to check a certain line.
Upvotes: 2
Reputation: 69914
If you're only using python3.x you can ignore this warning (it is disabled by default, some option you are passing to pylint
is enabling this)
The warning is intended to be part of the --py3k
suite of checks, which look for python2 / python3 compatibility issues (if you're python3-only, this suite of checks can be actively harmful to code you write)
The reason for flagging all uses of round
are that both the rounding algorithm and types returned changed in python 3. In python3, rounding is now done using "bankers rounding" (what's new in python 3.0#builtins)
Upvotes: 6