diff --git a/pylint/utils/utils.py b/pylint/utils/utils.py index f56fc8eb22..4bfced3a99 100644 --- a/pylint/utils/utils.py +++ b/pylint/utils/utils.py @@ -380,6 +380,11 @@ def _ini_format(stream: TextIO, options: list[tuple[str, OptionDict, Any]]) -> N DeprecationWarning, ) for optname, optdict, value in options: + # Skip deprecated option + if "kwargs" in optdict: + assert isinstance(optdict["kwargs"], dict) + if "new_names" in optdict["kwargs"]: + continue value = _format_option_value(optdict, value) help_opt = optdict.get("help") if help_opt: @@ -389,7 +394,7 @@ def _ini_format(stream: TextIO, options: list[tuple[str, OptionDict, Any]]) -> N print(help_opt, file=stream) else: print(file=stream) - if value is None: + if value in {"None", "False"}: print(f"#{optname}=", file=stream) else: value = str(value).strip() diff --git a/tests/test_self.py b/tests/test_self.py index a186174f1f..6a96933eb5 100644 --- a/tests/test_self.py +++ b/tests/test_self.py @@ -14,6 +14,7 @@ import re import subprocess import sys +import tempfile import textwrap import warnings from collections.abc import Generator, Iterator @@ -1344,6 +1345,17 @@ def test_generate_rcfile() -> None: ) assert process.stdout == process_two.stdout + # Check that the generated file is valid + with tempfile.NamedTemporaryFile(mode="w", delete=False) as temp: + filename = temp.name + temp.write(process.stdout) + runner = Run( + [join(HERE, "regrtest_data", "empty.py"), f"--rcfile={filename}"], + exit=False, + ) + assert not runner.linter.msg_status + os.remove(filename) + @staticmethod def test_generate_config_disable_symbolic_names() -> None: """Test that --generate-rcfile puts symbolic names in the --disable option."""