Skip to content

Commit 8873a37

Browse files
committed
Don't crash when encountering bare noqa comment.
1 parent eb95189 commit 8873a37

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

flake8_dunder_all/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,10 @@ def check_and_add_all(filename: PathLike, quote_type: str = '"') -> int:
250250
for line in source.splitlines():
251251
noqas = find_noqa(line)
252252
if noqas is not None:
253-
noqa_list: List[str] = noqas.group(1).rstrip().upper().split(',')
254-
if "DALL000" in noqa_list:
255-
return 0
253+
if noqas["codes"]:
254+
noqa_list: List[str] = noqas["codes"].rstrip().upper().split(',')
255+
if "DALL000" in noqa_list:
256+
return 0
256257

257258
tree = ast.parse(source)
258259
if sys.version_info < (3, 8): # pragma: no cover (py38+)

tests/test_main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
0,
5050
id="async function no __all__ and noqa",
5151
),
52+
pytest.param(f" # noqa \n{testing_source_g}", ["a_function"], 1, id="async function no __all__"),
5253
]
5354
)
5455
def test_main(tmp_pathplus: PathPlus, source: str, members: List[str], ret: int):

0 commit comments

Comments
 (0)