Fix more mypy issues

This commit is contained in:
Jelle Zijlstra 2024-05-18 10:09:10 -04:00
parent e97aec872e
commit 166cc00c7c
2 changed files with 3 additions and 4 deletions

View File

@ -835,7 +835,7 @@ class AssertionRewriter(ast.NodeVisitor):
current = self.stack.pop()
if self.stack:
self.explanation_specifiers = self.stack[-1]
keys: List[ast.expr] = [ast.Constant(key) for key in current.keys()]
keys: List[Optional[ast.expr]] = [ast.Constant(key) for key in current.keys()]
format_dict = ast.Dict(keys, list(current.values()))
form = ast.BinOp(expl_expr, ast.Mod(), format_dict)
name = "@py_format" + str(next(self.variable_counter))
@ -959,9 +959,7 @@ class AssertionRewriter(ast.NodeVisitor):
# Clear temporary variables by setting them to None.
if self.variables:
variables: List[ast.expr] = [
ast.Name(name, ast.Store()) for name in self.variables
]
variables = [ast.Name(name, ast.Store()) for name in self.variables]
clear = ast.Assign(variables, ast.Constant(None))
self.statements.append(clear)
# Fix locations (line numbers/column offsets).

View File

@ -130,6 +130,7 @@ class TestAssertionRewrite:
if isinstance(node, ast.Import):
continue
for n in [node, *ast.iter_child_nodes(node)]:
assert isinstance(n, (ast.stmt, ast.expr))
assert n.lineno == 3
assert n.col_offset == 0
assert n.end_lineno == 6