Skip to content

Commit 2499ce2

Browse files
[refactor to use match] AssertionRewriter.run()
Co-authored-by: Marc Mueller <[email protected]>
1 parent 237ede4 commit 2499ce2

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

src/_pytest/assertion/rewrite.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -703,24 +703,17 @@ def run(self, mod: ast.Module) -> None:
703703
return
704704
pos = 0
705705
for item in mod.body:
706-
if (
707-
expect_docstring
708-
and isinstance(item, ast.Expr)
709-
and isinstance(item.value, ast.Constant)
710-
and isinstance(item.value.value, str)
711-
):
712-
doc = item.value.value
713-
if self.is_rewrite_disabled(doc):
714-
return
715-
expect_docstring = False
716-
elif (
717-
isinstance(item, ast.ImportFrom)
718-
and item.level == 0
719-
and item.module == "__future__"
720-
):
721-
pass
722-
else:
723-
break
706+
match item:
707+
case ast.Expr(value=ast.Constant(value=str() as doc)) if (
708+
expect_docstring
709+
):
710+
if self.is_rewrite_disabled(doc):
711+
return
712+
expect_docstring = False
713+
case ast.ImportFrom(level=0, module="__future__"):
714+
pass
715+
case _:
716+
break
724717
pos += 1
725718
# Special case: for a decorated function, set the lineno to that of the
726719
# first decorator, not the `def`. Issue #4984.

0 commit comments

Comments
 (0)