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

Error when using floats in pyproject.toml #4518

Closed
siehar opened this issue May 27, 2021 · 1 comment · Fixed by #4520
Closed

Error when using floats in pyproject.toml #4518

siehar opened this issue May 27, 2021 · 1 comment · Fixed by #4520
Labels
Bug 🪲 Crash 💥 A bug that makes pylint crash
Milestone

Comments

@siehar
Copy link
Contributor

siehar commented May 27, 2021

Steps to reproduce

Add a pyproject.toml to the project with this content:

[tool.pylint.master]
fail-under = 9.4

When running pylint, it aborts with an exception.

Full traceback:

Traceback (most recent call last):
  File "/test/virtualenv/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/test/virtualenv/lib/python3.8/site-packages/pylint/__init__.py", line 24, in run_pylint
    PylintRun(sys.argv[1:])
  File "/test/virtualenv/lib/python3.8/site-packages/pylint/lint/run.py", line 333, in __init__
    linter.load_config_file()
  File "/test/virtualenv/lib/python3.8/site-packages/pylint/config/option_manager_mixin.py", line 313, in load_config_file
    for option, value in parser.items(section):
  File "/usr/lib/python3.8/configparser.py", line 859, in items
    return [(option, value_getter(option)) for option in orig_keys]
  File "/usr/lib/python3.8/configparser.py", line 859, in <listcomp>
    return [(option, value_getter(option)) for option in orig_keys]
  File "/usr/lib/python3.8/configparser.py", line 855, in <lambda>
    value_getter = lambda option: self._interpolation.before_get(self,
  File "/usr/lib/python3.8/configparser.py", line 395, in before_get
    self._interpolate_some(parser, option, L, value, section, defaults, 1)
  File "/usr/lib/python3.8/configparser.py", line 412, in _interpolate_some
    p = rest.find("%")
AttributeError: 'float' object has no attribute 'find'

Current behavior

With fail-under = 9 the behaviour is as expected, using a floating point value leads to an exception.

Expected behavior

Floating point values should work.

pylint --version output

Result of pylint --version output:

pylint --version
pylint 3.0.0a3
astroid 2.5.6
Python 3.8.5 (default, Jan 27 2021, 15:41:15) 
[GCC 9.3.0]

But also tested with latest release version 2.8.2 and it also happens there.

Reason

The issue seems to come from here: https://github.com/PyCQA/pylint/blob/master/pylint/config/option_manager_mixin.py#L281

Floats coming from the TOML parser aren't handled here which later on confuses ConfigParser.

A simple fix would be to change isinstance(value, int) to isinstance(value, (int, float)).

I tried that fix and it works though I'm not sure if there are some weird edge cases where this breaks.

@Pierre-Sassoulas Pierre-Sassoulas added Bug 🪲 Crash 💥 A bug that makes pylint crash labels May 28, 2021
@Pierre-Sassoulas
Copy link
Member

Thank you for the report and the analysis. Would you mind making a pull request for it as you already did most of the work ? (I don't think there will be edge cases :) )

siehar pushed a commit to siehar/pylint that referenced this issue May 28, 2021
siehar pushed a commit to siehar/pylint that referenced this issue May 28, 2021
Pierre-Sassoulas pushed a commit that referenced this issue May 29, 2021
* Handle floats when parsing pyproject.toml (#4518)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: Markus Siebenhaar <markus.siebenhaar@masiha.de>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.9.0 milestone Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Crash 💥 A bug that makes pylint crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants