Fix new typing issues in AST code

python/typeshed#11880 adds more precise types for AST nodes. I'm submitting some changes to adapt pytest to these changes.
This commit is contained in:
Jelle Zijlstra 2024-05-18 09:52:14 -04:00 committed by GitHub
parent 635fbe2bff
commit 8bb493b4f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 7 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 = [ast.Constant(key) for key in current.keys()]
keys: List[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))
@ -926,13 +926,13 @@ class AssertionRewriter(ast.NodeVisitor):
[*self.expl_stmts, hook_call_pass],
[],
)
statements_pass = [hook_impl_test]
statements_pass: List[ast.stmt] = [hook_impl_test]
# Test for assertion condition
main_test = ast.If(negation, statements_fail, statements_pass)
self.statements.append(main_test)
if self.format_variables:
variables = [
variables: List[ast.expr] = [
ast.Name(name, ast.Store()) for name in self.format_variables
]
clear_format = ast.Assign(variables, ast.Constant(None))
@ -959,7 +959,7 @@ class AssertionRewriter(ast.NodeVisitor):
# Clear temporary variables by setting them to None.
if self.variables:
variables = [ast.Name(name, ast.Store()) for name in self.variables]
variables: List[ast.expr] = [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).
@ -1114,11 +1114,11 @@ class AssertionRewriter(ast.NodeVisitor):
if isinstance(comp.left, (ast.Compare, ast.BoolOp)):
left_expl = f"({left_expl})"
res_variables = [self.variable() for i in range(len(comp.ops))]
load_names = [ast.Name(v, ast.Load()) for v in res_variables]
load_names: List[ast.expr] = [ast.Name(v, ast.Load()) for v in res_variables]
store_names = [ast.Name(v, ast.Store()) for v in res_variables]
it = zip(range(len(comp.ops)), comp.ops, comp.comparators)
expls = []
syms = []
expls: List[ast.expr] = []
syms: List[ast.expr] = []
results = [left_res]
for i, op, next_operand in it:
if (