| [case testHello] | |
| print("hello") | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| CallExpr:1( | |
| NameExpr(print) | |
| Args( | |
| StrExpr(hello))))) | |
| [case testMemberExpr] | |
| foo_bar.xyz2 | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| MemberExpr:1( | |
| NameExpr(foo_bar) | |
| xyz2))) | |
| [case testTupleExpr] | |
| ("a", "b") | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| TupleExpr:1( | |
| StrExpr(a) | |
| StrExpr(b)))) | |
| [case testOpExpr] | |
| ("x" + "y") * "z" | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| OpExpr:1( | |
| * | |
| OpExpr:1( | |
| + | |
| StrExpr(x) | |
| StrExpr(y)) | |
| StrExpr(z)))) | |
| [case testIntExpr] | |
| (0, 1, 2, 203, 5345, 50123, 1234567890, 9982374892739487239847897928374897298374, 0x1950A86A20F9469CFC6C) | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| TupleExpr:1( | |
| IntExpr(0) | |
| IntExpr(1) | |
| IntExpr(2) | |
| IntExpr(203) | |
| IntExpr(5345) | |
| IntExpr(50123) | |
| IntExpr(1234567890) | |
| IntExpr(9982374892739487239847897928374897298374) | |
| IntExpr(119547037146038801333356)))) | |
| [case testAssignmentStmt] | |
| x = 1 | |
| a, b = c = 6 | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(x) | |
| IntExpr(1)) | |
| AssignmentStmt:2( | |
| Lvalues( | |
| TupleExpr:2( | |
| NameExpr(a) | |
| NameExpr(b)) | |
| NameExpr(c)) | |
| IntExpr(6))) | |
| [case testOperatorAssignment] | |
| x += 1 | |
| y -= 2 | |
| z *= 3 | |
| [out] | |
| MypyFile:1( | |
| OperatorAssignmentStmt:1( | |
| + | |
| NameExpr(x) | |
| IntExpr(1)) | |
| OperatorAssignmentStmt:2( | |
| - | |
| NameExpr(y) | |
| IntExpr(2)) | |
| OperatorAssignmentStmt:3( | |
| * | |
| NameExpr(z) | |
| IntExpr(3))) | |
| [case testIfStmt] | |
| if x: | |
| y | |
| if a: | |
| b | |
| else: | |
| c | |
| [out] | |
| MypyFile:1( | |
| IfStmt:1( | |
| If( | |
| NameExpr(x)) | |
| Then( | |
| ExpressionStmt:2( | |
| NameExpr(y)))) | |
| IfStmt:3( | |
| If( | |
| NameExpr(a)) | |
| Then( | |
| ExpressionStmt:4( | |
| NameExpr(b))) | |
| Else( | |
| ExpressionStmt:6( | |
| NameExpr(c))))) | |
| [case testIfStmtElif] | |
| if a: | |
| b | |
| elif c: | |
| d | |
| else: | |
| e | |
| [out] | |
| MypyFile:1( | |
| IfStmt:1( | |
| If( | |
| NameExpr(a)) | |
| Then( | |
| ExpressionStmt:2( | |
| NameExpr(b))) | |
| Else( | |
| IfStmt:3( | |
| If( | |
| NameExpr(c)) | |
| Then( | |
| ExpressionStmt:4( | |
| NameExpr(d))) | |
| Else( | |
| ExpressionStmt:6( | |
| NameExpr(e))))))) | |
| [case testIfStmtMultipleElif] | |
| if 1: | |
| 2 | |
| elif 3: | |
| 4 | |
| elif 5: | |
| 6 | |
| else: | |
| 7 | |
| [out] | |
| MypyFile:1( | |
| IfStmt:1( | |
| If( | |
| IntExpr(1)) | |
| Then( | |
| ExpressionStmt:2( | |
| IntExpr(2))) | |
| Else( | |
| IfStmt:3( | |
| If( | |
| IntExpr(3)) | |
| Then( | |
| ExpressionStmt:4( | |
| IntExpr(4))) | |
| Else( | |
| IfStmt:5( | |
| If( | |
| IntExpr(5)) | |
| Then( | |
| ExpressionStmt:6( | |
| IntExpr(6))) | |
| Else( | |
| ExpressionStmt:8( | |
| IntExpr(7))))))))) | |
| [case testIfStmtElifNoElse] | |
| if a: | |
| b | |
| elif c: | |
| d | |
| [out] | |
| MypyFile:1( | |
| IfStmt:1( | |
| If( | |
| NameExpr(a)) | |
| Then( | |
| ExpressionStmt:2( | |
| NameExpr(b))) | |
| Else( | |
| IfStmt:3( | |
| If( | |
| NameExpr(c)) | |
| Then( | |
| ExpressionStmt:4( | |
| NameExpr(d))))))) | |
| [case testWhileStmt] | |
| while a: | |
| b | |
| while c: | |
| d | |
| else: | |
| e | |
| [out] | |
| MypyFile:1( | |
| WhileStmt:1( | |
| NameExpr(a) | |
| Block:2( | |
| ExpressionStmt:2( | |
| NameExpr(b)))) | |
| WhileStmt:3( | |
| NameExpr(c) | |
| Block:4( | |
| ExpressionStmt:4( | |
| NameExpr(d))) | |
| Else( | |
| ExpressionStmt:6( | |
| NameExpr(e))))) | |
| [case testIndexExpr] | |
| a[b] | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| IndexExpr:1( | |
| NameExpr(a) | |
| NameExpr(b)))) | |
| [case testListAndSetExpr] | |
| a = [] | |
| b = [1, 2] | |
| c = {3} | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(a) | |
| ListExpr:1()) | |
| AssignmentStmt:2( | |
| NameExpr(b) | |
| ListExpr:2( | |
| IntExpr(1) | |
| IntExpr(2))) | |
| AssignmentStmt:3( | |
| NameExpr(c) | |
| SetExpr:3( | |
| IntExpr(3)))) | |
| [case testBoolOpAnd] | |
| a and b | |
| a and b and c | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| OpExpr:1( | |
| and | |
| NameExpr(a) | |
| NameExpr(b))) | |
| ExpressionStmt:2( | |
| OpExpr:2( | |
| and | |
| NameExpr(a) | |
| OpExpr:2( | |
| and | |
| NameExpr(b) | |
| NameExpr(c))))) | |
| [case testBoolOpOr] | |
| x or y | |
| 1 or 2 or 3 | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| OpExpr:1( | |
| or | |
| NameExpr(x) | |
| NameExpr(y))) | |
| ExpressionStmt:2( | |
| OpExpr:2( | |
| or | |
| IntExpr(1) | |
| OpExpr:2( | |
| or | |
| IntExpr(2) | |
| IntExpr(3))))) | |
| [case testComparisonSimple] | |
| a < b | |
| x == y | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| ComparisonExpr:1( | |
| < | |
| NameExpr(a) | |
| NameExpr(b))) | |
| ExpressionStmt:2( | |
| ComparisonExpr:2( | |
| == | |
| NameExpr(x) | |
| NameExpr(y)))) | |
| [case testComparisonChained] | |
| a < b < c | |
| x == y != z | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| ComparisonExpr:1( | |
| < | |
| < | |
| NameExpr(a) | |
| NameExpr(b) | |
| NameExpr(c))) | |
| ExpressionStmt:2( | |
| ComparisonExpr:2( | |
| == | |
| != | |
| NameExpr(x) | |
| NameExpr(y) | |
| NameExpr(z)))) | |
| [case testComparisonIsNotIn] | |
| a is b | |
| x is not y | |
| z in w | |
| q not in r | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| ComparisonExpr:1( | |
| is | |
| NameExpr(a) | |
| NameExpr(b))) | |
| ExpressionStmt:2( | |
| ComparisonExpr:2( | |
| is not | |
| NameExpr(x) | |
| NameExpr(y))) | |
| ExpressionStmt:3( | |
| ComparisonExpr:3( | |
| in | |
| NameExpr(z) | |
| NameExpr(w))) | |
| ExpressionStmt:4( | |
| ComparisonExpr:4( | |
| not in | |
| NameExpr(q) | |
| NameExpr(r)))) | |
| [case testLiterals] | |
| (None, True, False, ...) | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| TupleExpr:1( | |
| NameExpr(None) | |
| NameExpr(True) | |
| NameExpr(False) | |
| Ellipsis))) | |
| [case testSimpleFunction] | |
| def foo(): | |
| x = 1 | |
| [out] | |
| MypyFile:1( | |
| FuncDef:1( | |
| foo | |
| Block:2( | |
| AssignmentStmt:2( | |
| NameExpr(x) | |
| IntExpr(1))))) | |
| [case testFunctionWithArgs] | |
| def add(x, y): | |
| return x + y | |
| [out] | |
| MypyFile:1( | |
| FuncDef:1( | |
| add | |
| Args( | |
| Var(x) | |
| Var(y)) | |
| Block:2( | |
| ReturnStmt:2( | |
| OpExpr:2( | |
| + | |
| NameExpr(x) | |
| NameExpr(y)))))) | |
| [case testFunctionWithVarArgs] | |
| def foo(*args): | |
| pass | |
| [out] | |
| MypyFile:1( | |
| FuncDef:1( | |
| foo | |
| VarArg( | |
| Var(args)) | |
| Block:2( | |
| PassStmt:2()))) | |
| [case testFunctionWithKwargs] | |
| def bar(**kwargs): | |
| pass | |
| [out] | |
| MypyFile:1( | |
| FuncDef:1( | |
| bar | |
| DictVarArg( | |
| Var(kwargs)) | |
| Block:2( | |
| PassStmt:2()))) | |
| [case testFunctionWithKwOnly] | |
| def baz(x, *, y): | |
| pass | |
| [out] | |
| MypyFile:1( | |
| FuncDef:1( | |
| baz | |
| MaxPos(1) | |
| Args( | |
| Var(x) | |
| Var(y)) | |
| Block:2( | |
| PassStmt:2()))) | |
| [case testFunctionWithAllArgKinds] | |
| def complex_fn(a, b, *args, c, **kwargs): | |
| pass | |
| [out] | |
| MypyFile:1( | |
| FuncDef:1( | |
| complex_fn | |
| MaxPos(2) | |
| Args( | |
| Var(a) | |
| Var(b) | |
| Var(c)) | |
| VarArg( | |
| Var(args)) | |
| DictVarArg( | |
| Var(kwargs)) | |
| Block:2( | |
| PassStmt:2()))) | |
| [case testAsyncFunction] | |
| async def async_foo(): | |
| pass | |
| [out] | |
| MypyFile:1( | |
| FuncDef:1( | |
| async_foo | |
| Async | |
| Block:2( | |
| PassStmt:2()))) | |
| [case testFunctionWithDefaultArg] | |
| def greet(name="World"): | |
| pass | |
| [out] | |
| MypyFile:1( | |
| FuncDef:1( | |
| greet | |
| Args( | |
| default( | |
| Var(name) | |
| StrExpr(World))) | |
| Block:2( | |
| PassStmt:2()))) | |
| [case testFunctionWithMultipleDefaults] | |
| def add(x=1, y=2): | |
| return x | |
| [out] | |
| MypyFile:1( | |
| FuncDef:1( | |
| add | |
| Args( | |
| default( | |
| Var(x) | |
| IntExpr(1)) | |
| default( | |
| Var(y) | |
| IntExpr(2))) | |
| Block:2( | |
| ReturnStmt:2( | |
| NameExpr(x))))) | |
| [case testFunctionMixedDefaultsAndRegular] | |
| def func(a, b=5, c=10): | |
| pass | |
| [out] | |
| MypyFile:1( | |
| FuncDef:1( | |
| func | |
| Args( | |
| Var(a) | |
| default( | |
| Var(b) | |
| IntExpr(5)) | |
| default( | |
| Var(c) | |
| IntExpr(10))) | |
| Block:2( | |
| PassStmt:2()))) | |
| [case testFunctionWithKwOnlyDefault] | |
| def func(*, x=42): | |
| pass | |
| [out] | |
| MypyFile:1( | |
| FuncDef:1( | |
| func | |
| MaxPos(0) | |
| Args( | |
| default( | |
| Var(x) | |
| IntExpr(42))) | |
| Block:2( | |
| PassStmt:2()))) | |
| [case testCallWithKeywordArgs] | |
| foo(x=1, y=2) | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| CallExpr:1( | |
| NameExpr(foo) | |
| Args() | |
| KwArgs( | |
| x | |
| IntExpr(1)) | |
| KwArgs( | |
| y | |
| IntExpr(2))))) | |
| [case testCallMixedPositionalAndKeyword] | |
| bar(1, 2, x=3, y=4) | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| CallExpr:1( | |
| NameExpr(bar) | |
| Args( | |
| IntExpr(1) | |
| IntExpr(2)) | |
| KwArgs( | |
| x | |
| IntExpr(3)) | |
| KwArgs( | |
| y | |
| IntExpr(4))))) | |
| [case testCallWithStarArgs] | |
| f(1, *x, 2) | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| CallExpr:1( | |
| NameExpr(f) | |
| Args( | |
| IntExpr(1) | |
| NameExpr(x) | |
| IntExpr(2)) | |
| VarArg))) | |
| [case testCallWithDictStarArgs] | |
| f(**x) | |
| f(1, **y) | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| CallExpr:1( | |
| NameExpr(f) | |
| Args() | |
| DictVarArg( | |
| NameExpr(x)))) | |
| ExpressionStmt:2( | |
| CallExpr:2( | |
| NameExpr(f) | |
| Args( | |
| IntExpr(1)) | |
| DictVarArg( | |
| NameExpr(y))))) | |
| [case testCallWithAllArgTypes] | |
| f(1, *x, a=2, **y) | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| CallExpr:1( | |
| NameExpr(f) | |
| Args( | |
| IntExpr(1) | |
| NameExpr(x)) | |
| VarArg | |
| KwArgs( | |
| a | |
| IntExpr(2)) | |
| DictVarArg( | |
| NameExpr(y))))) | |
| [case testSimpleClass] | |
| class A: | |
| pass | |
| [out] | |
| MypyFile:1( | |
| ClassDef:1( | |
| A | |
| PassStmt:2())) | |
| [case testClassWithMethod] | |
| class Foo: | |
| def bar(self): | |
| return 1 | |
| [out] | |
| MypyFile:1( | |
| ClassDef:1( | |
| Foo | |
| FuncDef:2( | |
| bar | |
| Args( | |
| Var(self)) | |
| Block:3( | |
| ReturnStmt:3( | |
| IntExpr(1)))))) | |
| [case testClassWithSingleBase] | |
| class A(B): | |
| pass | |
| [out] | |
| MypyFile:1( | |
| ClassDef:1( | |
| A | |
| BaseTypeExpr( | |
| NameExpr(B)) | |
| PassStmt:2())) | |
| [case testClassWithMultipleBases] | |
| class Child(Base1, Base2): | |
| x = 1 | |
| [out] | |
| MypyFile:1( | |
| ClassDef:1( | |
| Child | |
| BaseTypeExpr( | |
| NameExpr(Base1) | |
| NameExpr(Base2)) | |
| AssignmentStmt:2( | |
| NameExpr(x) | |
| IntExpr(1)))) | |
| [case testFloatLiteral] | |
| x = 3.14 | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(x) | |
| FloatExpr(3.14))) | |
| [case testUnaryExpressions] | |
| -x | |
| +y | |
| ~z | |
| not w | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| UnaryExpr:1( | |
| - | |
| NameExpr(x))) | |
| ExpressionStmt:2( | |
| UnaryExpr:2( | |
| + | |
| NameExpr(y))) | |
| ExpressionStmt:3( | |
| UnaryExpr:3( | |
| ~ | |
| NameExpr(z))) | |
| ExpressionStmt:4( | |
| UnaryExpr:4( | |
| not | |
| NameExpr(w)))) | |
| [case testDictionaryExpression] | |
| {} | |
| {1:x} | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| DictExpr:1()) | |
| ExpressionStmt:2( | |
| DictExpr:2( | |
| IntExpr(1) | |
| NameExpr(x)))) | |
| [case testComplexLiteral] | |
| 1j | |
| 2.5j | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| ComplexExpr(1j)) | |
| ExpressionStmt:2( | |
| ComplexExpr(2.5j))) | |
| [case testSlices] | |
| x[1:2] | |
| x[:1] | |
| x[1:] | |
| x[:] | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| IndexExpr:1( | |
| NameExpr(x) | |
| SliceExpr:1( | |
| IntExpr(1) | |
| IntExpr(2)))) | |
| ExpressionStmt:2( | |
| IndexExpr:2( | |
| NameExpr(x) | |
| SliceExpr:2( | |
| <empty> | |
| IntExpr(1)))) | |
| ExpressionStmt:3( | |
| IndexExpr:3( | |
| NameExpr(x) | |
| SliceExpr:3( | |
| IntExpr(1) | |
| <empty>))) | |
| ExpressionStmt:4( | |
| IndexExpr:4( | |
| NameExpr(x) | |
| SliceExpr:4( | |
| <empty> | |
| <empty>)))) | |
| [case testSliceWithStride] | |
| x[1:2:3] | |
| x[1::2] | |
| x[:1:2] | |
| x[::2] | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| IndexExpr:1( | |
| NameExpr(x) | |
| SliceExpr:1( | |
| IntExpr(1) | |
| IntExpr(2) | |
| IntExpr(3)))) | |
| ExpressionStmt:2( | |
| IndexExpr:2( | |
| NameExpr(x) | |
| SliceExpr:2( | |
| IntExpr(1) | |
| <empty> | |
| IntExpr(2)))) | |
| ExpressionStmt:3( | |
| IndexExpr:3( | |
| NameExpr(x) | |
| SliceExpr:3( | |
| <empty> | |
| IntExpr(1) | |
| IntExpr(2)))) | |
| ExpressionStmt:4( | |
| IndexExpr:4( | |
| NameExpr(x) | |
| SliceExpr:4( | |
| <empty> | |
| <empty> | |
| IntExpr(2))))) | |
| [case testFunctionSignature] | |
| def f() -> int: | |
| pass | |
| def g() -> None: | |
| pass | |
| def h(x: foo.bar, y, z: x.y.z): | |
| pass | |
| [out] | |
| MypyFile:1( | |
| FuncDef:1( | |
| f | |
| def () -> int? | |
| Block:2( | |
| PassStmt:2())) | |
| FuncDef:3( | |
| g | |
| def () -> None? | |
| Block:4( | |
| PassStmt:4())) | |
| FuncDef:5( | |
| h | |
| Args( | |
| Var(x) | |
| Var(y) | |
| Var(z)) | |
| def (x: foo.bar?, y: Any, z: x.y.z?) -> Any | |
| Block:6( | |
| PassStmt:6()))) | |
| [case testFunctionSignature2] | |
| def f(x: a[b]) -> c.d[e.f.g[h], i]: | |
| pass | |
| [out] | |
| MypyFile:1( | |
| FuncDef:1( | |
| f | |
| Args( | |
| Var(x)) | |
| def (x: a?[b?]) -> c.d?[e.f.g?[h?], i?] | |
| Block:2( | |
| PassStmt:2()))) | |
| [case testUnionTypes] | |
| def f(x: int | str) -> bool | None: | |
| pass | |
| [out] | |
| MypyFile:1( | |
| FuncDef:1( | |
| f | |
| Args( | |
| Var(x)) | |
| def (x: int? | str?) -> bool? | None? | |
| Block:2( | |
| PassStmt:2()))) | |
| [case testAnnotatedAssignment] | |
| x: int | |
| y: str = "hello" | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(x) | |
| TempNode:1( | |
| Any) | |
| int?) | |
| AssignmentStmt:2( | |
| NameExpr(y) | |
| StrExpr(hello) | |
| str?)) | |
| [case testImportStatements] | |
| import x | |
| import a, b | |
| import y as z | |
| [out] | |
| MypyFile:1( | |
| Import:1(x) | |
| Import:2(a, b) | |
| Import:3(y : z)) | |
| [case testImportFromStatements] | |
| from os import path | |
| from sys import argv, exit | |
| from typing import List as L | |
| from . import foo | |
| from .. import bar | |
| from .pkg import baz | |
| [out] | |
| MypyFile:1( | |
| ImportFrom:1(os, [path]) | |
| ImportFrom:2(sys, [argv, exit]) | |
| ImportFrom:3(typing, [List : L]) | |
| ImportFrom:4(., [foo]) | |
| ImportFrom:5(.., [bar]) | |
| ImportFrom:6(.pkg, [baz])) | |
| [case testImportAllStatements] | |
| from os import * | |
| from . import * | |
| from .. import * | |
| from .pkg import * | |
| [out] | |
| MypyFile:1( | |
| ImportAll:1(os) | |
| ImportAll:2(.) | |
| ImportAll:3(..) | |
| ImportAll:4(.pkg)) | |
| [case testRaiseStatements] | |
| raise | |
| raise ValueError | |
| raise ValueError("error message") | |
| raise KeyError from e | |
| [out] | |
| MypyFile:1( | |
| RaiseStmt:1() | |
| RaiseStmt:2( | |
| NameExpr(ValueError)) | |
| RaiseStmt:3( | |
| CallExpr:3( | |
| NameExpr(ValueError) | |
| Args( | |
| StrExpr(error message)))) | |
| RaiseStmt:4( | |
| NameExpr(KeyError) | |
| NameExpr(e))) | |
| [case testAssertStatements] | |
| assert x | |
| assert x == y | |
| assert condition, "error message" | |
| [out] | |
| MypyFile:1( | |
| AssertStmt:1( | |
| NameExpr(x)) | |
| AssertStmt:2( | |
| ComparisonExpr:2( | |
| == | |
| NameExpr(x) | |
| NameExpr(y))) | |
| AssertStmt:3( | |
| NameExpr(condition) | |
| StrExpr(error message))) | |
| [case testForStatements] | |
| for x in items: | |
| pass | |
| for i, j in pairs: | |
| x = 1 | |
| for y in range(10): | |
| break | |
| else: | |
| continue | |
| [out] | |
| MypyFile:1( | |
| ForStmt:1( | |
| NameExpr(x) | |
| NameExpr(items) | |
| Block:2( | |
| PassStmt:2())) | |
| ForStmt:3( | |
| TupleExpr:3( | |
| NameExpr(i) | |
| NameExpr(j)) | |
| NameExpr(pairs) | |
| Block:4( | |
| AssignmentStmt:4( | |
| NameExpr(x) | |
| IntExpr(1)))) | |
| ForStmt:5( | |
| NameExpr(y) | |
| CallExpr:5( | |
| NameExpr(range) | |
| Args( | |
| IntExpr(10))) | |
| Block:6( | |
| BreakStmt:6()) | |
| Else( | |
| ContinueStmt:8()))) | |
| [case testWithStatements] | |
| with f: | |
| pass | |
| with open("file") as f: | |
| x = 1 | |
| with a as x, b as y: | |
| break | |
| [out] | |
| MypyFile:1( | |
| WithStmt:1( | |
| Expr( | |
| NameExpr(f)) | |
| Block:2( | |
| PassStmt:2())) | |
| WithStmt:3( | |
| Expr( | |
| CallExpr:3( | |
| NameExpr(open) | |
| Args( | |
| StrExpr(file)))) | |
| Target( | |
| NameExpr(f)) | |
| Block:4( | |
| AssignmentStmt:4( | |
| NameExpr(x) | |
| IntExpr(1)))) | |
| WithStmt:5( | |
| Expr( | |
| NameExpr(a)) | |
| Target( | |
| NameExpr(x)) | |
| Expr( | |
| NameExpr(b)) | |
| Target( | |
| NameExpr(y)) | |
| Block:6( | |
| BreakStmt:6()))) | |
| [case testBreakAndContinue] | |
| while True: | |
| break | |
| while x: | |
| continue | |
| while y: | |
| if z: | |
| break | |
| else: | |
| continue | |
| [out] | |
| MypyFile:1( | |
| WhileStmt:1( | |
| NameExpr(True) | |
| Block:2( | |
| BreakStmt:2())) | |
| WhileStmt:3( | |
| NameExpr(x) | |
| Block:4( | |
| ContinueStmt:4())) | |
| WhileStmt:5( | |
| NameExpr(y) | |
| Block:6( | |
| IfStmt:6( | |
| If( | |
| NameExpr(z)) | |
| Then( | |
| BreakStmt:7()) | |
| Else( | |
| ContinueStmt:9()))))) | |
| [case testGeneratorExpressions] | |
| (x for x in items) | |
| (x * 2 for x in range(10) if x > 5) | |
| (x + y for x in range(3) for y in range(2)) | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| GeneratorExpr:1( | |
| NameExpr(x) | |
| NameExpr(x) | |
| NameExpr(items))) | |
| ExpressionStmt:2( | |
| GeneratorExpr:2( | |
| OpExpr:2( | |
| * | |
| NameExpr(x) | |
| IntExpr(2)) | |
| NameExpr(x) | |
| CallExpr:2( | |
| NameExpr(range) | |
| Args( | |
| IntExpr(10))) | |
| ComparisonExpr:2( | |
| > | |
| NameExpr(x) | |
| IntExpr(5)))) | |
| ExpressionStmt:3( | |
| GeneratorExpr:3( | |
| OpExpr:3( | |
| + | |
| NameExpr(x) | |
| NameExpr(y)) | |
| NameExpr(x) | |
| NameExpr(y) | |
| CallExpr:3( | |
| NameExpr(range) | |
| Args( | |
| IntExpr(3))) | |
| CallExpr:3( | |
| NameExpr(range) | |
| Args( | |
| IntExpr(2)))))) | |
| [case testYieldExpressions] | |
| def gen(): | |
| yield | |
| yield 1 | |
| yield from items | |
| [out] | |
| MypyFile:1( | |
| FuncDef:1( | |
| gen | |
| Block:2( | |
| ExpressionStmt:2( | |
| YieldExpr:2()) | |
| ExpressionStmt:3( | |
| YieldExpr:3( | |
| IntExpr(1))) | |
| ExpressionStmt:4( | |
| YieldFromExpr:4( | |
| NameExpr(items)))))) | |
| [case testListAndSetComprehensions] | |
| a = [x for x in items] | |
| b = [x * 2 for x in range(10) if x > 5] | |
| c = {y for y in data} | |
| d = {z + 1 for z in nums if z < 100} | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(a) | |
| ListComprehension:1( | |
| GeneratorExpr:1( | |
| NameExpr(x) | |
| NameExpr(x) | |
| NameExpr(items)))) | |
| AssignmentStmt:2( | |
| NameExpr(b) | |
| ListComprehension:2( | |
| GeneratorExpr:2( | |
| OpExpr:2( | |
| * | |
| NameExpr(x) | |
| IntExpr(2)) | |
| NameExpr(x) | |
| CallExpr:2( | |
| NameExpr(range) | |
| Args( | |
| IntExpr(10))) | |
| ComparisonExpr:2( | |
| > | |
| NameExpr(x) | |
| IntExpr(5))))) | |
| AssignmentStmt:3( | |
| NameExpr(c) | |
| SetComprehension:3( | |
| GeneratorExpr:3( | |
| NameExpr(y) | |
| NameExpr(y) | |
| NameExpr(data)))) | |
| AssignmentStmt:4( | |
| NameExpr(d) | |
| SetComprehension:4( | |
| GeneratorExpr:4( | |
| OpExpr:4( | |
| + | |
| NameExpr(z) | |
| IntExpr(1)) | |
| NameExpr(z) | |
| NameExpr(nums) | |
| ComparisonExpr:4( | |
| < | |
| NameExpr(z) | |
| IntExpr(100)))))) | |
| [case testDictComprehensions] | |
| a = {k: v for k, v in items} | |
| b = {x: x * 2 for x in range(10) if x > 5} | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(a) | |
| DictionaryComprehension:1( | |
| NameExpr(k) | |
| NameExpr(v) | |
| TupleExpr:1( | |
| NameExpr(k) | |
| NameExpr(v)) | |
| NameExpr(items))) | |
| AssignmentStmt:2( | |
| NameExpr(b) | |
| DictionaryComprehension:2( | |
| NameExpr(x) | |
| OpExpr:2( | |
| * | |
| NameExpr(x) | |
| IntExpr(2)) | |
| NameExpr(x) | |
| CallExpr:2( | |
| NameExpr(range) | |
| Args( | |
| IntExpr(10))) | |
| ComparisonExpr:2( | |
| > | |
| NameExpr(x) | |
| IntExpr(5))))) | |
| [case testDecoratedFuncDef] | |
| @dec | |
| def foo(): | |
| pass | |
| class C: | |
| @dec() | |
| @staticmethod | |
| def foo(): | |
| pass | |
| [out] | |
| MypyFile:1( | |
| Decorator:1( | |
| Var(foo) | |
| NameExpr(dec) | |
| FuncDef:2( | |
| foo | |
| Block:3( | |
| PassStmt:3()))) | |
| ClassDef:4( | |
| C | |
| Decorator:5( | |
| Var(foo) | |
| CallExpr:5( | |
| NameExpr(dec) | |
| Args()) | |
| NameExpr(staticmethod) | |
| FuncDef:7( | |
| foo | |
| Block:8( | |
| PassStmt:8()))))) | |
| [case testTryFinally] | |
| try: | |
| x | |
| finally: | |
| y | |
| [out] | |
| MypyFile:1( | |
| TryStmt:1( | |
| Block:2( | |
| ExpressionStmt:2( | |
| NameExpr(x))) | |
| Finally( | |
| ExpressionStmt:4( | |
| NameExpr(y))))) | |
| [case testTryExcept] | |
| try: | |
| x | |
| except Exception: | |
| y | |
| [out] | |
| MypyFile:1( | |
| TryStmt:1( | |
| Block:2( | |
| ExpressionStmt:2( | |
| NameExpr(x))) | |
| NameExpr(Exception) | |
| Block:4( | |
| ExpressionStmt:4( | |
| NameExpr(y))))) | |
| [case testTryExceptWithVar] | |
| try: | |
| x | |
| except Exception as e: | |
| y | |
| [out] | |
| MypyFile:1( | |
| TryStmt:1( | |
| Block:2( | |
| ExpressionStmt:2( | |
| NameExpr(x))) | |
| NameExpr(Exception) | |
| NameExpr(e) | |
| Block:4( | |
| ExpressionStmt:4( | |
| NameExpr(y))))) | |
| [case testTryExceptElse] | |
| try: | |
| x | |
| except Exception: | |
| y | |
| else: | |
| z | |
| [out] | |
| MypyFile:1( | |
| TryStmt:1( | |
| Block:2( | |
| ExpressionStmt:2( | |
| NameExpr(x))) | |
| NameExpr(Exception) | |
| Block:4( | |
| ExpressionStmt:4( | |
| NameExpr(y))) | |
| Else( | |
| ExpressionStmt:6( | |
| NameExpr(z))))) | |
| [case testTryMultipleExcept] | |
| try: | |
| x | |
| except ValueError: | |
| y | |
| except KeyError as e: | |
| z | |
| [out] | |
| MypyFile:1( | |
| TryStmt:1( | |
| Block:2( | |
| ExpressionStmt:2( | |
| NameExpr(x))) | |
| NameExpr(ValueError) | |
| Block:4( | |
| ExpressionStmt:4( | |
| NameExpr(y))) | |
| NameExpr(KeyError) | |
| NameExpr(e) | |
| Block:6( | |
| ExpressionStmt:6( | |
| NameExpr(z))))) | |
| [case testConditionalExprSimple] | |
| x if y else z | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| ConditionalExpr:1( | |
| Condition( | |
| NameExpr(y)) | |
| NameExpr(x) | |
| NameExpr(z)))) | |
| [case testFunctionWithCallableType] | |
| def f(x: Callable[[int, str], None]) -> None: | |
| pass | |
| [out] | |
| MypyFile:1( | |
| FuncDef:1( | |
| f | |
| Args( | |
| Var(x)) | |
| def (x: Callable?[<TypeList int?, str?>, None?]) -> None? | |
| Block:2( | |
| PassStmt:2()))) | |
| [case testFunctionWithEmptyCallableType] | |
| def g(callback: Callable[[], bool]) -> int: | |
| return 1 | |
| [out] | |
| MypyFile:1( | |
| FuncDef:1( | |
| g | |
| Args( | |
| Var(callback)) | |
| def (callback: Callable?[<TypeList >, bool?]) -> int? | |
| Block:2( | |
| ReturnStmt:2( | |
| IntExpr(1))))) | |
| [case testFunctionWithComplexCallableType] | |
| def h(f: Callable[[List[int], Dict[str, int]], Tuple[int, str]]) -> None: | |
| pass | |
| [out] | |
| MypyFile:1( | |
| FuncDef:1( | |
| h | |
| Args( | |
| Var(f)) | |
| def (f: Callable?[<TypeList List?[int?], Dict?[str?, int?]>, Tuple?[int?, str?]]) -> None? | |
| Block:2( | |
| PassStmt:2()))) | |
| [case testFunctionWithEllipsisCallableType] | |
| def f(callback: Callable[..., int]) -> None: | |
| pass | |
| [out] | |
| MypyFile:1( | |
| FuncDef:1( | |
| f | |
| Args( | |
| Var(callback)) | |
| def (callback: Callable?[..., int?]) -> None? | |
| Block:2( | |
| PassStmt:2()))) | |
| [case testCallableWithArgConstructor] | |
| from typing import Callable | |
| from mypy_extensions import Arg | |
| def f(x: Callable[[Arg(int, 'x'), Arg(str, 'y')], bool]) -> None: | |
| pass | |
| [out] | |
| MypyFile:1( | |
| ImportFrom:1(typing, [Callable]) | |
| ImportFrom:2(mypy_extensions, [Arg]) | |
| FuncDef:3( | |
| f | |
| Args( | |
| Var(x)) | |
| def (x: Callable?[<TypeList Arg(int?, x), Arg(str?, y)>, bool?]) -> None? | |
| Block:4( | |
| PassStmt:4()))) | |
| [case testCallableWithArgConstructorKeywordSyntax] | |
| from typing import Callable | |
| from mypy_extensions import Arg | |
| def f(callback: Callable[[Arg(type=int, name='value')], str]) -> None: | |
| pass | |
| [out] | |
| MypyFile:1( | |
| ImportFrom:1(typing, [Callable]) | |
| ImportFrom:2(mypy_extensions, [Arg]) | |
| FuncDef:3( | |
| f | |
| Args( | |
| Var(callback)) | |
| def (callback: Callable?[<TypeList Arg(int?, value)>, str?]) -> None? | |
| Block:4( | |
| PassStmt:4()))) | |
| [case testCallableWithArgNoName] | |
| from typing import Callable | |
| from mypy_extensions import Arg | |
| def f(x: Callable[[Arg(int)], bool]) -> None: | |
| pass | |
| [out] | |
| MypyFile:1( | |
| ImportFrom:1(typing, [Callable]) | |
| ImportFrom:2(mypy_extensions, [Arg]) | |
| FuncDef:3( | |
| f | |
| Args( | |
| Var(x)) | |
| def (x: Callable?[<TypeList Arg(int?)>, bool?]) -> None? | |
| Block:4( | |
| PassStmt:4()))) | |
| [case testLiteralTypes] | |
| x: Literal[True, False] | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(x) | |
| TempNode:1( | |
| Any) | |
| Literal?[True, False])) | |
| [case testLiteralIntTypes] | |
| x: Literal[1] | |
| y: Literal[1, 2, 3] | |
| z: Literal[-1] | |
| w: Literal[-1, 0, 1] | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(x) | |
| TempNode:1( | |
| Any) | |
| Literal?[1]) | |
| AssignmentStmt:2( | |
| NameExpr(y) | |
| TempNode:2( | |
| Any) | |
| Literal?[1, 2, 3]) | |
| AssignmentStmt:3( | |
| NameExpr(z) | |
| TempNode:3( | |
| Any) | |
| Literal?[-1]) | |
| AssignmentStmt:4( | |
| NameExpr(w) | |
| TempNode:4( | |
| Any) | |
| Literal?[-1, 0, 1])) | |
| [case testDelStmt] | |
| del x | |
| del x[0], y[1] | |
| del a.b | |
| [out] | |
| MypyFile:1( | |
| DelStmt:1( | |
| NameExpr(x)) | |
| DelStmt:2( | |
| TupleExpr:2( | |
| IndexExpr:2( | |
| NameExpr(x) | |
| IntExpr(0)) | |
| IndexExpr:2( | |
| NameExpr(y) | |
| IntExpr(1)))) | |
| DelStmt:3( | |
| MemberExpr:3( | |
| NameExpr(a) | |
| b))) | |
| [case testFString] | |
| f"foo {x}" | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| CallExpr:1( | |
| MemberExpr:1( | |
| StrExpr() | |
| join) | |
| Args( | |
| ListExpr:1( | |
| StrExpr(foo ) | |
| CallExpr:1( | |
| MemberExpr:1( | |
| StrExpr({:{}}) | |
| format) | |
| Args( | |
| NameExpr(x) | |
| StrExpr()))))))) | |
| [case testFStringWithConversion] | |
| x = 'mypy' | |
| F'Hello {x!r}' | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(x) | |
| StrExpr(mypy)) | |
| ExpressionStmt:2( | |
| CallExpr:2( | |
| MemberExpr:2( | |
| StrExpr() | |
| join) | |
| Args( | |
| ListExpr:2( | |
| StrExpr(Hello ) | |
| CallExpr:2( | |
| MemberExpr:2( | |
| StrExpr({!r:{}}) | |
| format) | |
| Args( | |
| NameExpr(x) | |
| StrExpr()))))))) | |
| [case testFStringTrivial] | |
| f"foo" | |
| f"{x}" | |
| f"foo" "bar" | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| StrExpr(foo)) | |
| ExpressionStmt:2( | |
| CallExpr:2( | |
| MemberExpr:2( | |
| StrExpr({:{}}) | |
| format) | |
| Args( | |
| NameExpr(x) | |
| StrExpr()))) | |
| ExpressionStmt:3( | |
| StrExpr(foobar))) | |
| [case testFStringWithOnlyFormatSpecifier] | |
| x = 'mypy' | |
| f'Hello {x:<30}' | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(x) | |
| StrExpr(mypy)) | |
| ExpressionStmt:2( | |
| CallExpr:2( | |
| MemberExpr:2( | |
| StrExpr() | |
| join) | |
| Args( | |
| ListExpr:2( | |
| StrExpr(Hello ) | |
| CallExpr:2( | |
| MemberExpr:2( | |
| StrExpr({:{}}) | |
| format) | |
| Args( | |
| NameExpr(x) | |
| StrExpr(<30)))))))) | |
| [case testFStringWithFormatSpecifierExpression] | |
| x = 'mypy' | |
| y = 30 | |
| f'Hello {x!s:<{y+y}}' | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(x) | |
| StrExpr(mypy)) | |
| AssignmentStmt:2( | |
| NameExpr(y) | |
| IntExpr(30)) | |
| ExpressionStmt:3( | |
| CallExpr:3( | |
| MemberExpr:3( | |
| StrExpr() | |
| join) | |
| Args( | |
| ListExpr:3( | |
| StrExpr(Hello ) | |
| CallExpr:3( | |
| MemberExpr:3( | |
| StrExpr({!s:{}}) | |
| format) | |
| Args( | |
| NameExpr(x) | |
| CallExpr:3( | |
| MemberExpr:3( | |
| StrExpr() | |
| join) | |
| Args( | |
| ListExpr:3( | |
| StrExpr(<) | |
| CallExpr:3( | |
| MemberExpr:3( | |
| StrExpr({:{}}) | |
| format) | |
| Args( | |
| OpExpr:3( | |
| + | |
| NameExpr(y) | |
| NameExpr(y)) | |
| StrExpr())))))))))))) | |
| [case testSimpleLambda] | |
| lambda: 1 | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| LambdaExpr:1( | |
| Block:1( | |
| ReturnStmt:1( | |
| IntExpr(1)))))) | |
| [case testLambdaWithOneArg] | |
| lambda x: y + 1 | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| LambdaExpr:1( | |
| Args( | |
| Var(x)) | |
| Block:1( | |
| ReturnStmt:1( | |
| OpExpr:1( | |
| + | |
| NameExpr(y) | |
| IntExpr(1))))))) | |
| [case testLambdaWithMultipleArgs] | |
| lambda x, y: x + y | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| LambdaExpr:1( | |
| Args( | |
| Var(x) | |
| Var(y)) | |
| Block:1( | |
| ReturnStmt:1( | |
| OpExpr:1( | |
| + | |
| NameExpr(x) | |
| NameExpr(y))))))) | |
| [case testLambdaWithDefault] | |
| lambda x=2: x | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| LambdaExpr:1( | |
| Args( | |
| default( | |
| Var(x) | |
| IntExpr(2))) | |
| Block:1( | |
| ReturnStmt:1( | |
| NameExpr(x)))))) | |
| [case testLambdaInCall] | |
| map(lambda x: x * 2, items) | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| CallExpr:1( | |
| NameExpr(map) | |
| Args( | |
| LambdaExpr:1( | |
| Args( | |
| Var(x)) | |
| Block:1( | |
| ReturnStmt:1( | |
| OpExpr:1( | |
| * | |
| NameExpr(x) | |
| IntExpr(2))))) | |
| NameExpr(items))))) | |
| [case testNamedExprSimple] | |
| if (x := 1): | |
| pass | |
| [out] | |
| MypyFile:1( | |
| IfStmt:1( | |
| If( | |
| AssignmentExpr:1( | |
| NameExpr(x) | |
| IntExpr(1))) | |
| Then( | |
| PassStmt:2()))) | |
| [case testStarExpression] | |
| *a | |
| *a, b | |
| a, *b | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| StarExpr:1( | |
| NameExpr(a))) | |
| ExpressionStmt:2( | |
| TupleExpr:2( | |
| StarExpr:2( | |
| NameExpr(a)) | |
| NameExpr(b))) | |
| ExpressionStmt:3( | |
| TupleExpr:3( | |
| NameExpr(a) | |
| StarExpr:3( | |
| NameExpr(b))))) | |
| [case testBytesLiteral] | |
| b"foo" | |
| b"foobar" | |
| b"x\\n\\'" | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| BytesExpr(foo)) | |
| ExpressionStmt:2( | |
| BytesExpr(foobar)) | |
| ExpressionStmt:3( | |
| BytesExpr(x\\n\\'))) | |
| [case testBytesLiteralWithEscapes] | |
| b'\r\n\t\x2f\xbe' | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| BytesExpr(\r\n\t/\xbe))) | |
| [case testBytesLiteralOctalEscapes] | |
| b'\1\476' | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| BytesExpr(\x01>))) | |
| [case testGlobalAndNonlocal] | |
| x = 1 | |
| y = 2 | |
| def outer(): | |
| global x | |
| def inner(): | |
| nonlocal y | |
| global z | |
| y = 3 | |
| z = 4 | |
| x = 5 | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(x) | |
| IntExpr(1)) | |
| AssignmentStmt:2( | |
| NameExpr(y) | |
| IntExpr(2)) | |
| FuncDef:3( | |
| outer | |
| Block:4( | |
| GlobalDecl:4( | |
| x) | |
| FuncDef:5( | |
| inner | |
| Block:6( | |
| NonlocalDecl:6( | |
| y) | |
| GlobalDecl:7( | |
| z) | |
| AssignmentStmt:8( | |
| NameExpr(y) | |
| IntExpr(3)) | |
| AssignmentStmt:9( | |
| NameExpr(z) | |
| IntExpr(4)))) | |
| AssignmentStmt:10( | |
| NameExpr(x) | |
| IntExpr(5))))) | |
| [case testAwaitExpression] | |
| async def foo(): | |
| x = await bar() | |
| return await baz(x) | |
| [out] | |
| MypyFile:1( | |
| FuncDef:1( | |
| foo | |
| Async | |
| Block:2( | |
| AssignmentStmt:2( | |
| NameExpr(x) | |
| AwaitExpr:2( | |
| CallExpr:2( | |
| NameExpr(bar) | |
| Args()))) | |
| ReturnStmt:3( | |
| AwaitExpr:3( | |
| CallExpr:3( | |
| NameExpr(baz) | |
| Args( | |
| NameExpr(x)))))))) | |
| [case testFunctionOverload] | |
| @overload | |
| def f() -> x: pass | |
| @overload | |
| def f() -> y: pass | |
| [out] | |
| MypyFile:1( | |
| OverloadedFuncDef:1( | |
| Decorator:1( | |
| Var(f) | |
| NameExpr(overload) | |
| FuncDef:2( | |
| f | |
| def () -> x? | |
| Block:2( | |
| PassStmt:2()))) | |
| Decorator:3( | |
| Var(f) | |
| NameExpr(overload) | |
| FuncDef:4( | |
| f | |
| def () -> y? | |
| Block:4( | |
| PassStmt:4()))))) | |
| [case testFunctionOverloadWithImplementation] | |
| @overload | |
| def f(a: x) -> x: ... | |
| @overload | |
| def f(a: y) -> y: ... | |
| def f(a): pass | |
| [out] | |
| MypyFile:1( | |
| OverloadedFuncDef:1( | |
| Decorator:1( | |
| Var(f) | |
| NameExpr(overload) | |
| FuncDef:2( | |
| f | |
| Args( | |
| Var(a)) | |
| def (a: x?) -> x? | |
| Block:2( | |
| ExpressionStmt:2( | |
| Ellipsis)))) | |
| Decorator:3( | |
| Var(f) | |
| NameExpr(overload) | |
| FuncDef:4( | |
| f | |
| Args( | |
| Var(a)) | |
| def (a: y?) -> y? | |
| Block:4( | |
| ExpressionStmt:4( | |
| Ellipsis)))) | |
| FuncDef:5( | |
| f | |
| Args( | |
| Var(a)) | |
| Block:5( | |
| PassStmt:5())))) | |
| [case testTypeIgnores] | |
| x = 1 # type: ignore | |
| y = ( | |
| 2 # type: ignore # Comment | |
| ) | |
| y = 1 # foo: ignore | |
| z = 1 #type: ignore[x] | |
| zz = 1 #type: ignore [ foo, arg-type ] | |
| [out] | |
| ignore: 1 | |
| ignore: 3 | |
| ignore: 6 [x] | |
| ignore: 7 [foo, arg-type] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(x) | |
| IntExpr(1)) | |
| AssignmentStmt:2( | |
| NameExpr(y) | |
| IntExpr(2)) | |
| AssignmentStmt:5( | |
| NameExpr(y) | |
| IntExpr(1)) | |
| AssignmentStmt:6( | |
| NameExpr(z) | |
| IntExpr(1)) | |
| AssignmentStmt:7( | |
| NameExpr(zz) | |
| IntExpr(1))) | |
| [case testMetaclass] | |
| class Foo(metaclass=Bar): pass | |
| [out] | |
| MypyFile:1( | |
| ClassDef:1( | |
| Foo | |
| Keywords(metaclass=NameExpr(Bar)) | |
| Metaclass(NameExpr(Bar)) | |
| PassStmt:1())) | |
| [case testClassWithKeywordArgs] | |
| class Foo(_root=None, total=False): pass | |
| [out] | |
| MypyFile:1( | |
| ClassDef:1( | |
| Foo | |
| Keywords(_root=NameExpr(None), total=NameExpr(False)) | |
| PassStmt:1())) | |
| [case testClassDecorator] | |
| @foo | |
| class X: pass | |
| @foo(bar) | |
| @x.y | |
| class Z: pass | |
| [out] | |
| MypyFile:1( | |
| ClassDef:2( | |
| X | |
| Decorators( | |
| NameExpr(foo)) | |
| PassStmt:2()) | |
| ClassDef:5( | |
| Z | |
| Decorators( | |
| CallExpr:3( | |
| NameExpr(foo) | |
| Args( | |
| NameExpr(bar))) | |
| MemberExpr:4( | |
| NameExpr(x) | |
| y)) | |
| PassStmt:5())) | |
| [case testLiteralStringType] | |
| from typing import Literal | |
| x: Literal["hello"] | |
| [out] | |
| MypyFile:1( | |
| ImportFrom:1(typing, [Literal]) | |
| AssignmentStmt:2( | |
| NameExpr(x) | |
| TempNode:2( | |
| Any) | |
| Literal?[hello?])) | |
| [case testLiteralStringWithEscapes] | |
| from typing import Literal | |
| x: Literal["hello\nworld"] | |
| [out] | |
| MypyFile:1( | |
| ImportFrom:1(typing, [Literal]) | |
| AssignmentStmt:2( | |
| NameExpr(x) | |
| TempNode:2( | |
| Any) | |
| Literal?['hello\nworld'])) | |
| [case testForwardReference] | |
| x: "int" | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(x) | |
| TempNode:1( | |
| Any) | |
| int?)) | |
| [case testForwardReferenceWithUnion] | |
| x: "int | str" | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(x) | |
| TempNode:1( | |
| Any) | |
| int? | str?)) | |
| [case testForwardReferenceWithComplexType] | |
| x: "list[int]" | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(x) | |
| TempNode:1( | |
| Any) | |
| list?[int?])) | |
| [case testMultipleLiteralStrings] | |
| from typing import Literal | |
| x: Literal["a", "b", "c"] | |
| [out] | |
| MypyFile:1( | |
| ImportFrom:1(typing, [Literal]) | |
| AssignmentStmt:2( | |
| NameExpr(x) | |
| TempNode:2( | |
| Any) | |
| Literal?[a?, b?, c?])) | |
| [case testLiteralBytesType] | |
| from typing import Literal | |
| x: Literal[b"foo"] | |
| y: Literal[b"hello\nworld", b"\x00\xff"] | |
| [out] | |
| MypyFile:1( | |
| ImportFrom:1(typing, [Literal]) | |
| AssignmentStmt:2( | |
| NameExpr(x) | |
| TempNode:2( | |
| Any) | |
| Literal?[b'foo']) | |
| AssignmentStmt:3( | |
| NameExpr(y) | |
| TempNode:3( | |
| Any) | |
| Literal?[b'hello\nworld', b'\x00\xff'])) | |
| [case testStripFunctionBodiesIfIgnoringErrors] | |
| # mypy: ignore-errors=True | |
| def f(self): | |
| self.x = 1 # Cannot define an attribute | |
| return 1 | |
| [out] | |
| MypyFile:1( | |
| FuncDef:2( | |
| f | |
| Args( | |
| Var(self)) | |
| Block:3())) | |
| [case testStripMethodBodiesIfIgnoringErrors] | |
| # mypy: ignore-errors=True | |
| class C: | |
| def f(self): | |
| x = self.x | |
| for x in y: | |
| pass | |
| with a as y: | |
| pass | |
| while self.foo(): | |
| self.bah() | |
| a[self.x] = 1 | |
| [out] | |
| MypyFile:1( | |
| ClassDef:2( | |
| C | |
| FuncDef:3( | |
| f | |
| Args( | |
| Var(self)) | |
| Block:4()))) | |
| [case testDoNotStripModuleTopLevelOrClassBody] | |
| # mypy: ignore-errors=True | |
| f() | |
| class C: | |
| x = 5 | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:2( | |
| CallExpr:2( | |
| NameExpr(f) | |
| Args())) | |
| ClassDef:3( | |
| C | |
| AssignmentStmt:4( | |
| NameExpr(x) | |
| IntExpr(5)))) | |
| [case testDoNotStripMethodThatAssignsToAttribute] | |
| # mypy: ignore-errors=True | |
| class C: | |
| def m1(self): | |
| self.x = 0 | |
| def m2(self): | |
| a, self.y = 0 | |
| [out] | |
| MypyFile:1( | |
| ClassDef:2( | |
| C | |
| FuncDef:3( | |
| m1 | |
| Args( | |
| Var(self)) | |
| Block:4( | |
| AssignmentStmt:4( | |
| MemberExpr:4( | |
| NameExpr(self) | |
| x) | |
| IntExpr(0)))) | |
| FuncDef:5( | |
| m2 | |
| Args( | |
| Var(self)) | |
| Block:6( | |
| AssignmentStmt:6( | |
| TupleExpr:6( | |
| NameExpr(a) | |
| MemberExpr:6( | |
| NameExpr(self) | |
| y)) | |
| IntExpr(0)))))) | |
| [case testDoNotStripMethodThatAssignsToAttributeWithinStatement] | |
| # mypy: ignore-errors=True | |
| class C: | |
| def m1(self): | |
| for x in y: | |
| self.x = 0 | |
| def m2(self): | |
| with x: | |
| self.y = 0 | |
| def m3(self): | |
| if x: | |
| self.y = 0 | |
| else: | |
| x = 4 | |
| [out] | |
| MypyFile:1( | |
| ClassDef:2( | |
| C | |
| FuncDef:3( | |
| m1 | |
| Args( | |
| Var(self)) | |
| Block:4( | |
| ForStmt:4( | |
| NameExpr(x) | |
| NameExpr(y) | |
| Block:5( | |
| AssignmentStmt:5( | |
| MemberExpr:5( | |
| NameExpr(self) | |
| x) | |
| IntExpr(0)))))) | |
| FuncDef:6( | |
| m2 | |
| Args( | |
| Var(self)) | |
| Block:7( | |
| WithStmt:7( | |
| Expr( | |
| NameExpr(x)) | |
| Block:8( | |
| AssignmentStmt:8( | |
| MemberExpr:8( | |
| NameExpr(self) | |
| y) | |
| IntExpr(0)))))) | |
| FuncDef:9( | |
| m3 | |
| Args( | |
| Var(self)) | |
| Block:10( | |
| IfStmt:10( | |
| If( | |
| NameExpr(x)) | |
| Then( | |
| AssignmentStmt:11( | |
| MemberExpr:11( | |
| NameExpr(self) | |
| y) | |
| IntExpr(0))) | |
| Else( | |
| AssignmentStmt:13( | |
| NameExpr(x) | |
| IntExpr(4)))))))) | |
| [case testDoNotStripMethodThatDefinesAttributeWithoutAssignment] | |
| # mypy: ignore-errors=True | |
| class C: | |
| def m1(self): | |
| with y as self.x: | |
| pass | |
| def m2(self): | |
| for self.y in x: | |
| pass | |
| [out] | |
| MypyFile:1( | |
| ClassDef:2( | |
| C | |
| FuncDef:3( | |
| m1 | |
| Args( | |
| Var(self)) | |
| Block:4( | |
| WithStmt:4( | |
| Expr( | |
| NameExpr(y)) | |
| Target( | |
| MemberExpr:4( | |
| NameExpr(self) | |
| x)) | |
| Block:5( | |
| PassStmt:5())))) | |
| FuncDef:6( | |
| m2 | |
| Args( | |
| Var(self)) | |
| Block:7( | |
| ForStmt:7( | |
| MemberExpr:7( | |
| NameExpr(self) | |
| y) | |
| NameExpr(x) | |
| Block:8( | |
| PassStmt:8())))))) | |
| [case testStripDecoratedFunctionOrMethod] | |
| # mypy: ignore-errors=True | |
| @deco | |
| def f(): | |
| x = 0 | |
| class C: | |
| @deco | |
| def m1(self): | |
| x = 0 | |
| @deco | |
| def m2(self): | |
| self.x = 0 | |
| [out] | |
| MypyFile:1( | |
| Decorator:2( | |
| Var(f) | |
| NameExpr(deco) | |
| FuncDef:3( | |
| f | |
| Block:4())) | |
| ClassDef:6( | |
| C | |
| Decorator:7( | |
| Var(m1) | |
| NameExpr(deco) | |
| FuncDef:8( | |
| m1 | |
| Args( | |
| Var(self)) | |
| Block:9())) | |
| Decorator:11( | |
| Var(m2) | |
| NameExpr(deco) | |
| FuncDef:12( | |
| m2 | |
| Args( | |
| Var(self)) | |
| Block:13( | |
| AssignmentStmt:13( | |
| MemberExpr:13( | |
| NameExpr(self) | |
| x) | |
| IntExpr(0))))))) | |
| [case testStripOverloadedMethod] | |
| # mypy: ignore-errors=True | |
| class C: | |
| @overload | |
| def m1(self, x: int) -> None: ... | |
| @overload | |
| def m1(self, x: str) -> None: ... | |
| def m1(self, x): | |
| x = 0 | |
| @overload | |
| def m2(self, x: int) -> None: ... | |
| @overload | |
| def m2(self, x: str) -> None: ... | |
| def m2(self, x): | |
| self.x = 0 | |
| [out] | |
| MypyFile:1( | |
| ClassDef:2( | |
| C | |
| OverloadedFuncDef:3( | |
| Decorator:3( | |
| Var(m1) | |
| NameExpr(overload) | |
| FuncDef:4( | |
| m1 | |
| Args( | |
| Var(self) | |
| Var(x)) | |
| def (self: Any, x: int?) -> None? | |
| Block:4( | |
| ExpressionStmt:4( | |
| Ellipsis)))) | |
| Decorator:5( | |
| Var(m1) | |
| NameExpr(overload) | |
| FuncDef:6( | |
| m1 | |
| Args( | |
| Var(self) | |
| Var(x)) | |
| def (self: Any, x: str?) -> None? | |
| Block:6( | |
| ExpressionStmt:6( | |
| Ellipsis)))) | |
| FuncDef:7( | |
| m1 | |
| Args( | |
| Var(self) | |
| Var(x)) | |
| Block:8())) | |
| OverloadedFuncDef:10( | |
| Decorator:10( | |
| Var(m2) | |
| NameExpr(overload) | |
| FuncDef:11( | |
| m2 | |
| Args( | |
| Var(self) | |
| Var(x)) | |
| def (self: Any, x: int?) -> None? | |
| Block:11( | |
| ExpressionStmt:11( | |
| Ellipsis)))) | |
| Decorator:12( | |
| Var(m2) | |
| NameExpr(overload) | |
| FuncDef:13( | |
| m2 | |
| Args( | |
| Var(self) | |
| Var(x)) | |
| def (self: Any, x: str?) -> None? | |
| Block:13( | |
| ExpressionStmt:13( | |
| Ellipsis)))) | |
| FuncDef:14( | |
| m2 | |
| Args( | |
| Var(self) | |
| Var(x)) | |
| Block:15( | |
| AssignmentStmt:15( | |
| MemberExpr:15( | |
| NameExpr(self) | |
| x) | |
| IntExpr(0))))))) | |
| [case testStripMethodInNestedClass] | |
| # mypy: ignore-errors=True | |
| class C: | |
| class D: | |
| def m1(self): | |
| self.x = 1 | |
| def m2(self): | |
| return self.x | |
| [out] | |
| MypyFile:1( | |
| ClassDef:2( | |
| C | |
| ClassDef:3( | |
| D | |
| FuncDef:4( | |
| m1 | |
| Args( | |
| Var(self)) | |
| Block:5( | |
| AssignmentStmt:5( | |
| MemberExpr:5( | |
| NameExpr(self) | |
| x) | |
| IntExpr(1)))) | |
| FuncDef:6( | |
| m2 | |
| Args( | |
| Var(self)) | |
| Block:7())))) | |
| [case testSuperExpr] | |
| super().x | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| SuperExpr:1( | |
| x | |
| CallExpr:1( | |
| NameExpr(super) | |
| Args())))) | |
| [case testTypeCommentSimple] | |
| x = [] # type: list[int] | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(x) | |
| ListExpr:1() | |
| list?[int?])) | |
| [case testTypeCommentMultiple] | |
| x = [] # type: list[int] | |
| y = {} # type: dict[str, int] | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(x) | |
| ListExpr:1() | |
| list?[int?]) | |
| AssignmentStmt:2( | |
| NameExpr(y) | |
| DictExpr:2() | |
| dict?[str?, int?])) | |
| [case testTypeCommentWithTrailingComment] | |
| x = [] # type: list[str] # This is a comment | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(x) | |
| ListExpr:1() | |
| list?[str?])) | |
| [case testTypeCommentUnion] | |
| x = None # type: str | None | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(x) | |
| NameExpr(None) | |
| str? | None?)) | |
| [case testNestedListAssignment] | |
| a1, [b1, c1] = a2, [b2, c2] | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| TupleExpr:1( | |
| NameExpr(a1) | |
| TupleExpr:1( | |
| NameExpr(b1) | |
| NameExpr(c1))) | |
| TupleExpr:1( | |
| NameExpr(a2) | |
| ListExpr:1( | |
| NameExpr(b2) | |
| NameExpr(c2))))) | |
| [case testSyntaxError1] | |
| x = [1 2] | |
| y = 2 | |
| [out] | |
| 1:8: error: Expected `,`, found int | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(x) | |
| ListExpr:1( | |
| IntExpr(1) | |
| IntExpr(2))) | |
| AssignmentStmt:2( | |
| NameExpr(y) | |
| IntExpr(2))) | |
| [case testSyntaxError2] | |
| f(a.) | |
| [out] | |
| 1:5: error: Expected an identifier | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| CallExpr:1( | |
| NameExpr(f) | |
| Args( | |
| MemberExpr:1( | |
| NameExpr(a) | |
| ))))) | |
| [case testSyntaxError3] | |
| f(a[]) | |
| [out] | |
| 1:5: error: Expected index or slice expression | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| CallExpr:1( | |
| NameExpr(f) | |
| Args( | |
| IndexExpr:1( | |
| NameExpr(a) | |
| NameExpr()))))) | |
| [case testSyntaxError4] | |
| from m import | |
| 1 | |
| [out] | |
| 1:14: error: Expected one or more symbol names after import | |
| MypyFile:1( | |
| ImportFrom:1(m, []) | |
| ExpressionStmt:2( | |
| IntExpr(1))) | |
| [case testSyntaxError5] | |
| from m | |
| 1 | |
| [out] | |
| 1:7: error: Expected `import`, found newline | |
| MypyFile:1( | |
| ImportFrom:1(m, []) | |
| ExpressionStmt:2( | |
| IntExpr(1))) | |
| [case testSyntaxError6] | |
| from m | |
| 1 | |
| [out] | |
| 1:7: error: Expected `import`, found newline | |
| MypyFile:1( | |
| ImportFrom:1(m, []) | |
| ExpressionStmt:2( | |
| IntExpr(1))) | |
| [case testSyntaxError7] | |
| def f(): | |
| g( | |
| h() | |
| def g(): ... | |
| [out] | |
| 3:8: error: Expected `)`, found newline | |
| MypyFile:1( | |
| FuncDef:1( | |
| f | |
| Block:2( | |
| ExpressionStmt:2( | |
| CallExpr:2( | |
| NameExpr(g) | |
| Args( | |
| CallExpr:3( | |
| NameExpr(h) | |
| Args())))))) | |
| FuncDef:5( | |
| g | |
| Block:5( | |
| ExpressionStmt:5( | |
| Ellipsis)))) | |
| [case testSyntaxError8] | |
| def f( | |
| x, | |
| y | |
| def g(): ... | |
| [out] | |
| 3:6: error: Expected `)`, found newline | |
| 5:1: error: Expected an indented block after function definition | |
| MypyFile:1( | |
| FuncDef:1( | |
| f | |
| Args( | |
| Var(x) | |
| Var(y)) | |
| Block:1()) | |
| FuncDef:5( | |
| g | |
| Block:5( | |
| ExpressionStmt:5( | |
| Ellipsis)))) | |
| [case testSyntaxError9] | |
| class A | |
| def f(): pass | |
| [out] | |
| 1:8: error: Expected `:`, found newline | |
| 3:1: error: Expected an indented block after `class` definition | |
| MypyFile:1( | |
| ClassDef:1( | |
| A) | |
| FuncDef:3( | |
| f | |
| Block:3( | |
| PassStmt:3()))) | |
| [case testSyntaxError10] | |
| (f() := 1) | |
| [out] | |
| 1:2: error: Assignment expression target must be an identifier | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| AssignmentExpr:1( | |
| NameExpr() | |
| IntExpr(1)))) | |
| [case testArgConstructorTooManyArgs] | |
| from typing import Callable | |
| from mypy_extensions import Arg | |
| def f(x: Callable[[Arg(int, 'x', 'extra')], bool]) -> None: | |
| pass | |
| [out] | |
| 3:19: error: Too many arguments for argument constructor | |
| MypyFile:1( | |
| ImportFrom:1(typing, [Callable]) | |
| ImportFrom:2(mypy_extensions, [Arg]) | |
| FuncDef:3( | |
| f | |
| Args( | |
| Var(x)) | |
| def (x: Callable?[<TypeList Arg(int?, x)>, bool?]) -> None? | |
| Block:4( | |
| PassStmt:4()))) | |
| [case testArgConstructorMultipleValuesForName] | |
| from typing import Callable | |
| from mypy_extensions import Arg | |
| def f(x: Callable[[Arg(int, 'x', name='y')], bool]) -> None: | |
| pass | |
| [out] | |
| 3:19: error: "Arg" gets multiple values for keyword argument "name" | |
| MypyFile:1( | |
| ImportFrom:1(typing, [Callable]) | |
| ImportFrom:2(mypy_extensions, [Arg]) | |
| FuncDef:3( | |
| f | |
| Args( | |
| Var(x)) | |
| def (x: Callable?[<TypeList Arg(int?, y)>, bool?]) -> None? | |
| Block:4( | |
| PassStmt:4()))) | |
| [case testArgConstructorMultipleValuesForType] | |
| from typing import Callable | |
| from mypy_extensions import Arg | |
| def f(x: Callable[[Arg(int, type=str)], bool]) -> None: | |
| pass | |
| [out] | |
| 3:19: error: "Arg" gets multiple values for keyword argument "type" | |
| MypyFile:1( | |
| ImportFrom:1(typing, [Callable]) | |
| ImportFrom:2(mypy_extensions, [Arg]) | |
| FuncDef:3( | |
| f | |
| Args( | |
| Var(x)) | |
| def (x: Callable?[<TypeList Arg(str?)>, bool?]) -> None? | |
| Block:4( | |
| PassStmt:4()))) | |
| [case testArgConstructorUnexpectedArg] | |
| from typing import Callable | |
| from mypy_extensions import Arg | |
| def f(x: Callable[[Arg(int, foo='bar')], bool]) -> None: | |
| pass | |
| [out] | |
| 3:19: error: Unexpected argument "foo" for argument constructor | |
| MypyFile:1( | |
| ImportFrom:1(typing, [Callable]) | |
| ImportFrom:2(mypy_extensions, [Arg]) | |
| FuncDef:3( | |
| f | |
| Args( | |
| Var(x)) | |
| def (x: Callable?[<TypeList Arg(int?)>, bool?]) -> None? | |
| Block:4( | |
| PassStmt:4()))) | |
| [case testArgConstructorMultipleErrors] | |
| from typing import Callable | |
| from mypy_extensions import Arg | |
| def f(x: Callable[[Arg(int, 'x', 'extra', foo='bar', name='y')], bool]) -> None: | |
| pass | |
| [out] | |
| 3:19: error: Too many arguments for argument constructor | |
| 3:19: error: Unexpected argument "foo" for argument constructor | |
| 3:19: error: "Arg" gets multiple values for keyword argument "name" | |
| MypyFile:1( | |
| ImportFrom:1(typing, [Callable]) | |
| ImportFrom:2(mypy_extensions, [Arg]) | |
| FuncDef:3( | |
| f | |
| Args( | |
| Var(x)) | |
| def (x: Callable?[<TypeList Arg(int?, y)>, bool?]) -> None? | |
| Block:4( | |
| PassStmt:4()))) | |
| [case testArgConstructorValidSyntax] | |
| from typing import Callable | |
| from mypy_extensions import Arg, DefaultArg, VarArg, KwArg | |
| def f(x: Callable[[Arg(int, 'x'), DefaultArg(str, 'y'), VarArg(bool), KwArg(float)], None]) -> None: | |
| pass | |
| [out] | |
| MypyFile:1( | |
| ImportFrom:1(typing, [Callable]) | |
| ImportFrom:2(mypy_extensions, [Arg, DefaultArg, VarArg, KwArg]) | |
| FuncDef:3( | |
| f | |
| Args( | |
| Var(x)) | |
| def (x: Callable?[<TypeList Arg(int?, x), DefaultArg(str?, y), VarArg(bool?), KwArg(float?)>, None?]) -> None? | |
| Block:4( | |
| PassStmt:4()))) | |
| [case testInvalidTypeFloatLiteral] | |
| x: 3.14 | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(x) | |
| TempNode:1( | |
| Any) | |
| None)) | |
| [case testInvalidTypeComplexLiteral] | |
| y: 1j | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(y) | |
| TempNode:1( | |
| Any) | |
| None)) | |
| [case testInvalidTypeBinaryOperatorAdd] | |
| z: int + str | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(z) | |
| TempNode:1( | |
| Any) | |
| None)) | |
| [case testInvalidTypeBinaryOperatorMul] | |
| a: int * str | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(a) | |
| TempNode:1( | |
| Any) | |
| None)) | |
| [case testInvalidTypeUnaryOperatorNot] | |
| b: not int | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(b) | |
| TempNode:1( | |
| Any) | |
| None)) | |
| [case testInvalidTypeUnaryOperatorInvert] | |
| c: ~int | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(c) | |
| TempNode:1( | |
| Any) | |
| None)) | |
| [case testInvalidTypeSetExpression] | |
| f: {1, 2, 3} | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(f) | |
| TempNode:1( | |
| Any) | |
| None)) | |
| [case testInvalidTypeListComprehension] | |
| g: [x for x in range(10)] | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(g) | |
| TempNode:1( | |
| Any) | |
| None)) | |
| [case testInvalidTypeLambda] | |
| h: lambda x: x | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(h) | |
| TempNode:1( | |
| Any) | |
| None)) | |
| [case testInvalidTypeIfExpression] | |
| i: int if True else str | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(i) | |
| TempNode:1( | |
| Any) | |
| None)) | |
| [case testInvalidTypeComparisonExpression] | |
| j: int < str | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(j) | |
| TempNode:1( | |
| Any) | |
| None)) | |
| [case testInvalidTypePositiveUnaryOp] | |
| k: +5 | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(k) | |
| TempNode:1( | |
| Any) | |
| 5)) | |
| [case testConditionalOverload1] | |
| @overload | |
| def foo(x: int): ... | |
| if sys.version_info[0] > 2: | |
| @overload | |
| def foo(x: str): ... | |
| def foo(x): pass | |
| [out] | |
| MypyFile:1( | |
| IfStmt:3( | |
| If( | |
| ComparisonExpr:3( | |
| > | |
| IndexExpr:3( | |
| MemberExpr:3( | |
| NameExpr(sys) | |
| version_info) | |
| IntExpr(0)) | |
| IntExpr(2))) | |
| Then() | |
| Else()) | |
| OverloadedFuncDef:1( | |
| Decorator:1( | |
| Var(foo) | |
| NameExpr(overload) | |
| FuncDef:2( | |
| foo | |
| Args( | |
| Var(x)) | |
| def (x: int?) -> Any | |
| Block:2( | |
| ExpressionStmt:2( | |
| Ellipsis)))) | |
| Decorator:4( | |
| Var(foo) | |
| NameExpr(overload) | |
| FuncDef:5( | |
| foo | |
| Args( | |
| Var(x)) | |
| def (x: str?) -> Any | |
| Block:5( | |
| ExpressionStmt:5( | |
| Ellipsis)))) | |
| FuncDef:6( | |
| foo | |
| Args( | |
| Var(x)) | |
| Block:6( | |
| PassStmt:6())))) | |
| [case testConditionalOverload2] | |
| @overload | |
| def foo(x: int): ... | |
| if sys.platform == "foo": | |
| @overload | |
| def foo(x: str): ... | |
| def foo(x): pass | |
| [out] | |
| MypyFile:1( | |
| IfStmt:3( | |
| If( | |
| ComparisonExpr:3( | |
| == | |
| MemberExpr:3( | |
| NameExpr(sys) | |
| platform) | |
| StrExpr(foo))) | |
| Then()) | |
| OverloadedFuncDef:1( | |
| Decorator:1( | |
| Var(foo) | |
| NameExpr(overload) | |
| FuncDef:2( | |
| foo | |
| Args( | |
| Var(x)) | |
| def (x: int?) -> Any | |
| Block:2( | |
| ExpressionStmt:2( | |
| Ellipsis)))) | |
| FuncDef:6( | |
| foo | |
| Args( | |
| Var(x)) | |
| Block:6( | |
| PassStmt:6())))) | |
| [case testConditionalOverload3] | |
| if sys.version_info[0] > 2: | |
| @overload | |
| def foo(x: str): ... | |
| @overload | |
| def foo(x: int): ... | |
| def foo(x): pass | |
| [out] | |
| MypyFile:1( | |
| IfStmt:1( | |
| If( | |
| ComparisonExpr:1( | |
| > | |
| IndexExpr:1( | |
| MemberExpr:1( | |
| NameExpr(sys) | |
| version_info) | |
| IntExpr(0)) | |
| IntExpr(2))) | |
| Then() | |
| Else()) | |
| OverloadedFuncDef:2( | |
| Decorator:2( | |
| Var(foo) | |
| NameExpr(overload) | |
| FuncDef:3( | |
| foo | |
| Args( | |
| Var(x)) | |
| def (x: str?) -> Any | |
| Block:3( | |
| ExpressionStmt:3( | |
| Ellipsis)))) | |
| Decorator:4( | |
| Var(foo) | |
| NameExpr(overload) | |
| FuncDef:5( | |
| foo | |
| Args( | |
| Var(x)) | |
| def (x: int?) -> Any | |
| Block:5( | |
| ExpressionStmt:5( | |
| Ellipsis)))) | |
| FuncDef:6( | |
| foo | |
| Args( | |
| Var(x)) | |
| Block:6( | |
| PassStmt:6())))) | |
| [case testMatchStmt] | |
| match x: | |
| case foo(y): | |
| pass | |
| case _: | |
| pass | |
| [out] | |
| MypyFile:1( | |
| MatchStmt:1( | |
| NameExpr(x) | |
| Pattern( | |
| ClassPattern:2( | |
| NameExpr(foo) | |
| Positionals( | |
| AsPattern:2( | |
| NameExpr(y))))) | |
| Body( | |
| PassStmt:3()) | |
| Pattern( | |
| AsPattern:4()) | |
| Body( | |
| PassStmt:5()))) | |
| [case testMatchLiteralPatterns] | |
| match x: | |
| case 1: | |
| pass | |
| case "hello": | |
| pass | |
| case True: | |
| pass | |
| case None: | |
| pass | |
| [out] | |
| MypyFile:1( | |
| MatchStmt:1( | |
| NameExpr(x) | |
| Pattern( | |
| ValuePattern:2( | |
| IntExpr(1))) | |
| Body( | |
| PassStmt:3()) | |
| Pattern( | |
| ValuePattern:4( | |
| StrExpr(hello))) | |
| Body( | |
| PassStmt:5()) | |
| Pattern( | |
| SingletonPattern:6( | |
| True)) | |
| Body( | |
| PassStmt:7()) | |
| Pattern( | |
| SingletonPattern:8()) | |
| Body( | |
| PassStmt:9()))) | |
| [case testMatchOrPattern] | |
| match x: | |
| case 1 | 2 | 3: | |
| pass | |
| [out] | |
| MypyFile:1( | |
| MatchStmt:1( | |
| NameExpr(x) | |
| Pattern( | |
| OrPattern:2( | |
| ValuePattern:2( | |
| IntExpr(1)) | |
| ValuePattern:2( | |
| IntExpr(2)) | |
| ValuePattern:2( | |
| IntExpr(3)))) | |
| Body( | |
| PassStmt:3()))) | |
| [case testMatchSequencePattern] | |
| match x: | |
| case [a, *rest, b]: | |
| pass | |
| [out] | |
| MypyFile:1( | |
| MatchStmt:1( | |
| NameExpr(x) | |
| Pattern( | |
| SequencePattern:2( | |
| AsPattern:2( | |
| NameExpr(a)) | |
| StarredPattern:2( | |
| NameExpr(rest)) | |
| AsPattern:2( | |
| NameExpr(b)))) | |
| Body( | |
| PassStmt:3()))) | |
| [case testMatchMappingPattern] | |
| match x: | |
| case {"key": value, "x": y}: | |
| pass | |
| [out] | |
| MypyFile:1( | |
| MatchStmt:1( | |
| NameExpr(x) | |
| Pattern( | |
| MappingPattern:2( | |
| Key( | |
| StrExpr(key)) | |
| Value( | |
| AsPattern:2( | |
| NameExpr(value))) | |
| Key( | |
| StrExpr(x)) | |
| Value( | |
| AsPattern:2( | |
| NameExpr(y))))) | |
| Body( | |
| PassStmt:3()))) | |
| [case testMatchGuard] | |
| match x: | |
| case y if y > 0: | |
| pass | |
| [out] | |
| MypyFile:1( | |
| MatchStmt:1( | |
| NameExpr(x) | |
| Pattern( | |
| AsPattern:2( | |
| NameExpr(y))) | |
| Guard( | |
| ComparisonExpr:2( | |
| > | |
| NameExpr(y) | |
| IntExpr(0))) | |
| Body( | |
| PassStmt:3()))) | |
| [case testTypeCommentLastLine] | |
| d = [ | |
| # Placeholder for items | |
| ] # type: list[int] | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(d) | |
| ListExpr:1() | |
| list?[int?])) | |
| [case testDebugFString] | |
| f"test {x=}" | |
| [out] | |
| MypyFile:1( | |
| ExpressionStmt:1( | |
| CallExpr:1( | |
| MemberExpr:1( | |
| StrExpr() | |
| join) | |
| Args( | |
| ListExpr:1( | |
| StrExpr(test x=) | |
| CallExpr:1( | |
| MemberExpr:1( | |
| StrExpr({!r:{}}) | |
| format) | |
| Args( | |
| NameExpr(x) | |
| StrExpr()))))))) | |
| [case testNoneInStringType] | |
| x: "None" | |
| [out] | |
| MypyFile:1( | |
| AssignmentStmt:1( | |
| NameExpr(x) | |
| TempNode:1( | |
| Any) | |
| None?)) |