mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-11 07:14:18 +00:00
Merge pull request #1648 from PyCQA/invalid-syntax-partial-parse
ignore config files that partially parse as flake8 configs
This commit is contained in:
commit
e76b59ae44
2 changed files with 4 additions and 2 deletions
|
|
@ -29,9 +29,9 @@ def _find_config_file(path: str) -> Optional[str]:
|
||||||
home_stat = None
|
home_stat = None
|
||||||
|
|
||||||
dir_stat = _stat_key(path)
|
dir_stat = _stat_key(path)
|
||||||
cfg = configparser.RawConfigParser()
|
|
||||||
while True:
|
while True:
|
||||||
for candidate in ("setup.cfg", "tox.ini", ".flake8"):
|
for candidate in ("setup.cfg", "tox.ini", ".flake8"):
|
||||||
|
cfg = configparser.RawConfigParser()
|
||||||
cfg_path = os.path.join(path, candidate)
|
cfg_path = os.path.join(path, candidate)
|
||||||
try:
|
try:
|
||||||
cfg.read(cfg_path, encoding="UTF-8")
|
cfg.read(cfg_path, encoding="UTF-8")
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,9 @@ def test_config_file_without_section_is_not_considered(tmp_path):
|
||||||
|
|
||||||
|
|
||||||
def test_config_file_with_parse_error_is_not_considered(tmp_path, caplog):
|
def test_config_file_with_parse_error_is_not_considered(tmp_path, caplog):
|
||||||
tmp_path.joinpath("setup.cfg").write_text("[error")
|
# the syntax error here is deliberately to trigger a partial parse
|
||||||
|
# https://github.com/python/cpython/issues/95546
|
||||||
|
tmp_path.joinpath("setup.cfg").write_text("[flake8]\nx = 1\n...")
|
||||||
|
|
||||||
assert config._find_config_file(str(tmp_path)) is None
|
assert config._find_config_file(str(tmp_path)) is None
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue