py36+: com2ann

This commit is contained in:
Anthony Sottile
2020-10-05 18:13:05 -07:00
parent 703e89134c
commit 33d119f71a
62 changed files with 431 additions and 443 deletions

View File

@@ -133,7 +133,7 @@ IDENT_PREFIX = "$"
def expression(s: Scanner) -> ast.Expression:
if s.accept(TokenType.EOF):
ret = ast.NameConstant(False) # type: ast.expr
ret: ast.expr = ast.NameConstant(False)
else:
ret = expr(s)
s.accept(TokenType.EOF, reject=True)
@@ -203,9 +203,9 @@ class Expression:
:param input: The input expression - one line.
"""
astexpr = expression(Scanner(input))
code = compile(
code: types.CodeType = compile(
astexpr, filename="<pytest match expression>", mode="eval",
) # type: types.CodeType
)
return Expression(code)
def evaluate(self, matcher: Callable[[str], bool]) -> bool:
@@ -217,7 +217,5 @@ class Expression:
:returns: Whether the expression matches or not.
"""
ret = eval(
self.code, {"__builtins__": {}}, MatcherAdapter(matcher)
) # type: bool
ret: bool = eval(self.code, {"__builtins__": {}}, MatcherAdapter(matcher))
return ret