Skip to content

Commit 25e8ff1

Browse files
committed
ignore config files that partially parse as flake8 configs
1 parent 70c0b3d commit 25e8ff1

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/flake8/options/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ def _find_config_file(path: str) -> Optional[str]:
2929
home_stat = None
3030

3131
dir_stat = _stat_key(path)
32-
cfg = configparser.RawConfigParser()
3332
while True:
3433
for candidate in ("setup.cfg", "tox.ini", ".flake8"):
34+
cfg = configparser.RawConfigParser()
3535
cfg_path = os.path.join(path, candidate)
3636
try:
3737
cfg.read(cfg_path, encoding="UTF-8")

tests/unit/test_options_config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ def test_config_file_without_section_is_not_considered(tmp_path):
2121

2222

2323
def test_config_file_with_parse_error_is_not_considered(tmp_path, caplog):
24-
tmp_path.joinpath("setup.cfg").write_text("[error")
24+
# the syntax error here is deliberately to trigger a partial parse
25+
# https://github.com/python/cpython/issues/95546
26+
tmp_path.joinpath("setup.cfg").write_text("[flake8]\nx = 1\n...")
2527

2628
assert config._find_config_file(str(tmp_path)) is None
2729

0 commit comments

Comments
 (0)