Skip to content

Commit

Permalink
Ignore SyntaxError exceptions
Browse files Browse the repository at this point in the history
We parse 'logical_line's in a couple of extensions. There is currently a
potential bug in flake8 [1] that means these lines are not valid Python.
While we wait on a fix, simply skip these lines.

[1] PyCQA/flake8#1948

Change-Id: Ia0f2d729ee48f85afaa58ddb6e983e12d4f298a2
Signed-off-by: Stephen Finucane <[email protected]>
  • Loading branch information
stephenfin committed Jul 31, 2024
1 parent 977ee03 commit 634cb78
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions hacking/checks/except_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,13 @@ def hacking_assert_is_none(logical_line, noqa):
except ValueError:
continue
checker = NoneArgChecker(func_name)
checker.visit(ast.parse(logical_line))
try:
parsed_logical_line = ast.parse(logical_line)
except SyntaxError:
# let flake8 catch this itself
# https://github.com/PyCQA/flake8/issues/1948
continue
checker.visit(parsed_logical_line)
if checker.none_found:
yield start, "H203: Use assertIs(Not)None to check for None"

Expand Down Expand Up @@ -212,7 +218,13 @@ def hacking_assert_equal(logical_line, noqa):
return
comparisons = [ast.Eq, ast.NotEq]
checker = AssertTrueFalseChecker(methods, comparisons)
checker.visit(ast.parse(logical_line))
try:
parsed_logical_line = ast.parse(logical_line)
except SyntaxError:
# let flake8 catch this itself
# https://github.com/PyCQA/flake8/issues/1948
return
checker.visit(parsed_logical_line)
if checker.error:
yield start, 'H204: Use assert(Not)Equal()'

Expand Down Expand Up @@ -243,7 +255,13 @@ def hacking_assert_greater_less(logical_line, noqa):
return
comparisons = [ast.Gt, ast.GtE, ast.Lt, ast.LtE]
checker = AssertTrueFalseChecker(methods, comparisons)
checker.visit(ast.parse(logical_line))
try:
parsed_logical_line = ast.parse(logical_line)
except SyntaxError:
# let flake8 catch this itself
# https://github.com/PyCQA/flake8/issues/1948
return
checker.visit(parsed_logical_line)
if checker.error:
yield start, 'H205: Use assert{Greater,Less}[Equal]'

Expand Down

0 comments on commit 634cb78

Please sign in to comment.