Skip to content

Commit

Permalink
Use walruses in a couple of places (#401)
Browse files Browse the repository at this point in the history
Some minor cleanup now we've dropped support for py37
  • Loading branch information
AlexWaygood authored Jun 19, 2023
1 parent 5a8522e commit 7a10c90
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
17 changes: 7 additions & 10 deletions pyi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1970,18 +1970,15 @@ def _check_for_type_comments(lines: list[str]) -> Iterator[Error]:
if cleaned_line.startswith("#"):
continue

match = _TYPE_COMMENT_REGEX.search(cleaned_line)
if not match:
continue

type_comment = match.group(1).strip()
if match := _TYPE_COMMENT_REGEX.search(cleaned_line):
type_comment = match.group(1).strip()

try:
ast.parse(type_comment)
except SyntaxError:
continue
try:
ast.parse(type_comment)
except SyntaxError:
continue

yield Error(lineno, 0, Y033, PyiTreeChecker)
yield Error(lineno, 0, Y033, PyiTreeChecker)


@dataclass
Expand Down
3 changes: 1 addition & 2 deletions tests/test_pyi_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ def test_pyi_file(path: str) -> None:
flags = []
expected_output = ""

match = re.search(r"_py3(\d+)\.pyi$", path)
if match is not None:
if match := re.search(r"_py3(\d+)\.pyi$", path):
if sys.version_info < (3, int(match.group(1))):
pytest.skip(f"Python {sys.version_info} is too old for {path}")

Expand Down

0 comments on commit 7a10c90

Please sign in to comment.