From e3dc34ee41b3703808b22357a071302c48fc6fe6 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Mon, 12 Apr 2021 11:33:40 -0700 Subject: [PATCH] fixup comments --- src/_pytest/assertion/rewrite.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/_pytest/assertion/rewrite.py b/src/_pytest/assertion/rewrite.py index f661fe9475e..33e2ef6cc49 100644 --- a/src/_pytest/assertion/rewrite.py +++ b/src/_pytest/assertion/rewrite.py @@ -685,8 +685,8 @@ def run(self, mod: ast.Module) -> None: # Nothing to do. return - # Insert some special imports at the top of the module but after any - # docstrings and __future__ imports. + # We'll insert some special imports at the top of the module, but after any + # docstrings and __future__ imports, so first figure out where that is. doc = getattr(mod, "docstring", None) expect_docstring = doc is None if doc is not None and self.is_rewrite_disabled(doc): @@ -718,6 +718,7 @@ def run(self, mod: ast.Module) -> None: lineno = item.decorator_list[0].lineno else: lineno = item.lineno + # Now actually insert the special imports. if sys.version_info >= (3, 10): aliases = [ ast.alias("builtins", "@py_builtins", lineno=lineno, col_offset=0), @@ -737,6 +738,7 @@ def run(self, mod: ast.Module) -> None: ast.Import([alias], lineno=lineno, col_offset=0) for alias in aliases ] mod.body[pos:pos] = imports + # Collect asserts. nodes: List[ast.AST] = [mod] while nodes: