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

Fix Pylint Configuration Parsing Bug Causing Incorrect Option Settings #8460 #8591

Closed
wants to merge 9 commits into from
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/8460.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixed issue of specifying options as false on .toml files.

Refs #8460
3 changes: 2 additions & 1 deletion pylint/config/config_file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def parse_toml_file(file_path: Path) -> PylintConfigFileData:
for config, value in values.items():
value = _parse_rich_type_value(value)
config_content[config] = value
options += [f"--{config}", value]
if value.lower() != "false":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also check the type of the config option. If somebody put in false for a non-store_true option we don't want to this this. A test for this would also be good!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! Do you know if there's an efficient way to check the type of config? I was looking at the function "_convert_option_to_argument" in pylint/config/utils.py, but not sure if that would work.

Copy link
Collaborator

@DanielNoord DanielNoord Apr 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, although you could perhaps wait with parsing them until you reach:

try:
self.config, parsed_args = self._arg_parser.parse_known_args(
arguments, self.config
)

This should have knowledge of all registered arguments.

options += [f"--{config}", value]
else:
values = _parse_rich_type_value(values)
config_content[opt] = values
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"from_stdin": false,
"exit_zero": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Check to see if we can specify configurations as false
# without pylint treating the presence of the key as enabling that value

[tool.pylint.main]
from_stdin = false
exit_zero = false