-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Pylint fix for invalid TOML config #4720
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
Changes from 4 commits
a685cf0
48bce35
19ede0f
04c0603
a0745b9
22ed923
0fbaadc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -293,9 +293,8 @@ def read_config_file(self, config_file=None, verbose=None): | |
msg = "No config file found, using default configuration" | ||
print(msg, file=sys.stderr) | ||
|
||
@staticmethod | ||
def _parse_toml( | ||
config_file: Union[Path, str], parser: configparser.ConfigParser | ||
self, config_file: Union[Path, str], parser: configparser.ConfigParser | ||
) -> None: | ||
"""Parse and handle errors of a toml configuration file.""" | ||
with open(config_file, encoding="utf-8") as fp: | ||
|
@@ -305,16 +304,28 @@ def _parse_toml( | |
except KeyError: | ||
return | ||
for section, values in sections_values.items(): | ||
section_name = section.upper() | ||
# TOML has rich types, convert values to | ||
# strings as ConfigParser expects. | ||
if not isinstance(values, dict): | ||
# This class is a mixin: add_message comes from the `PyLinter` class | ||
self.add_message( # type: ignore | ||
"bad-configuration-option-value", line=0, args=(section, values) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm probably overlooking something really obvious, but how does this check whether There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is nothing directly in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps I think such a check (option value types) would be helpful anyway, if we don't already check it, so reserving There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, I'm going to change the name and upgrade the tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
) | ||
continue | ||
for option, value in values.items(): | ||
if isinstance(value, bool): | ||
values[option] = "yes" if value else "no" | ||
elif isinstance(value, (int, float)): | ||
values[option] = str(value) | ||
elif isinstance(value, list): | ||
values[option] = ",".join(value) | ||
parser._sections[section.upper()] = values # type: ignore | ||
else: | ||
values[option] = str(value) | ||
for option, value in values.items(): | ||
try: | ||
parser.set(section_name, option, value=value) | ||
except configparser.NoSectionError: | ||
parser.add_section(section_name) | ||
Pierre-Sassoulas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
parser.set(section_name, option, value=value) | ||
|
||
def load_config_file(self): | ||
"""Dispatch values previously read from a configuration file to each | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[tool.pylint.basic] | ||
name-group = { "a"="b" } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[tool.pylint.imports] | ||
preferred-modules = { "a"="b" } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
************* Module {abspath} | ||
{relpath}:1:0: E0014: Incorrect setting encountered in top level configuration-section 'load-plugins' : '[]' (bad-configuration-option-value) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[tool.pylint] | ||
# load-plugins does not belong in top level section | ||
load-plugins = [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
************* Module {abspath} | ||
{relpath}:1:0: E0014: Incorrect setting encountered in top level configuration-section 'load-plugins' : '[]' (bad-configuration-option-value) | ||
{relpath}:1:0: E0014: Incorrect setting encountered in top level configuration-section 'disable' : 'logging-not-lazy,logging-format-interpolation' (bad-configuration-option-value) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[tool.pylint] | ||
# Both disable and load-plugins do not belong in the top level section | ||
load-plugins = [] | ||
disable = "logging-not-lazy,logging-format-interpolation" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"functional_append": { | ||
"disable": [["logging-not-lazy"], ["logging-format-interpolation"]] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Both disable and load-plugins do not belong in the imports section | ||
Pierre-Sassoulas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# TODO This should be fixed in #5259 | ||
[tool.pylint."imports"] | ||
disable = [ | ||
"logging-not-lazy", | ||
"logging-format-interpolation", | ||
] | ||
preferred-modules = { "a"="b" } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"functional_append": { | ||
"disable": [["logging-not-lazy"], ["logging-format-interpolation"]] | ||
}, | ||
"jobs": 10, | ||
"reports": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[tool.pylint."messages control"] | ||
disable = [ | ||
"logging-not-lazy", | ||
"logging-format-interpolation", | ||
] | ||
jobs = 10 | ||
reports = true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
************* Module {abspath} | ||
{relpath}:1:0: E0014: Incorrect setting encountered in top level configuration-section 'disable' : 'logging-not-lazy,logging-format-interpolation' (bad-configuration-option-value) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[tool.pylint] | ||
# disable does not belong in top level section | ||
disable = "logging-not-lazy,logging-format-interpolation" |
Uh oh!
There was an error while loading. Please reload this page.