| 1 |
[case testHello] |
| 2 |
print("hello") |
| 3 |
[out] |
| 4 |
MypyFile:1( |
| 5 |
ExpressionStmt:1( |
| 6 |
CallExpr:1( |
| 7 |
NameExpr(print) |
| 8 |
Args( |
| 9 |
StrExpr(hello))))) |
| 10 |
|
| 11 |
[case testMemberExpr] |
| 12 |
foo_bar.xyz2 |
| 13 |
[out] |
| 14 |
MypyFile:1( |
| 15 |
ExpressionStmt:1( |
| 16 |
MemberExpr:1( |
| 17 |
NameExpr(foo_bar) |
| 18 |
xyz2))) |
| 19 |
|
| 20 |
[case testTupleExpr] |
| 21 |
("a", "b") |
| 22 |
[out] |
| 23 |
MypyFile:1( |
| 24 |
ExpressionStmt:1( |
| 25 |
TupleExpr:1( |
| 26 |
StrExpr(a) |
| 27 |
StrExpr(b)))) |
| 28 |
|
| 29 |
[case testOpExpr] |
| 30 |
("x" + "y") * "z" |
| 31 |
[out] |
| 32 |
MypyFile:1( |
| 33 |
ExpressionStmt:1( |
| 34 |
OpExpr:1( |
| 35 |
* |
| 36 |
OpExpr:1( |
| 37 |
+ |
| 38 |
StrExpr(x) |
| 39 |
StrExpr(y)) |
| 40 |
StrExpr(z)))) |
| 41 |
|
| 42 |
[case testIntExpr] |
| 43 |
(0, 1, 2, 203, 5345, 50123, 1234567890, 9982374892739487239847897928374897298374, 0x1950A86A20F9469CFC6C) |
| 44 |
[out] |
| 45 |
MypyFile:1( |
| 46 |
ExpressionStmt:1( |
| 47 |
TupleExpr:1( |
| 48 |
IntExpr(0) |
| 49 |
IntExpr(1) |
| 50 |
IntExpr(2) |
| 51 |
IntExpr(203) |
| 52 |
IntExpr(5345) |
| 53 |
IntExpr(50123) |
| 54 |
IntExpr(1234567890) |
| 55 |
IntExpr(9982374892739487239847897928374897298374) |
| 56 |
IntExpr(119547037146038801333356)))) |
| 57 |
|
| 58 |
[case testAssignmentStmt] |
| 59 |
x = 1 |
| 60 |
a, b = c = 6 |
| 61 |
[out] |
| 62 |
MypyFile:1( |
| 63 |
AssignmentStmt:1( |
| 64 |
NameExpr(x) |
| 65 |
IntExpr(1)) |
| 66 |
AssignmentStmt:2( |
| 67 |
Lvalues( |
| 68 |
TupleExpr:2( |
| 69 |
NameExpr(a) |
| 70 |
NameExpr(b)) |
| 71 |
NameExpr(c)) |
| 72 |
IntExpr(6))) |
| 73 |
|
| 74 |
[case testOperatorAssignment] |
| 75 |
x += 1 |
| 76 |
y -= 2 |
| 77 |
z *= 3 |
| 78 |
[out] |
| 79 |
MypyFile:1( |
| 80 |
OperatorAssignmentStmt:1( |
| 81 |
+ |
| 82 |
NameExpr(x) |
| 83 |
IntExpr(1)) |
| 84 |
OperatorAssignmentStmt:2( |
| 85 |
- |
| 86 |
NameExpr(y) |
| 87 |
IntExpr(2)) |
| 88 |
OperatorAssignmentStmt:3( |
| 89 |
* |
| 90 |
NameExpr(z) |
| 91 |
IntExpr(3))) |
| 92 |
|
| 93 |
[case testIfStmt] |
| 94 |
if x: |
| 95 |
y |
| 96 |
if a: |
| 97 |
b |
| 98 |
else: |
| 99 |
c |
| 100 |
[out] |
| 101 |
MypyFile:1( |
| 102 |
IfStmt:1( |
| 103 |
If( |
| 104 |
NameExpr(x)) |
| 105 |
Then( |
| 106 |
ExpressionStmt:2( |
| 107 |
NameExpr(y)))) |
| 108 |
IfStmt:3( |
| 109 |
If( |
| 110 |
NameExpr(a)) |
| 111 |
Then( |
| 112 |
ExpressionStmt:4( |
| 113 |
NameExpr(b))) |
| 114 |
Else( |
| 115 |
ExpressionStmt:6( |
| 116 |
NameExpr(c))))) |
| 117 |
|
| 118 |
[case testIfStmtElif] |
| 119 |
if a: |
| 120 |
b |
| 121 |
elif c: |
| 122 |
d |
| 123 |
else: |
| 124 |
e |
| 125 |
[out] |
| 126 |
MypyFile:1( |
| 127 |
IfStmt:1( |
| 128 |
If( |
| 129 |
NameExpr(a)) |
| 130 |
Then( |
| 131 |
ExpressionStmt:2( |
| 132 |
NameExpr(b))) |
| 133 |
Else( |
| 134 |
IfStmt:3( |
| 135 |
If( |
| 136 |
NameExpr(c)) |
| 137 |
Then( |
| 138 |
ExpressionStmt:4( |
| 139 |
NameExpr(d))) |
| 140 |
Else( |
| 141 |
ExpressionStmt:6( |
| 142 |
NameExpr(e))))))) |
| 143 |
|
| 144 |
[case testIfStmtMultipleElif] |
| 145 |
if 1: |
| 146 |
2 |
| 147 |
elif 3: |
| 148 |
4 |
| 149 |
elif 5: |
| 150 |
6 |
| 151 |
else: |
| 152 |
7 |
| 153 |
[out] |
| 154 |
MypyFile:1( |
| 155 |
IfStmt:1( |
| 156 |
If( |
| 157 |
IntExpr(1)) |
| 158 |
Then( |
| 159 |
ExpressionStmt:2( |
| 160 |
IntExpr(2))) |
| 161 |
Else( |
| 162 |
IfStmt:3( |
| 163 |
If( |
| 164 |
IntExpr(3)) |
| 165 |
Then( |
| 166 |
ExpressionStmt:4( |
| 167 |
IntExpr(4))) |
| 168 |
Else( |
| 169 |
IfStmt:5( |
| 170 |
If( |
| 171 |
IntExpr(5)) |
| 172 |
Then( |
| 173 |
ExpressionStmt:6( |
| 174 |
IntExpr(6))) |
| 175 |
Else( |
| 176 |
ExpressionStmt:8( |
| 177 |
IntExpr(7))))))))) |
| 178 |
|
| 179 |
[case testIfStmtElifNoElse] |
| 180 |
if a: |
| 181 |
b |
| 182 |
elif c: |
| 183 |
d |
| 184 |
[out] |
| 185 |
MypyFile:1( |
| 186 |
IfStmt:1( |
| 187 |
If( |
| 188 |
NameExpr(a)) |
| 189 |
Then( |
| 190 |
ExpressionStmt:2( |
| 191 |
NameExpr(b))) |
| 192 |
Else( |
| 193 |
IfStmt:3( |
| 194 |
If( |
| 195 |
NameExpr(c)) |
| 196 |
Then( |
| 197 |
ExpressionStmt:4( |
| 198 |
NameExpr(d))))))) |
| 199 |
|
| 200 |
[case testWhileStmt] |
| 201 |
while a: |
| 202 |
b |
| 203 |
while c: |
| 204 |
d |
| 205 |
else: |
| 206 |
e |
| 207 |
[out] |
| 208 |
MypyFile:1( |
| 209 |
WhileStmt:1( |
| 210 |
NameExpr(a) |
| 211 |
Block:2( |
| 212 |
ExpressionStmt:2( |
| 213 |
NameExpr(b)))) |
| 214 |
WhileStmt:3( |
| 215 |
NameExpr(c) |
| 216 |
Block:4( |
| 217 |
ExpressionStmt:4( |
| 218 |
NameExpr(d))) |
| 219 |
Else( |
| 220 |
ExpressionStmt:6( |
| 221 |
NameExpr(e))))) |
| 222 |
|
| 223 |
[case testIndexExpr] |
| 224 |
a[b] |
| 225 |
[out] |
| 226 |
MypyFile:1( |
| 227 |
ExpressionStmt:1( |
| 228 |
IndexExpr:1( |
| 229 |
NameExpr(a) |
| 230 |
NameExpr(b)))) |
| 231 |
|
| 232 |
[case testListAndSetExpr] |
| 233 |
a = [] |
| 234 |
b = [1, 2] |
| 235 |
c = {3} |
| 236 |
[out] |
| 237 |
MypyFile:1( |
| 238 |
AssignmentStmt:1( |
| 239 |
NameExpr(a) |
| 240 |
ListExpr:1()) |
| 241 |
AssignmentStmt:2( |
| 242 |
NameExpr(b) |
| 243 |
ListExpr:2( |
| 244 |
IntExpr(1) |
| 245 |
IntExpr(2))) |
| 246 |
AssignmentStmt:3( |
| 247 |
NameExpr(c) |
| 248 |
SetExpr:3( |
| 249 |
IntExpr(3)))) |
| 250 |
|
| 251 |
[case testBoolOpAnd] |
| 252 |
a and b |
| 253 |
a and b and c |
| 254 |
[out] |
| 255 |
MypyFile:1( |
| 256 |
ExpressionStmt:1( |
| 257 |
OpExpr:1( |
| 258 |
and |
| 259 |
NameExpr(a) |
| 260 |
NameExpr(b))) |
| 261 |
ExpressionStmt:2( |
| 262 |
OpExpr:2( |
| 263 |
and |
| 264 |
NameExpr(a) |
| 265 |
OpExpr:2( |
| 266 |
and |
| 267 |
NameExpr(b) |
| 268 |
NameExpr(c))))) |
| 269 |
|
| 270 |
[case testBoolOpOr] |
| 271 |
x or y |
| 272 |
1 or 2 or 3 |
| 273 |
[out] |
| 274 |
MypyFile:1( |
| 275 |
ExpressionStmt:1( |
| 276 |
OpExpr:1( |
| 277 |
or |
| 278 |
NameExpr(x) |
| 279 |
NameExpr(y))) |
| 280 |
ExpressionStmt:2( |
| 281 |
OpExpr:2( |
| 282 |
or |
| 283 |
IntExpr(1) |
| 284 |
OpExpr:2( |
| 285 |
or |
| 286 |
IntExpr(2) |
| 287 |
IntExpr(3))))) |
| 288 |
|
| 289 |
[case testComparisonSimple] |
| 290 |
a < b |
| 291 |
x == y |
| 292 |
[out] |
| 293 |
MypyFile:1( |
| 294 |
ExpressionStmt:1( |
| 295 |
ComparisonExpr:1( |
| 296 |
< |
| 297 |
NameExpr(a) |
| 298 |
NameExpr(b))) |
| 299 |
ExpressionStmt:2( |
| 300 |
ComparisonExpr:2( |
| 301 |
== |
| 302 |
NameExpr(x) |
| 303 |
NameExpr(y)))) |
| 304 |
|
| 305 |
[case testComparisonChained] |
| 306 |
a < b < c |
| 307 |
x == y != z |
| 308 |
[out] |
| 309 |
MypyFile:1( |
| 310 |
ExpressionStmt:1( |
| 311 |
ComparisonExpr:1( |
| 312 |
< |
| 313 |
< |
| 314 |
NameExpr(a) |
| 315 |
NameExpr(b) |
| 316 |
NameExpr(c))) |
| 317 |
ExpressionStmt:2( |
| 318 |
ComparisonExpr:2( |
| 319 |
== |
| 320 |
!= |
| 321 |
NameExpr(x) |
| 322 |
NameExpr(y) |
| 323 |
NameExpr(z)))) |
| 324 |
|
| 325 |
[case testComparisonIsNotIn] |
| 326 |
a is b |
| 327 |
x is not y |
| 328 |
z in w |
| 329 |
q not in r |
| 330 |
[out] |
| 331 |
MypyFile:1( |
| 332 |
ExpressionStmt:1( |
| 333 |
ComparisonExpr:1( |
| 334 |
is |
| 335 |
NameExpr(a) |
| 336 |
NameExpr(b))) |
| 337 |
ExpressionStmt:2( |
| 338 |
ComparisonExpr:2( |
| 339 |
is not |
| 340 |
NameExpr(x) |
| 341 |
NameExpr(y))) |
| 342 |
ExpressionStmt:3( |
| 343 |
ComparisonExpr:3( |
| 344 |
in |
| 345 |
NameExpr(z) |
| 346 |
NameExpr(w))) |
| 347 |
ExpressionStmt:4( |
| 348 |
ComparisonExpr:4( |
| 349 |
not in |
| 350 |
NameExpr(q) |
| 351 |
NameExpr(r)))) |
| 352 |
|
| 353 |
[case testLiterals] |
| 354 |
(None, True, False, ...) |
| 355 |
[out] |
| 356 |
MypyFile:1( |
| 357 |
ExpressionStmt:1( |
| 358 |
TupleExpr:1( |
| 359 |
NameExpr(None) |
| 360 |
NameExpr(True) |
| 361 |
NameExpr(False) |
| 362 |
Ellipsis))) |
| 363 |
|
| 364 |
[case testSimpleFunction] |
| 365 |
def foo(): |
| 366 |
x = 1 |
| 367 |
[out] |
| 368 |
MypyFile:1( |
| 369 |
FuncDef:1( |
| 370 |
foo |
| 371 |
Block:2( |
| 372 |
AssignmentStmt:2( |
| 373 |
NameExpr(x) |
| 374 |
IntExpr(1))))) |
| 375 |
|
| 376 |
[case testFunctionWithArgs] |
| 377 |
def add(x, y): |
| 378 |
return x + y |
| 379 |
[out] |
| 380 |
MypyFile:1( |
| 381 |
FuncDef:1( |
| 382 |
add |
| 383 |
Args( |
| 384 |
Var(x) |
| 385 |
Var(y)) |
| 386 |
Block:2( |
| 387 |
ReturnStmt:2( |
| 388 |
OpExpr:2( |
| 389 |
+ |
| 390 |
NameExpr(x) |
| 391 |
NameExpr(y)))))) |
| 392 |
|
| 393 |
[case testFunctionWithVarArgs] |
| 394 |
def foo(*args): |
| 395 |
pass |
| 396 |
[out] |
| 397 |
MypyFile:1( |
| 398 |
FuncDef:1( |
| 399 |
foo |
| 400 |
VarArg( |
| 401 |
Var(args)) |
| 402 |
Block:2( |
| 403 |
PassStmt:2()))) |
| 404 |
|
| 405 |
[case testFunctionWithKwargs] |
| 406 |
def bar(**kwargs): |
| 407 |
pass |
| 408 |
[out] |
| 409 |
MypyFile:1( |
| 410 |
FuncDef:1( |
| 411 |
bar |
| 412 |
DictVarArg( |
| 413 |
Var(kwargs)) |
| 414 |
Block:2( |
| 415 |
PassStmt:2()))) |
| 416 |
|
| 417 |
[case testFunctionWithKwOnly] |
| 418 |
def baz(x, *, y): |
| 419 |
pass |
| 420 |
[out] |
| 421 |
MypyFile:1( |
| 422 |
FuncDef:1( |
| 423 |
baz |
| 424 |
MaxPos(1) |
| 425 |
Args( |
| 426 |
Var(x) |
| 427 |
Var(y)) |
| 428 |
Block:2( |
| 429 |
PassStmt:2()))) |
| 430 |
|
| 431 |
[case testFunctionWithAllArgKinds] |
| 432 |
def complex_fn(a, b, *args, c, **kwargs): |
| 433 |
pass |
| 434 |
[out] |
| 435 |
MypyFile:1( |
| 436 |
FuncDef:1( |
| 437 |
complex_fn |
| 438 |
MaxPos(2) |
| 439 |
Args( |
| 440 |
Var(a) |
| 441 |
Var(b) |
| 442 |
Var(c)) |
| 443 |
VarArg( |
| 444 |
Var(args)) |
| 445 |
DictVarArg( |
| 446 |
Var(kwargs)) |
| 447 |
Block:2( |
| 448 |
PassStmt:2()))) |
| 449 |
|
| 450 |
[case testAsyncFunction] |
| 451 |
async def async_foo(): |
| 452 |
pass |
| 453 |
[out] |
| 454 |
MypyFile:1( |
| 455 |
FuncDef:1( |
| 456 |
async_foo |
| 457 |
Async |
| 458 |
Block:2( |
| 459 |
PassStmt:2()))) |
| 460 |
|
| 461 |
[case testFunctionWithDefaultArg] |
| 462 |
def greet(name="World"): |
| 463 |
pass |
| 464 |
[out] |
| 465 |
MypyFile:1( |
| 466 |
FuncDef:1( |
| 467 |
greet |
| 468 |
Args( |
| 469 |
default( |
| 470 |
Var(name) |
| 471 |
StrExpr(World))) |
| 472 |
Block:2( |
| 473 |
PassStmt:2()))) |
| 474 |
|
| 475 |
[case testFunctionWithMultipleDefaults] |
| 476 |
def add(x=1, y=2): |
| 477 |
return x |
| 478 |
[out] |
| 479 |
MypyFile:1( |
| 480 |
FuncDef:1( |
| 481 |
add |
| 482 |
Args( |
| 483 |
default( |
| 484 |
Var(x) |
| 485 |
IntExpr(1)) |
| 486 |
default( |
| 487 |
Var(y) |
| 488 |
IntExpr(2))) |
| 489 |
Block:2( |
| 490 |
ReturnStmt:2( |
| 491 |
NameExpr(x))))) |
| 492 |
|
| 493 |
[case testFunctionMixedDefaultsAndRegular] |
| 494 |
def func(a, b=5, c=10): |
| 495 |
pass |
| 496 |
[out] |
| 497 |
MypyFile:1( |
| 498 |
FuncDef:1( |
| 499 |
func |
| 500 |
Args( |
| 501 |
Var(a) |
| 502 |
default( |
| 503 |
Var(b) |
| 504 |
IntExpr(5)) |
| 505 |
default( |
| 506 |
Var(c) |
| 507 |
IntExpr(10))) |
| 508 |
Block:2( |
| 509 |
PassStmt:2()))) |
| 510 |
|
| 511 |
[case testFunctionWithKwOnlyDefault] |
| 512 |
def func(*, x=42): |
| 513 |
pass |
| 514 |
[out] |
| 515 |
MypyFile:1( |
| 516 |
FuncDef:1( |
| 517 |
func |
| 518 |
MaxPos(0) |
| 519 |
Args( |
| 520 |
default( |
| 521 |
Var(x) |
| 522 |
IntExpr(42))) |
| 523 |
Block:2( |
| 524 |
PassStmt:2()))) |
| 525 |
|
| 526 |
[case testCallWithKeywordArgs] |
| 527 |
foo(x=1, y=2) |
| 528 |
[out] |
| 529 |
MypyFile:1( |
| 530 |
ExpressionStmt:1( |
| 531 |
CallExpr:1( |
| 532 |
NameExpr(foo) |
| 533 |
Args() |
| 534 |
KwArgs( |
| 535 |
x |
| 536 |
IntExpr(1)) |
| 537 |
KwArgs( |
| 538 |
y |
| 539 |
IntExpr(2))))) |
| 540 |
|
| 541 |
[case testCallMixedPositionalAndKeyword] |
| 542 |
bar(1, 2, x=3, y=4) |
| 543 |
[out] |
| 544 |
MypyFile:1( |
| 545 |
ExpressionStmt:1( |
| 546 |
CallExpr:1( |
| 547 |
NameExpr(bar) |
| 548 |
Args( |
| 549 |
IntExpr(1) |
| 550 |
IntExpr(2)) |
| 551 |
KwArgs( |
| 552 |
x |
| 553 |
IntExpr(3)) |
| 554 |
KwArgs( |
| 555 |
y |
| 556 |
IntExpr(4))))) |
| 557 |
|
| 558 |
[case testCallWithStarArgs] |
| 559 |
f(1, *x, 2) |
| 560 |
[out] |
| 561 |
MypyFile:1( |
| 562 |
ExpressionStmt:1( |
| 563 |
CallExpr:1( |
| 564 |
NameExpr(f) |
| 565 |
Args( |
| 566 |
IntExpr(1) |
| 567 |
NameExpr(x) |
| 568 |
IntExpr(2)) |
| 569 |
VarArg))) |
| 570 |
|
| 571 |
[case testCallWithDictStarArgs] |
| 572 |
f(**x) |
| 573 |
f(1, **y) |
| 574 |
[out] |
| 575 |
MypyFile:1( |
| 576 |
ExpressionStmt:1( |
| 577 |
CallExpr:1( |
| 578 |
NameExpr(f) |
| 579 |
Args() |
| 580 |
DictVarArg( |
| 581 |
NameExpr(x)))) |
| 582 |
ExpressionStmt:2( |
| 583 |
CallExpr:2( |
| 584 |
NameExpr(f) |
| 585 |
Args( |
| 586 |
IntExpr(1)) |
| 587 |
DictVarArg( |
| 588 |
NameExpr(y))))) |
| 589 |
|
| 590 |
[case testCallWithAllArgTypes] |
| 591 |
f(1, *x, a=2, **y) |
| 592 |
[out] |
| 593 |
MypyFile:1( |
| 594 |
ExpressionStmt:1( |
| 595 |
CallExpr:1( |
| 596 |
NameExpr(f) |
| 597 |
Args( |
| 598 |
IntExpr(1) |
| 599 |
NameExpr(x)) |
| 600 |
VarArg |
| 601 |
KwArgs( |
| 602 |
a |
| 603 |
IntExpr(2)) |
| 604 |
DictVarArg( |
| 605 |
NameExpr(y))))) |
| 606 |
|
| 607 |
[case testSimpleClass] |
| 608 |
class A: |
| 609 |
pass |
| 610 |
[out] |
| 611 |
MypyFile:1( |
| 612 |
ClassDef:1( |
| 613 |
A |
| 614 |
PassStmt:2())) |
| 615 |
|
| 616 |
[case testClassWithMethod] |
| 617 |
class Foo: |
| 618 |
def bar(self): |
| 619 |
return 1 |
| 620 |
[out] |
| 621 |
MypyFile:1( |
| 622 |
ClassDef:1( |
| 623 |
Foo |
| 624 |
FuncDef:2( |
| 625 |
bar |
| 626 |
Args( |
| 627 |
Var(self)) |
| 628 |
Block:3( |
| 629 |
ReturnStmt:3( |
| 630 |
IntExpr(1)))))) |
| 631 |
|
| 632 |
[case testClassWithSingleBase] |
| 633 |
class A(B): |
| 634 |
pass |
| 635 |
[out] |
| 636 |
MypyFile:1( |
| 637 |
ClassDef:1( |
| 638 |
A |
| 639 |
BaseTypeExpr( |
| 640 |
NameExpr(B)) |
| 641 |
PassStmt:2())) |
| 642 |
|
| 643 |
[case testClassWithMultipleBases] |
| 644 |
class Child(Base1, Base2): |
| 645 |
x = 1 |
| 646 |
[out] |
| 647 |
MypyFile:1( |
| 648 |
ClassDef:1( |
| 649 |
Child |
| 650 |
BaseTypeExpr( |
| 651 |
NameExpr(Base1) |
| 652 |
NameExpr(Base2)) |
| 653 |
AssignmentStmt:2( |
| 654 |
NameExpr(x) |
| 655 |
IntExpr(1)))) |
| 656 |
|
| 657 |
[case testFloatLiteral] |
| 658 |
x = 3.14 |
| 659 |
[out] |
| 660 |
MypyFile:1( |
| 661 |
AssignmentStmt:1( |
| 662 |
NameExpr(x) |
| 663 |
FloatExpr(3.14))) |
| 664 |
|
| 665 |
[case testUnaryExpressions] |
| 666 |
-x |
| 667 |
+y |
| 668 |
~z |
| 669 |
not w |
| 670 |
[out] |
| 671 |
MypyFile:1( |
| 672 |
ExpressionStmt:1( |
| 673 |
UnaryExpr:1( |
| 674 |
- |
| 675 |
NameExpr(x))) |
| 676 |
ExpressionStmt:2( |
| 677 |
UnaryExpr:2( |
| 678 |
+ |
| 679 |
NameExpr(y))) |
| 680 |
ExpressionStmt:3( |
| 681 |
UnaryExpr:3( |
| 682 |
~ |
| 683 |
NameExpr(z))) |
| 684 |
ExpressionStmt:4( |
| 685 |
UnaryExpr:4( |
| 686 |
not |
| 687 |
NameExpr(w)))) |
| 688 |
|
| 689 |
[case testDictionaryExpression] |
| 690 |
{} |
| 691 |
{1:x} |
| 692 |
[out] |
| 693 |
MypyFile:1( |
| 694 |
ExpressionStmt:1( |
| 695 |
DictExpr:1()) |
| 696 |
ExpressionStmt:2( |
| 697 |
DictExpr:2( |
| 698 |
IntExpr(1) |
| 699 |
NameExpr(x)))) |
| 700 |
|
| 701 |
[case testComplexLiteral] |
| 702 |
1j |
| 703 |
2.5j |
| 704 |
[out] |
| 705 |
MypyFile:1( |
| 706 |
ExpressionStmt:1( |
| 707 |
ComplexExpr(1j)) |
| 708 |
ExpressionStmt:2( |
| 709 |
ComplexExpr(2.5j))) |
| 710 |
|
| 711 |
[case testSlices] |
| 712 |
x[1:2] |
| 713 |
x[:1] |
| 714 |
x[1:] |
| 715 |
x[:] |
| 716 |
[out] |
| 717 |
MypyFile:1( |
| 718 |
ExpressionStmt:1( |
| 719 |
IndexExpr:1( |
| 720 |
NameExpr(x) |
| 721 |
SliceExpr:1( |
| 722 |
IntExpr(1) |
| 723 |
IntExpr(2)))) |
| 724 |
ExpressionStmt:2( |
| 725 |
IndexExpr:2( |
| 726 |
NameExpr(x) |
| 727 |
SliceExpr:2( |
| 728 |
<empty> |
| 729 |
IntExpr(1)))) |
| 730 |
ExpressionStmt:3( |
| 731 |
IndexExpr:3( |
| 732 |
NameExpr(x) |
| 733 |
SliceExpr:3( |
| 734 |
IntExpr(1) |
| 735 |
<empty>))) |
| 736 |
ExpressionStmt:4( |
| 737 |
IndexExpr:4( |
| 738 |
NameExpr(x) |
| 739 |
SliceExpr:4( |
| 740 |
<empty> |
| 741 |
<empty>)))) |
| 742 |
|
| 743 |
[case testSliceWithStride] |
| 744 |
x[1:2:3] |
| 745 |
x[1::2] |
| 746 |
x[:1:2] |
| 747 |
x[::2] |
| 748 |
[out] |
| 749 |
MypyFile:1( |
| 750 |
ExpressionStmt:1( |
| 751 |
IndexExpr:1( |
| 752 |
NameExpr(x) |
| 753 |
SliceExpr:1( |
| 754 |
IntExpr(1) |
| 755 |
IntExpr(2) |
| 756 |
IntExpr(3)))) |
| 757 |
ExpressionStmt:2( |
| 758 |
IndexExpr:2( |
| 759 |
NameExpr(x) |
| 760 |
SliceExpr:2( |
| 761 |
IntExpr(1) |
| 762 |
<empty> |
| 763 |
IntExpr(2)))) |
| 764 |
ExpressionStmt:3( |
| 765 |
IndexExpr:3( |
| 766 |
NameExpr(x) |
| 767 |
SliceExpr:3( |
| 768 |
<empty> |
| 769 |
IntExpr(1) |
| 770 |
IntExpr(2)))) |
| 771 |
ExpressionStmt:4( |
| 772 |
IndexExpr:4( |
| 773 |
NameExpr(x) |
| 774 |
SliceExpr:4( |
| 775 |
<empty> |
| 776 |
<empty> |
| 777 |
IntExpr(2))))) |
| 778 |
|
| 779 |
[case testFunctionSignature] |
| 780 |
def f() -> int: |
| 781 |
pass |
| 782 |
def g() -> None: |
| 783 |
pass |
| 784 |
def h(x: foo.bar, y, z: x.y.z): |
| 785 |
pass |
| 786 |
[out] |
| 787 |
MypyFile:1( |
| 788 |
FuncDef:1( |
| 789 |
f |
| 790 |
def () -> int? |
| 791 |
Block:2( |
| 792 |
PassStmt:2())) |
| 793 |
FuncDef:3( |
| 794 |
g |
| 795 |
def () -> None? |
| 796 |
Block:4( |
| 797 |
PassStmt:4())) |
| 798 |
FuncDef:5( |
| 799 |
h |
| 800 |
Args( |
| 801 |
Var(x) |
| 802 |
Var(y) |
| 803 |
Var(z)) |
| 804 |
def (x: foo.bar?, y: Any, z: x.y.z?) -> Any |
| 805 |
Block:6( |
| 806 |
PassStmt:6()))) |
| 807 |
|
| 808 |
[case testFunctionSignature2] |
| 809 |
def f(x: a[b]) -> c.d[e.f.g[h], i]: |
| 810 |
pass |
| 811 |
[out] |
| 812 |
MypyFile:1( |
| 813 |
FuncDef:1( |
| 814 |
f |
| 815 |
Args( |
| 816 |
Var(x)) |
| 817 |
def (x: a?[b?]) -> c.d?[e.f.g?[h?], i?] |
| 818 |
Block:2( |
| 819 |
PassStmt:2()))) |
| 820 |
|
| 821 |
[case testUnionTypes] |
| 822 |
def f(x: int | str) -> bool | None: |
| 823 |
pass |
| 824 |
[out] |
| 825 |
MypyFile:1( |
| 826 |
FuncDef:1( |
| 827 |
f |
| 828 |
Args( |
| 829 |
Var(x)) |
| 830 |
def (x: int? | str?) -> bool? | None? |
| 831 |
Block:2( |
| 832 |
PassStmt:2()))) |
| 833 |
|
| 834 |
[case testAnnotatedAssignment] |
| 835 |
x: int |
| 836 |
y: str = "hello" |
| 837 |
[out] |
| 838 |
MypyFile:1( |
| 839 |
AssignmentStmt:1( |
| 840 |
NameExpr(x) |
| 841 |
TempNode:1( |
| 842 |
Any) |
| 843 |
int?) |
| 844 |
AssignmentStmt:2( |
| 845 |
NameExpr(y) |
| 846 |
StrExpr(hello) |
| 847 |
str?)) |
| 848 |
|
| 849 |
[case testImportStatements] |
| 850 |
import x |
| 851 |
import a, b |
| 852 |
import y as z |
| 853 |
[out] |
| 854 |
MypyFile:1( |
| 855 |
Import:1(x) |
| 856 |
Import:2(a, b) |
| 857 |
Import:3(y : z)) |
| 858 |
|
| 859 |
[case testImportFromStatements] |
| 860 |
from os import path |
| 861 |
from sys import argv, exit |
| 862 |
from typing import List as L |
| 863 |
from . import foo |
| 864 |
from .. import bar |
| 865 |
from .pkg import baz |
| 866 |
[out] |
| 867 |
MypyFile:1( |
| 868 |
ImportFrom:1(os, [path]) |
| 869 |
ImportFrom:2(sys, [argv, exit]) |
| 870 |
ImportFrom:3(typing, [List : L]) |
| 871 |
ImportFrom:4(., [foo]) |
| 872 |
ImportFrom:5(.., [bar]) |
| 873 |
ImportFrom:6(.pkg, [baz])) |
| 874 |
|
| 875 |
[case testImportAllStatements] |
| 876 |
from os import * |
| 877 |
from . import * |
| 878 |
from .. import * |
| 879 |
from .pkg import * |
| 880 |
[out] |
| 881 |
MypyFile:1( |
| 882 |
ImportAll:1(os) |
| 883 |
ImportAll:2(.) |
| 884 |
ImportAll:3(..) |
| 885 |
ImportAll:4(.pkg)) |
| 886 |
|
| 887 |
[case testRaiseStatements] |
| 888 |
raise |
| 889 |
raise ValueError |
| 890 |
raise ValueError("error message") |
| 891 |
raise KeyError from e |
| 892 |
[out] |
| 893 |
MypyFile:1( |
| 894 |
RaiseStmt:1() |
| 895 |
RaiseStmt:2( |
| 896 |
NameExpr(ValueError)) |
| 897 |
RaiseStmt:3( |
| 898 |
CallExpr:3( |
| 899 |
NameExpr(ValueError) |
| 900 |
Args( |
| 901 |
StrExpr(error message)))) |
| 902 |
RaiseStmt:4( |
| 903 |
NameExpr(KeyError) |
| 904 |
NameExpr(e))) |
| 905 |
|
| 906 |
[case testAssertStatements] |
| 907 |
assert x |
| 908 |
assert x == y |
| 909 |
assert condition, "error message" |
| 910 |
[out] |
| 911 |
MypyFile:1( |
| 912 |
AssertStmt:1( |
| 913 |
NameExpr(x)) |
| 914 |
AssertStmt:2( |
| 915 |
ComparisonExpr:2( |
| 916 |
== |
| 917 |
NameExpr(x) |
| 918 |
NameExpr(y))) |
| 919 |
AssertStmt:3( |
| 920 |
NameExpr(condition) |
| 921 |
StrExpr(error message))) |
| 922 |
|
| 923 |
[case testForStatements] |
| 924 |
for x in items: |
| 925 |
pass |
| 926 |
for i, j in pairs: |
| 927 |
x = 1 |
| 928 |
for y in range(10): |
| 929 |
break |
| 930 |
else: |
| 931 |
continue |
| 932 |
[out] |
| 933 |
MypyFile:1( |
| 934 |
ForStmt:1( |
| 935 |
NameExpr(x) |
| 936 |
NameExpr(items) |
| 937 |
Block:2( |
| 938 |
PassStmt:2())) |
| 939 |
ForStmt:3( |
| 940 |
TupleExpr:3( |
| 941 |
NameExpr(i) |
| 942 |
NameExpr(j)) |
| 943 |
NameExpr(pairs) |
| 944 |
Block:4( |
| 945 |
AssignmentStmt:4( |
| 946 |
NameExpr(x) |
| 947 |
IntExpr(1)))) |
| 948 |
ForStmt:5( |
| 949 |
NameExpr(y) |
| 950 |
CallExpr:5( |
| 951 |
NameExpr(range) |
| 952 |
Args( |
| 953 |
IntExpr(10))) |
| 954 |
Block:6( |
| 955 |
BreakStmt:6()) |
| 956 |
Else( |
| 957 |
ContinueStmt:8()))) |
| 958 |
|
| 959 |
[case testWithStatements] |
| 960 |
with f: |
| 961 |
pass |
| 962 |
with open("file") as f: |
| 963 |
x = 1 |
| 964 |
with a as x, b as y: |
| 965 |
break |
| 966 |
[out] |
| 967 |
MypyFile:1( |
| 968 |
WithStmt:1( |
| 969 |
Expr( |
| 970 |
NameExpr(f)) |
| 971 |
Block:2( |
| 972 |
PassStmt:2())) |
| 973 |
WithStmt:3( |
| 974 |
Expr( |
| 975 |
CallExpr:3( |
| 976 |
NameExpr(open) |
| 977 |
Args( |
| 978 |
StrExpr(file)))) |
| 979 |
Target( |
| 980 |
NameExpr(f)) |
| 981 |
Block:4( |
| 982 |
AssignmentStmt:4( |
| 983 |
NameExpr(x) |
| 984 |
IntExpr(1)))) |
| 985 |
WithStmt:5( |
| 986 |
Expr( |
| 987 |
NameExpr(a)) |
| 988 |
Target( |
| 989 |
NameExpr(x)) |
| 990 |
Expr( |
| 991 |
NameExpr(b)) |
| 992 |
Target( |
| 993 |
NameExpr(y)) |
| 994 |
Block:6( |
| 995 |
BreakStmt:6()))) |
| 996 |
|
| 997 |
[case testBreakAndContinue] |
| 998 |
while True: |
| 999 |
break |
| 1000 |
while x: |
| 1001 |
continue |
| 1002 |
while y: |
| 1003 |
if z: |
| 1004 |
break |
| 1005 |
else: |
| 1006 |
continue |
| 1007 |
[out] |
| 1008 |
MypyFile:1( |
| 1009 |
WhileStmt:1( |
| 1010 |
NameExpr(True) |
| 1011 |
Block:2( |
| 1012 |
BreakStmt:2())) |
| 1013 |
WhileStmt:3( |
| 1014 |
NameExpr(x) |
| 1015 |
Block:4( |
| 1016 |
ContinueStmt:4())) |
| 1017 |
WhileStmt:5( |
| 1018 |
NameExpr(y) |
| 1019 |
Block:6( |
| 1020 |
IfStmt:6( |
| 1021 |
If( |
| 1022 |
NameExpr(z)) |
| 1023 |
Then( |
| 1024 |
BreakStmt:7()) |
| 1025 |
Else( |
| 1026 |
ContinueStmt:9()))))) |
| 1027 |
|
| 1028 |
[case testGeneratorExpressions] |
| 1029 |
(x for x in items) |
| 1030 |
(x * 2 for x in range(10) if x > 5) |
| 1031 |
(x + y for x in range(3) for y in range(2)) |
| 1032 |
[out] |
| 1033 |
MypyFile:1( |
| 1034 |
ExpressionStmt:1( |
| 1035 |
GeneratorExpr:1( |
| 1036 |
NameExpr(x) |
| 1037 |
NameExpr(x) |
| 1038 |
NameExpr(items))) |
| 1039 |
ExpressionStmt:2( |
| 1040 |
GeneratorExpr:2( |
| 1041 |
OpExpr:2( |
| 1042 |
* |
| 1043 |
NameExpr(x) |
| 1044 |
IntExpr(2)) |
| 1045 |
NameExpr(x) |
| 1046 |
CallExpr:2( |
| 1047 |
NameExpr(range) |
| 1048 |
Args( |
| 1049 |
IntExpr(10))) |
| 1050 |
ComparisonExpr:2( |
| 1051 |
> |
| 1052 |
NameExpr(x) |
| 1053 |
IntExpr(5)))) |
| 1054 |
ExpressionStmt:3( |
| 1055 |
GeneratorExpr:3( |
| 1056 |
OpExpr:3( |
| 1057 |
+ |
| 1058 |
NameExpr(x) |
| 1059 |
NameExpr(y)) |
| 1060 |
NameExpr(x) |
| 1061 |
NameExpr(y) |
| 1062 |
CallExpr:3( |
| 1063 |
NameExpr(range) |
| 1064 |
Args( |
| 1065 |
IntExpr(3))) |
| 1066 |
CallExpr:3( |
| 1067 |
NameExpr(range) |
| 1068 |
Args( |
| 1069 |
IntExpr(2)))))) |
| 1070 |
|
| 1071 |
[case testYieldExpressions] |
| 1072 |
def gen(): |
| 1073 |
yield |
| 1074 |
yield 1 |
| 1075 |
yield from items |
| 1076 |
[out] |
| 1077 |
MypyFile:1( |
| 1078 |
FuncDef:1( |
| 1079 |
gen |
| 1080 |
Block:2( |
| 1081 |
ExpressionStmt:2( |
| 1082 |
YieldExpr:2()) |
| 1083 |
ExpressionStmt:3( |
| 1084 |
YieldExpr:3( |
| 1085 |
IntExpr(1))) |
| 1086 |
ExpressionStmt:4( |
| 1087 |
YieldFromExpr:4( |
| 1088 |
NameExpr(items)))))) |
| 1089 |
|
| 1090 |
[case testListAndSetComprehensions] |
| 1091 |
a = [x for x in items] |
| 1092 |
b = [x * 2 for x in range(10) if x > 5] |
| 1093 |
c = {y for y in data} |
| 1094 |
d = {z + 1 for z in nums if z < 100} |
| 1095 |
[out] |
| 1096 |
MypyFile:1( |
| 1097 |
AssignmentStmt:1( |
| 1098 |
NameExpr(a) |
| 1099 |
ListComprehension:1( |
| 1100 |
GeneratorExpr:1( |
| 1101 |
NameExpr(x) |
| 1102 |
NameExpr(x) |
| 1103 |
NameExpr(items)))) |
| 1104 |
AssignmentStmt:2( |
| 1105 |
NameExpr(b) |
| 1106 |
ListComprehension:2( |
| 1107 |
GeneratorExpr:2( |
| 1108 |
OpExpr:2( |
| 1109 |
* |
| 1110 |
NameExpr(x) |
| 1111 |
IntExpr(2)) |
| 1112 |
NameExpr(x) |
| 1113 |
CallExpr:2( |
| 1114 |
NameExpr(range) |
| 1115 |
Args( |
| 1116 |
IntExpr(10))) |
| 1117 |
ComparisonExpr:2( |
| 1118 |
> |
| 1119 |
NameExpr(x) |
| 1120 |
IntExpr(5))))) |
| 1121 |
AssignmentStmt:3( |
| 1122 |
NameExpr(c) |
| 1123 |
SetComprehension:3( |
| 1124 |
GeneratorExpr:3( |
| 1125 |
NameExpr(y) |
| 1126 |
NameExpr(y) |
| 1127 |
NameExpr(data)))) |
| 1128 |
AssignmentStmt:4( |
| 1129 |
NameExpr(d) |
| 1130 |
SetComprehension:4( |
| 1131 |
GeneratorExpr:4( |
| 1132 |
OpExpr:4( |
| 1133 |
+ |
| 1134 |
NameExpr(z) |
| 1135 |
IntExpr(1)) |
| 1136 |
NameExpr(z) |
| 1137 |
NameExpr(nums) |
| 1138 |
ComparisonExpr:4( |
| 1139 |
< |
| 1140 |
NameExpr(z) |
| 1141 |
IntExpr(100)))))) |
| 1142 |
|
| 1143 |
[case testDictComprehensions] |
| 1144 |
a = {k: v for k, v in items} |
| 1145 |
b = {x: x * 2 for x in range(10) if x > 5} |
| 1146 |
[out] |
| 1147 |
MypyFile:1( |
| 1148 |
AssignmentStmt:1( |
| 1149 |
NameExpr(a) |
| 1150 |
DictionaryComprehension:1( |
| 1151 |
NameExpr(k) |
| 1152 |
NameExpr(v) |
| 1153 |
TupleExpr:1( |
| 1154 |
NameExpr(k) |
| 1155 |
NameExpr(v)) |
| 1156 |
NameExpr(items))) |
| 1157 |
AssignmentStmt:2( |
| 1158 |
NameExpr(b) |
| 1159 |
DictionaryComprehension:2( |
| 1160 |
NameExpr(x) |
| 1161 |
OpExpr:2( |
| 1162 |
* |
| 1163 |
NameExpr(x) |
| 1164 |
IntExpr(2)) |
| 1165 |
NameExpr(x) |
| 1166 |
CallExpr:2( |
| 1167 |
NameExpr(range) |
| 1168 |
Args( |
| 1169 |
IntExpr(10))) |
| 1170 |
ComparisonExpr:2( |
| 1171 |
> |
| 1172 |
NameExpr(x) |
| 1173 |
IntExpr(5))))) |
| 1174 |
|
| 1175 |
[case testDecoratedFuncDef] |
| 1176 |
@dec |
| 1177 |
def foo(): |
| 1178 |
pass |
| 1179 |
class C: |
| 1180 |
@dec() |
| 1181 |
@staticmethod |
| 1182 |
def foo(): |
| 1183 |
pass |
| 1184 |
[out] |
| 1185 |
MypyFile:1( |
| 1186 |
Decorator:1( |
| 1187 |
Var(foo) |
| 1188 |
NameExpr(dec) |
| 1189 |
FuncDef:2( |
| 1190 |
foo |
| 1191 |
Block:3( |
| 1192 |
PassStmt:3()))) |
| 1193 |
ClassDef:4( |
| 1194 |
C |
| 1195 |
Decorator:5( |
| 1196 |
Var(foo) |
| 1197 |
CallExpr:5( |
| 1198 |
NameExpr(dec) |
| 1199 |
Args()) |
| 1200 |
NameExpr(staticmethod) |
| 1201 |
FuncDef:7( |
| 1202 |
foo |
| 1203 |
Block:8( |
| 1204 |
PassStmt:8()))))) |
| 1205 |
[case testTryFinally] |
| 1206 |
try: |
| 1207 |
x |
| 1208 |
finally: |
| 1209 |
y |
| 1210 |
[out] |
| 1211 |
MypyFile:1( |
| 1212 |
TryStmt:1( |
| 1213 |
Block:2( |
| 1214 |
ExpressionStmt:2( |
| 1215 |
NameExpr(x))) |
| 1216 |
Finally( |
| 1217 |
ExpressionStmt:4( |
| 1218 |
NameExpr(y))))) |
| 1219 |
|
| 1220 |
[case testTryExcept] |
| 1221 |
try: |
| 1222 |
x |
| 1223 |
except Exception: |
| 1224 |
y |
| 1225 |
[out] |
| 1226 |
MypyFile:1( |
| 1227 |
TryStmt:1( |
| 1228 |
Block:2( |
| 1229 |
ExpressionStmt:2( |
| 1230 |
NameExpr(x))) |
| 1231 |
NameExpr(Exception) |
| 1232 |
Block:4( |
| 1233 |
ExpressionStmt:4( |
| 1234 |
NameExpr(y))))) |
| 1235 |
|
| 1236 |
[case testTryExceptWithVar] |
| 1237 |
try: |
| 1238 |
x |
| 1239 |
except Exception as e: |
| 1240 |
y |
| 1241 |
[out] |
| 1242 |
MypyFile:1( |
| 1243 |
TryStmt:1( |
| 1244 |
Block:2( |
| 1245 |
ExpressionStmt:2( |
| 1246 |
NameExpr(x))) |
| 1247 |
NameExpr(Exception) |
| 1248 |
NameExpr(e) |
| 1249 |
Block:4( |
| 1250 |
ExpressionStmt:4( |
| 1251 |
NameExpr(y))))) |
| 1252 |
|
| 1253 |
[case testTryExceptElse] |
| 1254 |
try: |
| 1255 |
x |
| 1256 |
except Exception: |
| 1257 |
y |
| 1258 |
else: |
| 1259 |
z |
| 1260 |
[out] |
| 1261 |
MypyFile:1( |
| 1262 |
TryStmt:1( |
| 1263 |
Block:2( |
| 1264 |
ExpressionStmt:2( |
| 1265 |
NameExpr(x))) |
| 1266 |
NameExpr(Exception) |
| 1267 |
Block:4( |
| 1268 |
ExpressionStmt:4( |
| 1269 |
NameExpr(y))) |
| 1270 |
Else( |
| 1271 |
ExpressionStmt:6( |
| 1272 |
NameExpr(z))))) |
| 1273 |
|
| 1274 |
[case testTryMultipleExcept] |
| 1275 |
try: |
| 1276 |
x |
| 1277 |
except ValueError: |
| 1278 |
y |
| 1279 |
except KeyError as e: |
| 1280 |
z |
| 1281 |
[out] |
| 1282 |
MypyFile:1( |
| 1283 |
TryStmt:1( |
| 1284 |
Block:2( |
| 1285 |
ExpressionStmt:2( |
| 1286 |
NameExpr(x))) |
| 1287 |
NameExpr(ValueError) |
| 1288 |
Block:4( |
| 1289 |
ExpressionStmt:4( |
| 1290 |
NameExpr(y))) |
| 1291 |
NameExpr(KeyError) |
| 1292 |
NameExpr(e) |
| 1293 |
Block:6( |
| 1294 |
ExpressionStmt:6( |
| 1295 |
NameExpr(z))))) |
| 1296 |
|
| 1297 |
[case testConditionalExprSimple] |
| 1298 |
x if y else z |
| 1299 |
[out] |
| 1300 |
MypyFile:1( |
| 1301 |
ExpressionStmt:1( |
| 1302 |
ConditionalExpr:1( |
| 1303 |
Condition( |
| 1304 |
NameExpr(y)) |
| 1305 |
NameExpr(x) |
| 1306 |
NameExpr(z)))) |
| 1307 |
|
| 1308 |
[case testFunctionWithCallableType] |
| 1309 |
def f(x: Callable[[int, str], None]) -> None: |
| 1310 |
pass |
| 1311 |
[out] |
| 1312 |
MypyFile:1( |
| 1313 |
FuncDef:1( |
| 1314 |
f |
| 1315 |
Args( |
| 1316 |
Var(x)) |
| 1317 |
def (x: Callable?[<TypeList int?, str?>, None?]) -> None? |
| 1318 |
Block:2( |
| 1319 |
PassStmt:2()))) |
| 1320 |
|
| 1321 |
[case testFunctionWithEmptyCallableType] |
| 1322 |
def g(callback: Callable[[], bool]) -> int: |
| 1323 |
return 1 |
| 1324 |
[out] |
| 1325 |
MypyFile:1( |
| 1326 |
FuncDef:1( |
| 1327 |
g |
| 1328 |
Args( |
| 1329 |
Var(callback)) |
| 1330 |
def (callback: Callable?[<TypeList >, bool?]) -> int? |
| 1331 |
Block:2( |
| 1332 |
ReturnStmt:2( |
| 1333 |
IntExpr(1))))) |
| 1334 |
|
| 1335 |
[case testFunctionWithComplexCallableType] |
| 1336 |
def h(f: Callable[[List[int], Dict[str, int]], Tuple[int, str]]) -> None: |
| 1337 |
pass |
| 1338 |
[out] |
| 1339 |
MypyFile:1( |
| 1340 |
FuncDef:1( |
| 1341 |
h |
| 1342 |
Args( |
| 1343 |
Var(f)) |
| 1344 |
def (f: Callable?[<TypeList List?[int?], Dict?[str?, int?]>, Tuple?[int?, str?]]) -> None? |
| 1345 |
Block:2( |
| 1346 |
PassStmt:2()))) |
| 1347 |
|
| 1348 |
[case testFunctionWithEllipsisCallableType] |
| 1349 |
def f(callback: Callable[..., int]) -> None: |
| 1350 |
pass |
| 1351 |
[out] |
| 1352 |
MypyFile:1( |
| 1353 |
FuncDef:1( |
| 1354 |
f |
| 1355 |
Args( |
| 1356 |
Var(callback)) |
| 1357 |
def (callback: Callable?[..., int?]) -> None? |
| 1358 |
Block:2( |
| 1359 |
PassStmt:2()))) |
| 1360 |
|
| 1361 |
[case testCallableWithArgConstructor] |
| 1362 |
from typing import Callable |
| 1363 |
from mypy_extensions import Arg |
| 1364 |
def f(x: Callable[[Arg(int, 'x'), Arg(str, 'y')], bool]) -> None: |
| 1365 |
pass |
| 1366 |
[out] |
| 1367 |
MypyFile:1( |
| 1368 |
ImportFrom:1(typing, [Callable]) |
| 1369 |
ImportFrom:2(mypy_extensions, [Arg]) |
| 1370 |
FuncDef:3( |
| 1371 |
f |
| 1372 |
Args( |
| 1373 |
Var(x)) |
| 1374 |
def (x: Callable?[<TypeList Arg(int?, x), Arg(str?, y)>, bool?]) -> None? |
| 1375 |
Block:4( |
| 1376 |
PassStmt:4()))) |
| 1377 |
|
| 1378 |
[case testCallableWithArgConstructorKeywordSyntax] |
| 1379 |
from typing import Callable |
| 1380 |
from mypy_extensions import Arg |
| 1381 |
def f(callback: Callable[[Arg(type=int, name='value')], str]) -> None: |
| 1382 |
pass |
| 1383 |
[out] |
| 1384 |
MypyFile:1( |
| 1385 |
ImportFrom:1(typing, [Callable]) |
| 1386 |
ImportFrom:2(mypy_extensions, [Arg]) |
| 1387 |
FuncDef:3( |
| 1388 |
f |
| 1389 |
Args( |
| 1390 |
Var(callback)) |
| 1391 |
def (callback: Callable?[<TypeList Arg(int?, value)>, str?]) -> None? |
| 1392 |
Block:4( |
| 1393 |
PassStmt:4()))) |
| 1394 |
|
| 1395 |
[case testCallableWithArgNoName] |
| 1396 |
from typing import Callable |
| 1397 |
from mypy_extensions import Arg |
| 1398 |
def f(x: Callable[[Arg(int)], bool]) -> None: |
| 1399 |
pass |
| 1400 |
[out] |
| 1401 |
MypyFile:1( |
| 1402 |
ImportFrom:1(typing, [Callable]) |
| 1403 |
ImportFrom:2(mypy_extensions, [Arg]) |
| 1404 |
FuncDef:3( |
| 1405 |
f |
| 1406 |
Args( |
| 1407 |
Var(x)) |
| 1408 |
def (x: Callable?[<TypeList Arg(int?)>, bool?]) -> None? |
| 1409 |
Block:4( |
| 1410 |
PassStmt:4()))) |
| 1411 |
|
| 1412 |
[case testLiteralTypes] |
| 1413 |
x: Literal[True, False] |
| 1414 |
[out] |
| 1415 |
MypyFile:1( |
| 1416 |
AssignmentStmt:1( |
| 1417 |
NameExpr(x) |
| 1418 |
TempNode:1( |
| 1419 |
Any) |
| 1420 |
Literal?[True, False])) |
| 1421 |
|
| 1422 |
[case testLiteralIntTypes] |
| 1423 |
x: Literal[1] |
| 1424 |
y: Literal[1, 2, 3] |
| 1425 |
z: Literal[-1] |
| 1426 |
w: Literal[-1, 0, 1] |
| 1427 |
[out] |
| 1428 |
MypyFile:1( |
| 1429 |
AssignmentStmt:1( |
| 1430 |
NameExpr(x) |
| 1431 |
TempNode:1( |
| 1432 |
Any) |
| 1433 |
Literal?[1]) |
| 1434 |
AssignmentStmt:2( |
| 1435 |
NameExpr(y) |
| 1436 |
TempNode:2( |
| 1437 |
Any) |
| 1438 |
Literal?[1, 2, 3]) |
| 1439 |
AssignmentStmt:3( |
| 1440 |
NameExpr(z) |
| 1441 |
TempNode:3( |
| 1442 |
Any) |
| 1443 |
Literal?[-1]) |
| 1444 |
AssignmentStmt:4( |
| 1445 |
NameExpr(w) |
| 1446 |
TempNode:4( |
| 1447 |
Any) |
| 1448 |
Literal?[-1, 0, 1])) |
| 1449 |
|
| 1450 |
[case testDelStmt] |
| 1451 |
del x |
| 1452 |
del x[0], y[1] |
| 1453 |
del a.b |
| 1454 |
[out] |
| 1455 |
MypyFile:1( |
| 1456 |
DelStmt:1( |
| 1457 |
NameExpr(x)) |
| 1458 |
DelStmt:2( |
| 1459 |
TupleExpr:2( |
| 1460 |
IndexExpr:2( |
| 1461 |
NameExpr(x) |
| 1462 |
IntExpr(0)) |
| 1463 |
IndexExpr:2( |
| 1464 |
NameExpr(y) |
| 1465 |
IntExpr(1)))) |
| 1466 |
DelStmt:3( |
| 1467 |
MemberExpr:3( |
| 1468 |
NameExpr(a) |
| 1469 |
b))) |
| 1470 |
|
| 1471 |
[case testFString] |
| 1472 |
f"foo {x}" |
| 1473 |
[out] |
| 1474 |
MypyFile:1( |
| 1475 |
ExpressionStmt:1( |
| 1476 |
CallExpr:1( |
| 1477 |
MemberExpr:1( |
| 1478 |
StrExpr() |
| 1479 |
join) |
| 1480 |
Args( |
| 1481 |
ListExpr:1( |
| 1482 |
StrExpr(foo ) |
| 1483 |
CallExpr:1( |
| 1484 |
MemberExpr:1( |
| 1485 |
StrExpr({:{}}) |
| 1486 |
format) |
| 1487 |
Args( |
| 1488 |
NameExpr(x) |
| 1489 |
StrExpr()))))))) |
| 1490 |
|
| 1491 |
[case testFStringWithConversion] |
| 1492 |
x = 'mypy' |
| 1493 |
F'Hello {x!r}' |
| 1494 |
[out] |
| 1495 |
MypyFile:1( |
| 1496 |
AssignmentStmt:1( |
| 1497 |
NameExpr(x) |
| 1498 |
StrExpr(mypy)) |
| 1499 |
ExpressionStmt:2( |
| 1500 |
CallExpr:2( |
| 1501 |
MemberExpr:2( |
| 1502 |
StrExpr() |
| 1503 |
join) |
| 1504 |
Args( |
| 1505 |
ListExpr:2( |
| 1506 |
StrExpr(Hello ) |
| 1507 |
CallExpr:2( |
| 1508 |
MemberExpr:2( |
| 1509 |
StrExpr({!r:{}}) |
| 1510 |
format) |
| 1511 |
Args( |
| 1512 |
NameExpr(x) |
| 1513 |
StrExpr()))))))) |
| 1514 |
|
| 1515 |
[case testFStringTrivial] |
| 1516 |
f"foo" |
| 1517 |
f"{x}" |
| 1518 |
f"foo" "bar" |
| 1519 |
[out] |
| 1520 |
MypyFile:1( |
| 1521 |
ExpressionStmt:1( |
| 1522 |
StrExpr(foo)) |
| 1523 |
ExpressionStmt:2( |
| 1524 |
CallExpr:2( |
| 1525 |
MemberExpr:2( |
| 1526 |
StrExpr({:{}}) |
| 1527 |
format) |
| 1528 |
Args( |
| 1529 |
NameExpr(x) |
| 1530 |
StrExpr()))) |
| 1531 |
ExpressionStmt:3( |
| 1532 |
StrExpr(foobar))) |
| 1533 |
|
| 1534 |
[case testFStringWithOnlyFormatSpecifier] |
| 1535 |
x = 'mypy' |
| 1536 |
f'Hello {x:<30}' |
| 1537 |
[out] |
| 1538 |
MypyFile:1( |
| 1539 |
AssignmentStmt:1( |
| 1540 |
NameExpr(x) |
| 1541 |
StrExpr(mypy)) |
| 1542 |
ExpressionStmt:2( |
| 1543 |
CallExpr:2( |
| 1544 |
MemberExpr:2( |
| 1545 |
StrExpr() |
| 1546 |
join) |
| 1547 |
Args( |
| 1548 |
ListExpr:2( |
| 1549 |
StrExpr(Hello ) |
| 1550 |
CallExpr:2( |
| 1551 |
MemberExpr:2( |
| 1552 |
StrExpr({:{}}) |
| 1553 |
format) |
| 1554 |
Args( |
| 1555 |
NameExpr(x) |
| 1556 |
StrExpr(<30)))))))) |
| 1557 |
|
| 1558 |
[case testFStringWithFormatSpecifierExpression] |
| 1559 |
x = 'mypy' |
| 1560 |
y = 30 |
| 1561 |
f'Hello {x!s:<{y+y}}' |
| 1562 |
[out] |
| 1563 |
MypyFile:1( |
| 1564 |
AssignmentStmt:1( |
| 1565 |
NameExpr(x) |
| 1566 |
StrExpr(mypy)) |
| 1567 |
AssignmentStmt:2( |
| 1568 |
NameExpr(y) |
| 1569 |
IntExpr(30)) |
| 1570 |
ExpressionStmt:3( |
| 1571 |
CallExpr:3( |
| 1572 |
MemberExpr:3( |
| 1573 |
StrExpr() |
| 1574 |
join) |
| 1575 |
Args( |
| 1576 |
ListExpr:3( |
| 1577 |
StrExpr(Hello ) |
| 1578 |
CallExpr:3( |
| 1579 |
MemberExpr:3( |
| 1580 |
StrExpr({!s:{}}) |
| 1581 |
format) |
| 1582 |
Args( |
| 1583 |
NameExpr(x) |
| 1584 |
CallExpr:3( |
| 1585 |
MemberExpr:3( |
| 1586 |
StrExpr() |
| 1587 |
join) |
| 1588 |
Args( |
| 1589 |
ListExpr:3( |
| 1590 |
StrExpr(<) |
| 1591 |
CallExpr:3( |
| 1592 |
MemberExpr:3( |
| 1593 |
StrExpr({:{}}) |
| 1594 |
format) |
| 1595 |
Args( |
| 1596 |
OpExpr:3( |
| 1597 |
+ |
| 1598 |
NameExpr(y) |
| 1599 |
NameExpr(y)) |
| 1600 |
StrExpr())))))))))))) |
| 1601 |
|
| 1602 |
[case testSimpleLambda] |
| 1603 |
lambda: 1 |
| 1604 |
[out] |
| 1605 |
MypyFile:1( |
| 1606 |
ExpressionStmt:1( |
| 1607 |
LambdaExpr:1( |
| 1608 |
Block:1( |
| 1609 |
ReturnStmt:1( |
| 1610 |
IntExpr(1)))))) |
| 1611 |
|
| 1612 |
[case testLambdaWithOneArg] |
| 1613 |
lambda x: y + 1 |
| 1614 |
[out] |
| 1615 |
MypyFile:1( |
| 1616 |
ExpressionStmt:1( |
| 1617 |
LambdaExpr:1( |
| 1618 |
Args( |
| 1619 |
Var(x)) |
| 1620 |
Block:1( |
| 1621 |
ReturnStmt:1( |
| 1622 |
OpExpr:1( |
| 1623 |
+ |
| 1624 |
NameExpr(y) |
| 1625 |
IntExpr(1))))))) |
| 1626 |
|
| 1627 |
[case testLambdaWithMultipleArgs] |
| 1628 |
lambda x, y: x + y |
| 1629 |
[out] |
| 1630 |
MypyFile:1( |
| 1631 |
ExpressionStmt:1( |
| 1632 |
LambdaExpr:1( |
| 1633 |
Args( |
| 1634 |
Var(x) |
| 1635 |
Var(y)) |
| 1636 |
Block:1( |
| 1637 |
ReturnStmt:1( |
| 1638 |
OpExpr:1( |
| 1639 |
+ |
| 1640 |
NameExpr(x) |
| 1641 |
NameExpr(y))))))) |
| 1642 |
|
| 1643 |
[case testLambdaWithDefault] |
| 1644 |
lambda x=2: x |
| 1645 |
[out] |
| 1646 |
MypyFile:1( |
| 1647 |
ExpressionStmt:1( |
| 1648 |
LambdaExpr:1( |
| 1649 |
Args( |
| 1650 |
default( |
| 1651 |
Var(x) |
| 1652 |
IntExpr(2))) |
| 1653 |
Block:1( |
| 1654 |
ReturnStmt:1( |
| 1655 |
NameExpr(x)))))) |
| 1656 |
|
| 1657 |
[case testLambdaInCall] |
| 1658 |
map(lambda x: x * 2, items) |
| 1659 |
[out] |
| 1660 |
MypyFile:1( |
| 1661 |
ExpressionStmt:1( |
| 1662 |
CallExpr:1( |
| 1663 |
NameExpr(map) |
| 1664 |
Args( |
| 1665 |
LambdaExpr:1( |
| 1666 |
Args( |
| 1667 |
Var(x)) |
| 1668 |
Block:1( |
| 1669 |
ReturnStmt:1( |
| 1670 |
OpExpr:1( |
| 1671 |
* |
| 1672 |
NameExpr(x) |
| 1673 |
IntExpr(2))))) |
| 1674 |
NameExpr(items))))) |
| 1675 |
|
| 1676 |
[case testNamedExprSimple] |
| 1677 |
if (x := 1): |
| 1678 |
pass |
| 1679 |
[out] |
| 1680 |
MypyFile:1( |
| 1681 |
IfStmt:1( |
| 1682 |
If( |
| 1683 |
AssignmentExpr:1( |
| 1684 |
NameExpr(x) |
| 1685 |
IntExpr(1))) |
| 1686 |
Then( |
| 1687 |
PassStmt:2()))) |
| 1688 |
|
| 1689 |
[case testStarExpression] |
| 1690 |
*a |
| 1691 |
*a, b |
| 1692 |
a, *b |
| 1693 |
[out] |
| 1694 |
MypyFile:1( |
| 1695 |
ExpressionStmt:1( |
| 1696 |
StarExpr:1( |
| 1697 |
NameExpr(a))) |
| 1698 |
ExpressionStmt:2( |
| 1699 |
TupleExpr:2( |
| 1700 |
StarExpr:2( |
| 1701 |
NameExpr(a)) |
| 1702 |
NameExpr(b))) |
| 1703 |
ExpressionStmt:3( |
| 1704 |
TupleExpr:3( |
| 1705 |
NameExpr(a) |
| 1706 |
StarExpr:3( |
| 1707 |
NameExpr(b))))) |
| 1708 |
|
| 1709 |
[case testBytesLiteral] |
| 1710 |
b"foo" |
| 1711 |
b"foobar" |
| 1712 |
b"x\\n\\'" |
| 1713 |
[out] |
| 1714 |
MypyFile:1( |
| 1715 |
ExpressionStmt:1( |
| 1716 |
BytesExpr(foo)) |
| 1717 |
ExpressionStmt:2( |
| 1718 |
BytesExpr(foobar)) |
| 1719 |
ExpressionStmt:3( |
| •1720 |
BytesExpr(x\\n\\'))) |
| 1721 |
|
| 1722 |
[case testBytesLiteralWithEscapes] |
| 1723 |
b'\r\n\t\x2f\xbe' |
| 1724 |
[out] |
| 1725 |
MypyFile:1( |
| 1726 |
ExpressionStmt:1( |
| 1727 |
BytesExpr(\r\n\t/\xbe))) |
| 1728 |
|
| 1729 |
[case testBytesLiteralOctalEscapes] |
| 1730 |
b'\1\476' |
| 1731 |
[out] |
| 1732 |
MypyFile:1( |
| 1733 |
ExpressionStmt:1( |
| 1734 |
BytesExpr(\x01>))) |
| 1735 |
[case testGlobalAndNonlocal] |
| 1736 |
x = 1 |
| 1737 |
y = 2 |
| 1738 |
def outer(): |
| 1739 |
global x |
| 1740 |
def inner(): |
| 1741 |
nonlocal y |
| 1742 |
global z |
| 1743 |
y = 3 |
| 1744 |
z = 4 |
| 1745 |
x = 5 |
| 1746 |
[out] |
| 1747 |
MypyFile:1( |
| 1748 |
AssignmentStmt:1( |
| 1749 |
NameExpr(x) |
| 1750 |
IntExpr(1)) |
| 1751 |
AssignmentStmt:2( |
| 1752 |
NameExpr(y) |
| 1753 |
IntExpr(2)) |
| 1754 |
FuncDef:3( |
| 1755 |
outer |
| 1756 |
Block:4( |
| 1757 |
GlobalDecl:4( |
| 1758 |
x) |
| 1759 |
FuncDef:5( |
| 1760 |
inner |
| 1761 |
Block:6( |
| 1762 |
NonlocalDecl:6( |
| 1763 |
y) |
| 1764 |
GlobalDecl:7( |
| 1765 |
z) |
| 1766 |
AssignmentStmt:8( |
| 1767 |
NameExpr(y) |
| 1768 |
IntExpr(3)) |
| 1769 |
AssignmentStmt:9( |
| 1770 |
NameExpr(z) |
| 1771 |
IntExpr(4)))) |
| 1772 |
AssignmentStmt:10( |
| 1773 |
NameExpr(x) |
| 1774 |
IntExpr(5))))) |
| 1775 |
[case testAwaitExpression] |
| 1776 |
async def foo(): |
| 1777 |
x = await bar() |
| 1778 |
return await baz(x) |
| 1779 |
[out] |
| 1780 |
MypyFile:1( |
| 1781 |
FuncDef:1( |
| 1782 |
foo |
| 1783 |
Async |
| 1784 |
Block:2( |
| 1785 |
AssignmentStmt:2( |
| 1786 |
NameExpr(x) |
| 1787 |
AwaitExpr:2( |
| 1788 |
CallExpr:2( |
| 1789 |
NameExpr(bar) |
| 1790 |
Args()))) |
| 1791 |
ReturnStmt:3( |
| 1792 |
AwaitExpr:3( |
| 1793 |
CallExpr:3( |
| 1794 |
NameExpr(baz) |
| 1795 |
Args( |
| 1796 |
NameExpr(x)))))))) |
| 1797 |
|
| 1798 |
[case testFunctionOverload] |
| 1799 |
@overload |
| 1800 |
def f() -> x: pass |
| 1801 |
@overload |
| 1802 |
def f() -> y: pass |
| 1803 |
[out] |
| 1804 |
MypyFile:1( |
| 1805 |
OverloadedFuncDef:1( |
| 1806 |
Decorator:1( |
| 1807 |
Var(f) |
| 1808 |
NameExpr(overload) |
| 1809 |
FuncDef:2( |
| 1810 |
f |
| 1811 |
def () -> x? |
| 1812 |
Block:2( |
| 1813 |
PassStmt:2()))) |
| 1814 |
Decorator:3( |
| 1815 |
Var(f) |
| 1816 |
NameExpr(overload) |
| 1817 |
FuncDef:4( |
| 1818 |
f |
| 1819 |
def () -> y? |
| 1820 |
Block:4( |
| 1821 |
PassStmt:4()))))) |
| 1822 |
|
| 1823 |
[case testFunctionOverloadWithImplementation] |
| 1824 |
@overload |
| 1825 |
def f(a: x) -> x: ... |
| 1826 |
@overload |
| 1827 |
def f(a: y) -> y: ... |
| 1828 |
def f(a): pass |
| 1829 |
[out] |
| 1830 |
MypyFile:1( |
| 1831 |
OverloadedFuncDef:1( |
| 1832 |
Decorator:1( |
| 1833 |
Var(f) |
| 1834 |
NameExpr(overload) |
| 1835 |
FuncDef:2( |
| 1836 |
f |
| 1837 |
Args( |
| 1838 |
Var(a)) |
| 1839 |
def (a: x?) -> x? |
| 1840 |
Block:2( |
| 1841 |
ExpressionStmt:2( |
| 1842 |
Ellipsis)))) |
| 1843 |
Decorator:3( |
| 1844 |
Var(f) |
| 1845 |
NameExpr(overload) |
| 1846 |
FuncDef:4( |
| 1847 |
f |
| 1848 |
Args( |
| 1849 |
Var(a)) |
| 1850 |
def (a: y?) -> y? |
| 1851 |
Block:4( |
| 1852 |
ExpressionStmt:4( |
| 1853 |
Ellipsis)))) |
| 1854 |
FuncDef:5( |
| 1855 |
f |
| 1856 |
Args( |
| 1857 |
Var(a)) |
| 1858 |
Block:5( |
| 1859 |
PassStmt:5())))) |
| 1860 |
|
| 1861 |
[case testTypeIgnores] |
| 1862 |
x = 1 # type: ignore |
| 1863 |
y = ( |
| 1864 |
2 # type: ignore # Comment |
| 1865 |
) |
| 1866 |
y = 1 # foo: ignore |
| 1867 |
z = 1 #type: ignore[x] |
| 1868 |
zz = 1 #type: ignore [ foo, arg-type ] |
| 1869 |
[out] |
| 1870 |
ignore: 1 |
| 1871 |
ignore: 3 |
| 1872 |
ignore: 6 [x] |
| 1873 |
ignore: 7 [foo, arg-type] |
| 1874 |
MypyFile:1( |
| 1875 |
AssignmentStmt:1( |
| 1876 |
NameExpr(x) |
| 1877 |
IntExpr(1)) |
| 1878 |
AssignmentStmt:2( |
| 1879 |
NameExpr(y) |
| 1880 |
IntExpr(2)) |
| 1881 |
AssignmentStmt:5( |
| 1882 |
NameExpr(y) |
| 1883 |
IntExpr(1)) |
| 1884 |
AssignmentStmt:6( |
| 1885 |
NameExpr(z) |
| 1886 |
IntExpr(1)) |
| 1887 |
AssignmentStmt:7( |
| 1888 |
NameExpr(zz) |
| 1889 |
IntExpr(1))) |
| 1890 |
|
| 1891 |
[case testMetaclass] |
| 1892 |
class Foo(metaclass=Bar): pass |
| 1893 |
[out] |
| 1894 |
MypyFile:1( |
| 1895 |
ClassDef:1( |
| 1896 |
Foo |
| 1897 |
Keywords(metaclass=NameExpr(Bar)) |
| 1898 |
Metaclass(NameExpr(Bar)) |
| 1899 |
PassStmt:1())) |
| 1900 |
|
| 1901 |
[case testClassWithKeywordArgs] |
| 1902 |
class Foo(_root=None, total=False): pass |
| 1903 |
[out] |
| 1904 |
MypyFile:1( |
| 1905 |
ClassDef:1( |
| 1906 |
Foo |
| 1907 |
Keywords(_root=NameExpr(None), total=NameExpr(False)) |
| 1908 |
PassStmt:1())) |
| 1909 |
|
| 1910 |
[case testClassDecorator] |
| 1911 |
@foo |
| 1912 |
class X: pass |
| 1913 |
@foo(bar) |
| 1914 |
@x.y |
| 1915 |
class Z: pass |
| 1916 |
[out] |
| 1917 |
MypyFile:1( |
| 1918 |
ClassDef:2( |
| 1919 |
X |
| 1920 |
Decorators( |
| 1921 |
NameExpr(foo)) |
| 1922 |
PassStmt:2()) |
| 1923 |
ClassDef:5( |
| 1924 |
Z |
| 1925 |
Decorators( |
| 1926 |
CallExpr:3( |
| 1927 |
NameExpr(foo) |
| 1928 |
Args( |
| 1929 |
NameExpr(bar))) |
| 1930 |
MemberExpr:4( |
| 1931 |
NameExpr(x) |
| 1932 |
y)) |
| 1933 |
PassStmt:5())) |
| 1934 |
|
| 1935 |
[case testLiteralStringType] |
| 1936 |
from typing import Literal |
| 1937 |
x: Literal["hello"] |
| 1938 |
[out] |
| 1939 |
MypyFile:1( |
| 1940 |
ImportFrom:1(typing, [Literal]) |
| 1941 |
AssignmentStmt:2( |
| 1942 |
NameExpr(x) |
| 1943 |
TempNode:2( |
| 1944 |
Any) |
| 1945 |
Literal?[hello?])) |
| 1946 |
|
| 1947 |
[case testLiteralStringWithEscapes] |
| 1948 |
from typing import Literal |
| 1949 |
x: Literal["hello\nworld"] |
| 1950 |
[out] |
| 1951 |
MypyFile:1( |
| 1952 |
ImportFrom:1(typing, [Literal]) |
| 1953 |
AssignmentStmt:2( |
| 1954 |
NameExpr(x) |
| 1955 |
TempNode:2( |
| 1956 |
Any) |
| 1957 |
Literal?['hello\nworld'])) |
| 1958 |
|
| 1959 |
[case testForwardReference] |
| 1960 |
x: "int" |
| 1961 |
[out] |
| 1962 |
MypyFile:1( |
| 1963 |
AssignmentStmt:1( |
| 1964 |
NameExpr(x) |
| 1965 |
TempNode:1( |
| 1966 |
Any) |
| 1967 |
int?)) |
| 1968 |
|
| 1969 |
[case testForwardReferenceWithUnion] |
| 1970 |
x: "int | str" |
| 1971 |
[out] |
| 1972 |
MypyFile:1( |
| 1973 |
AssignmentStmt:1( |
| 1974 |
NameExpr(x) |
| 1975 |
TempNode:1( |
| 1976 |
Any) |
| 1977 |
int? | str?)) |
| 1978 |
|
| 1979 |
[case testForwardReferenceWithComplexType] |
| 1980 |
x: "list[int]" |
| 1981 |
[out] |
| 1982 |
MypyFile:1( |
| 1983 |
AssignmentStmt:1( |
| 1984 |
NameExpr(x) |
| 1985 |
TempNode:1( |
| 1986 |
Any) |
| 1987 |
list?[int?])) |
| 1988 |
|
| 1989 |
[case testMultipleLiteralStrings] |
| 1990 |
from typing import Literal |
| 1991 |
x: Literal["a", "b", "c"] |
| 1992 |
[out] |
| 1993 |
MypyFile:1( |
| 1994 |
ImportFrom:1(typing, [Literal]) |
| 1995 |
AssignmentStmt:2( |
| 1996 |
NameExpr(x) |
| 1997 |
TempNode:2( |
| 1998 |
Any) |
| 1999 |
Literal?[a?, b?, c?])) |
| 2000 |
|
| 2001 |
[case testLiteralBytesType] |
| 2002 |
from typing import Literal |
| 2003 |
x: Literal[b"foo"] |
| 2004 |
y: Literal[b"hello\nworld", b"\x00\xff"] |
| 2005 |
[out] |
| 2006 |
MypyFile:1( |
| 2007 |
ImportFrom:1(typing, [Literal]) |
| 2008 |
AssignmentStmt:2( |
| 2009 |
NameExpr(x) |
| 2010 |
TempNode:2( |
| 2011 |
Any) |
| 2012 |
Literal?[b'foo']) |
| 2013 |
AssignmentStmt:3( |
| 2014 |
NameExpr(y) |
| 2015 |
TempNode:3( |
| 2016 |
Any) |
| 2017 |
Literal?[b'hello\nworld', b'\x00\xff'])) |
| 2018 |
|
| 2019 |
[case testStripFunctionBodiesIfIgnoringErrors] |
| 2020 |
# mypy: ignore-errors=True |
| 2021 |
def f(self): |
| 2022 |
self.x = 1 # Cannot define an attribute |
| 2023 |
return 1 |
| 2024 |
[out] |
| 2025 |
MypyFile:1( |
| 2026 |
FuncDef:2( |
| 2027 |
f |
| 2028 |
Args( |
| 2029 |
Var(self)) |
| 2030 |
Block:3())) |
| 2031 |
|
| 2032 |
[case testStripMethodBodiesIfIgnoringErrors] |
| 2033 |
# mypy: ignore-errors=True |
| 2034 |
class C: |
| 2035 |
def f(self): |
| 2036 |
x = self.x |
| 2037 |
for x in y: |
| 2038 |
pass |
| 2039 |
with a as y: |
| 2040 |
pass |
| 2041 |
while self.foo(): |
| 2042 |
self.bah() |
| 2043 |
a[self.x] = 1 |
| 2044 |
[out] |
| 2045 |
MypyFile:1( |
| 2046 |
ClassDef:2( |
| 2047 |
C |
| 2048 |
FuncDef:3( |
| 2049 |
f |
| 2050 |
Args( |
| 2051 |
Var(self)) |
| 2052 |
Block:4()))) |
| 2053 |
|
| 2054 |
[case testDoNotStripModuleTopLevelOrClassBody] |
| 2055 |
# mypy: ignore-errors=True |
| 2056 |
f() |
| 2057 |
class C: |
| 2058 |
x = 5 |
| 2059 |
[out] |
| 2060 |
MypyFile:1( |
| 2061 |
ExpressionStmt:2( |
| 2062 |
CallExpr:2( |
| 2063 |
NameExpr(f) |
| 2064 |
Args())) |
| 2065 |
ClassDef:3( |
| 2066 |
C |
| 2067 |
AssignmentStmt:4( |
| 2068 |
NameExpr(x) |
| 2069 |
IntExpr(5)))) |
| 2070 |
|
| 2071 |
[case testDoNotStripMethodThatAssignsToAttribute] |
| 2072 |
# mypy: ignore-errors=True |
| 2073 |
class C: |
| 2074 |
def m1(self): |
| 2075 |
self.x = 0 |
| 2076 |
def m2(self): |
| 2077 |
a, self.y = 0 |
| 2078 |
[out] |
| 2079 |
MypyFile:1( |
| 2080 |
ClassDef:2( |
| 2081 |
C |
| 2082 |
FuncDef:3( |
| 2083 |
m1 |
| 2084 |
Args( |
| 2085 |
Var(self)) |
| 2086 |
Block:4( |
| 2087 |
AssignmentStmt:4( |
| 2088 |
MemberExpr:4( |
| 2089 |
NameExpr(self) |
| 2090 |
x) |
| 2091 |
IntExpr(0)))) |
| 2092 |
FuncDef:5( |
| 2093 |
m2 |
| 2094 |
Args( |
| 2095 |
Var(self)) |
| 2096 |
Block:6( |
| 2097 |
AssignmentStmt:6( |
| 2098 |
TupleExpr:6( |
| 2099 |
NameExpr(a) |
| 2100 |
MemberExpr:6( |
| 2101 |
NameExpr(self) |
| 2102 |
y)) |
| 2103 |
IntExpr(0)))))) |
| 2104 |
|
| 2105 |
[case testDoNotStripMethodThatAssignsToAttributeWithinStatement] |
| 2106 |
# mypy: ignore-errors=True |
| 2107 |
class C: |
| 2108 |
def m1(self): |
| 2109 |
for x in y: |
| 2110 |
self.x = 0 |
| 2111 |
def m2(self): |
| 2112 |
with x: |
| 2113 |
self.y = 0 |
| 2114 |
def m3(self): |
| 2115 |
if x: |
| 2116 |
self.y = 0 |
| 2117 |
else: |
| 2118 |
x = 4 |
| 2119 |
[out] |
| 2120 |
MypyFile:1( |
| 2121 |
ClassDef:2( |
| 2122 |
C |
| 2123 |
FuncDef:3( |
| 2124 |
m1 |
| 2125 |
Args( |
| 2126 |
Var(self)) |
| 2127 |
Block:4( |
| 2128 |
ForStmt:4( |
| 2129 |
NameExpr(x) |
| 2130 |
NameExpr(y) |
| 2131 |
Block:5( |
| 2132 |
AssignmentStmt:5( |
| 2133 |
MemberExpr:5( |
| 2134 |
NameExpr(self) |
| 2135 |
x) |
| 2136 |
IntExpr(0)))))) |
| 2137 |
FuncDef:6( |
| 2138 |
m2 |
| 2139 |
Args( |
| 2140 |
Var(self)) |
| 2141 |
Block:7( |
| 2142 |
WithStmt:7( |
| 2143 |
Expr( |
| 2144 |
NameExpr(x)) |
| 2145 |
Block:8( |
| 2146 |
AssignmentStmt:8( |
| 2147 |
MemberExpr:8( |
| 2148 |
NameExpr(self) |
| 2149 |
y) |
| 2150 |
IntExpr(0)))))) |
| 2151 |
FuncDef:9( |
| 2152 |
m3 |
| 2153 |
Args( |
| 2154 |
Var(self)) |
| 2155 |
Block:10( |
| 2156 |
IfStmt:10( |
| 2157 |
If( |
| 2158 |
NameExpr(x)) |
| 2159 |
Then( |
| 2160 |
AssignmentStmt:11( |
| 2161 |
MemberExpr:11( |
| 2162 |
NameExpr(self) |
| 2163 |
y) |
| 2164 |
IntExpr(0))) |
| 2165 |
Else( |
| 2166 |
AssignmentStmt:13( |
| 2167 |
NameExpr(x) |
| 2168 |
IntExpr(4)))))))) |
| 2169 |
|
| 2170 |
[case testDoNotStripMethodThatDefinesAttributeWithoutAssignment] |
| 2171 |
# mypy: ignore-errors=True |
| 2172 |
class C: |
| 2173 |
def m1(self): |
| 2174 |
with y as self.x: |
| 2175 |
pass |
| 2176 |
def m2(self): |
| 2177 |
for self.y in x: |
| 2178 |
pass |
| 2179 |
[out] |
| 2180 |
MypyFile:1( |
| 2181 |
ClassDef:2( |
| 2182 |
C |
| 2183 |
FuncDef:3( |
| 2184 |
m1 |
| 2185 |
Args( |
| 2186 |
Var(self)) |
| 2187 |
Block:4( |
| 2188 |
WithStmt:4( |
| 2189 |
Expr( |
| 2190 |
NameExpr(y)) |
| 2191 |
Target( |
| 2192 |
MemberExpr:4( |
| 2193 |
NameExpr(self) |
| 2194 |
x)) |
| 2195 |
Block:5( |
| 2196 |
PassStmt:5())))) |
| 2197 |
FuncDef:6( |
| 2198 |
m2 |
| 2199 |
Args( |
| 2200 |
Var(self)) |
| 2201 |
Block:7( |
| 2202 |
ForStmt:7( |
| 2203 |
MemberExpr:7( |
| 2204 |
NameExpr(self) |
| 2205 |
y) |
| 2206 |
NameExpr(x) |
| 2207 |
Block:8( |
| 2208 |
PassStmt:8())))))) |
| 2209 |
|
| 2210 |
[case testStripDecoratedFunctionOrMethod] |
| 2211 |
# mypy: ignore-errors=True |
| 2212 |
@deco |
| 2213 |
def f(): |
| 2214 |
x = 0 |
| 2215 |
|
| 2216 |
class C: |
| 2217 |
@deco |
| 2218 |
def m1(self): |
| 2219 |
x = 0 |
| 2220 |
|
| 2221 |
@deco |
| 2222 |
def m2(self): |
| 2223 |
self.x = 0 |
| 2224 |
[out] |
| 2225 |
MypyFile:1( |
| 2226 |
Decorator:2( |
| 2227 |
Var(f) |
| 2228 |
NameExpr(deco) |
| 2229 |
FuncDef:3( |
| 2230 |
f |
| 2231 |
Block:4())) |
| 2232 |
ClassDef:6( |
| 2233 |
C |
| 2234 |
Decorator:7( |
| 2235 |
Var(m1) |
| 2236 |
NameExpr(deco) |
| 2237 |
FuncDef:8( |
| 2238 |
m1 |
| 2239 |
Args( |
| 2240 |
Var(self)) |
| 2241 |
Block:9())) |
| 2242 |
Decorator:11( |
| 2243 |
Var(m2) |
| 2244 |
NameExpr(deco) |
| 2245 |
FuncDef:12( |
| 2246 |
m2 |
| 2247 |
Args( |
| 2248 |
Var(self)) |
| 2249 |
Block:13( |
| 2250 |
AssignmentStmt:13( |
| 2251 |
MemberExpr:13( |
| 2252 |
NameExpr(self) |
| 2253 |
x) |
| 2254 |
IntExpr(0))))))) |
| 2255 |
|
| 2256 |
[case testStripOverloadedMethod] |
| 2257 |
# mypy: ignore-errors=True |
| 2258 |
class C: |
| 2259 |
@overload |
| 2260 |
def m1(self, x: int) -> None: ... |
| 2261 |
@overload |
| 2262 |
def m1(self, x: str) -> None: ... |
| 2263 |
def m1(self, x): |
| 2264 |
x = 0 |
| 2265 |
|
| 2266 |
@overload |
| 2267 |
def m2(self, x: int) -> None: ... |
| 2268 |
@overload |
| 2269 |
def m2(self, x: str) -> None: ... |
| 2270 |
def m2(self, x): |
| 2271 |
self.x = 0 |
| 2272 |
[out] |
| 2273 |
MypyFile:1( |
| 2274 |
ClassDef:2( |
| 2275 |
C |
| 2276 |
OverloadedFuncDef:3( |
| 2277 |
Decorator:3( |
| 2278 |
Var(m1) |
| 2279 |
NameExpr(overload) |
| 2280 |
FuncDef:4( |
| 2281 |
m1 |
| 2282 |
Args( |
| 2283 |
Var(self) |
| 2284 |
Var(x)) |
| 2285 |
def (self: Any, x: int?) -> None? |
| 2286 |
Block:4( |
| 2287 |
ExpressionStmt:4( |
| 2288 |
Ellipsis)))) |
| 2289 |
Decorator:5( |
| 2290 |
Var(m1) |
| 2291 |
NameExpr(overload) |
| 2292 |
FuncDef:6( |
| 2293 |
m1 |
| 2294 |
Args( |
| 2295 |
Var(self) |
| 2296 |
Var(x)) |
| 2297 |
def (self: Any, x: str?) -> None? |
| 2298 |
Block:6( |
| 2299 |
ExpressionStmt:6( |
| 2300 |
Ellipsis)))) |
| 2301 |
FuncDef:7( |
| 2302 |
m1 |
| 2303 |
Args( |
| 2304 |
Var(self) |
| 2305 |
Var(x)) |
| 2306 |
Block:8())) |
| 2307 |
OverloadedFuncDef:10( |
| 2308 |
Decorator:10( |
| 2309 |
Var(m2) |
| 2310 |
NameExpr(overload) |
| 2311 |
FuncDef:11( |
| 2312 |
m2 |
| 2313 |
Args( |
| 2314 |
Var(self) |
| 2315 |
Var(x)) |
| 2316 |
def (self: Any, x: int?) -> None? |
| 2317 |
Block:11( |
| 2318 |
ExpressionStmt:11( |
| 2319 |
Ellipsis)))) |
| 2320 |
Decorator:12( |
| 2321 |
Var(m2) |
| 2322 |
NameExpr(overload) |
| 2323 |
FuncDef:13( |
| 2324 |
m2 |
| 2325 |
Args( |
| 2326 |
Var(self) |
| 2327 |
Var(x)) |
| 2328 |
def (self: Any, x: str?) -> None? |
| 2329 |
Block:13( |
| 2330 |
ExpressionStmt:13( |
| 2331 |
Ellipsis)))) |
| 2332 |
FuncDef:14( |
| 2333 |
m2 |
| 2334 |
Args( |
| 2335 |
Var(self) |
| 2336 |
Var(x)) |
| 2337 |
Block:15( |
| 2338 |
AssignmentStmt:15( |
| 2339 |
MemberExpr:15( |
| 2340 |
NameExpr(self) |
| 2341 |
x) |
| 2342 |
IntExpr(0))))))) |
| 2343 |
|
| 2344 |
[case testStripMethodInNestedClass] |
| 2345 |
# mypy: ignore-errors=True |
| 2346 |
class C: |
| 2347 |
class D: |
| 2348 |
def m1(self): |
| 2349 |
self.x = 1 |
| 2350 |
def m2(self): |
| 2351 |
return self.x |
| 2352 |
[out] |
| 2353 |
MypyFile:1( |
| 2354 |
ClassDef:2( |
| 2355 |
C |
| 2356 |
ClassDef:3( |
| 2357 |
D |
| 2358 |
FuncDef:4( |
| 2359 |
m1 |
| 2360 |
Args( |
| 2361 |
Var(self)) |
| 2362 |
Block:5( |
| 2363 |
AssignmentStmt:5( |
| 2364 |
MemberExpr:5( |
| 2365 |
NameExpr(self) |
| 2366 |
x) |
| 2367 |
IntExpr(1)))) |
| 2368 |
FuncDef:6( |
| 2369 |
m2 |
| 2370 |
Args( |
| 2371 |
Var(self)) |
| 2372 |
Block:7())))) |
| 2373 |
|
| 2374 |
[case testSuperExpr] |
| 2375 |
super().x |
| 2376 |
[out] |
| 2377 |
MypyFile:1( |
| 2378 |
ExpressionStmt:1( |
| 2379 |
SuperExpr:1( |
| 2380 |
x |
| 2381 |
CallExpr:1( |
| 2382 |
NameExpr(super) |
| 2383 |
Args())))) |
| 2384 |
|
| 2385 |
[case testTypeCommentSimple] |
| 2386 |
x = [] # type: list[int] |
| 2387 |
[out] |
| 2388 |
MypyFile:1( |
| 2389 |
AssignmentStmt:1( |
| 2390 |
NameExpr(x) |
| 2391 |
ListExpr:1() |
| 2392 |
list?[int?])) |
| 2393 |
|
| 2394 |
[case testTypeCommentMultiple] |
| 2395 |
x = [] # type: list[int] |
| 2396 |
y = {} # type: dict[str, int] |
| 2397 |
[out] |
| 2398 |
MypyFile:1( |
| 2399 |
AssignmentStmt:1( |
| 2400 |
NameExpr(x) |
| 2401 |
ListExpr:1() |
| 2402 |
list?[int?]) |
| 2403 |
AssignmentStmt:2( |
| 2404 |
NameExpr(y) |
| 2405 |
DictExpr:2() |
| 2406 |
dict?[str?, int?])) |
| 2407 |
|
| 2408 |
[case testTypeCommentWithTrailingComment] |
| 2409 |
x = [] # type: list[str] # This is a comment |
| 2410 |
[out] |
| 2411 |
MypyFile:1( |
| 2412 |
AssignmentStmt:1( |
| 2413 |
NameExpr(x) |
| 2414 |
ListExpr:1() |
| 2415 |
list?[str?])) |
| 2416 |
|
| 2417 |
[case testTypeCommentUnion] |
| 2418 |
x = None # type: str | None |
| 2419 |
[out] |
| 2420 |
MypyFile:1( |
| 2421 |
AssignmentStmt:1( |
| 2422 |
NameExpr(x) |
| 2423 |
NameExpr(None) |
| 2424 |
str? | None?)) |
| 2425 |
|
| 2426 |
[case testNestedListAssignment] |
| 2427 |
a1, [b1, c1] = a2, [b2, c2] |
| 2428 |
[out] |
| 2429 |
MypyFile:1( |
| 2430 |
AssignmentStmt:1( |
| 2431 |
TupleExpr:1( |
| 2432 |
NameExpr(a1) |
| 2433 |
TupleExpr:1( |
| 2434 |
NameExpr(b1) |
| 2435 |
NameExpr(c1))) |
| 2436 |
TupleExpr:1( |
| 2437 |
NameExpr(a2) |
| 2438 |
ListExpr:1( |
| 2439 |
NameExpr(b2) |
| 2440 |
NameExpr(c2))))) |
| 2441 |
|
| 2442 |
[case testSyntaxError1] |
| 2443 |
x = [1 2] |
| 2444 |
y = 2 |
| 2445 |
[out] |
| 2446 |
1:8: error: Expected `,`, found int |
| 2447 |
MypyFile:1( |
| 2448 |
AssignmentStmt:1( |
| 2449 |
NameExpr(x) |
| 2450 |
ListExpr:1( |
| 2451 |
IntExpr(1) |
| 2452 |
IntExpr(2))) |
| 2453 |
AssignmentStmt:2( |
| 2454 |
NameExpr(y) |
| 2455 |
IntExpr(2))) |
| 2456 |
|
| 2457 |
[case testSyntaxError2] |
| 2458 |
f(a.) |
| 2459 |
[out] |
| 2460 |
1:5: error: Expected an identifier |
| 2461 |
MypyFile:1( |
| 2462 |
ExpressionStmt:1( |
| 2463 |
CallExpr:1( |
| 2464 |
NameExpr(f) |
| 2465 |
Args( |
| 2466 |
MemberExpr:1( |
| 2467 |
NameExpr(a) |
| 2468 |
))))) |
| 2469 |
|
| 2470 |
[case testSyntaxError3] |
| 2471 |
f(a[]) |
| 2472 |
[out] |
| 2473 |
1:5: error: Expected index or slice expression |
| 2474 |
MypyFile:1( |
| 2475 |
ExpressionStmt:1( |
| 2476 |
CallExpr:1( |
| 2477 |
NameExpr(f) |
| 2478 |
Args( |
| 2479 |
IndexExpr:1( |
| 2480 |
NameExpr(a) |
| 2481 |
NameExpr()))))) |
| 2482 |
|
| 2483 |
[case testSyntaxError4] |
| 2484 |
from m import |
| 2485 |
1 |
| 2486 |
[out] |
| 2487 |
1:14: error: Expected one or more symbol names after import |
| 2488 |
MypyFile:1( |
| 2489 |
ImportFrom:1(m, []) |
| 2490 |
ExpressionStmt:2( |
| 2491 |
IntExpr(1))) |
| 2492 |
|
| 2493 |
[case testSyntaxError5] |
| 2494 |
from m |
| 2495 |
1 |
| 2496 |
[out] |
| 2497 |
1:7: error: Expected `import`, found newline |
| 2498 |
MypyFile:1( |
| 2499 |
ImportFrom:1(m, []) |
| 2500 |
ExpressionStmt:2( |
| 2501 |
IntExpr(1))) |
| 2502 |
|
| 2503 |
[case testSyntaxError6] |
| 2504 |
from m |
| 2505 |
1 |
| 2506 |
[out] |
| 2507 |
1:7: error: Expected `import`, found newline |
| 2508 |
MypyFile:1( |
| 2509 |
ImportFrom:1(m, []) |
| 2510 |
ExpressionStmt:2( |
| 2511 |
IntExpr(1))) |
| 2512 |
|
| 2513 |
[case testSyntaxError7] |
| 2514 |
def f(): |
| 2515 |
g( |
| 2516 |
h() |
| 2517 |
|
| 2518 |
def g(): ... |
| 2519 |
[out] |
| 2520 |
3:8: error: Expected `)`, found newline |
| 2521 |
MypyFile:1( |
| 2522 |
FuncDef:1( |
| 2523 |
f |
| 2524 |
Block:2( |
| 2525 |
ExpressionStmt:2( |
| 2526 |
CallExpr:2( |
| 2527 |
NameExpr(g) |
| 2528 |
Args( |
| 2529 |
CallExpr:3( |
| 2530 |
NameExpr(h) |
| 2531 |
Args())))))) |
| 2532 |
FuncDef:5( |
| 2533 |
g |
| 2534 |
Block:5( |
| 2535 |
ExpressionStmt:5( |
| 2536 |
Ellipsis)))) |
| 2537 |
|
| 2538 |
[case testSyntaxError8] |
| 2539 |
def f( |
| 2540 |
x, |
| 2541 |
y |
| 2542 |
|
| 2543 |
def g(): ... |
| 2544 |
[out] |
| 2545 |
3:6: error: Expected `)`, found newline |
| 2546 |
5:1: error: Expected an indented block after function definition |
| 2547 |
MypyFile:1( |
| 2548 |
FuncDef:1( |
| 2549 |
f |
| 2550 |
Args( |
| 2551 |
Var(x) |
| 2552 |
Var(y)) |
| 2553 |
Block:1()) |
| 2554 |
FuncDef:5( |
| 2555 |
g |
| 2556 |
Block:5( |
| 2557 |
ExpressionStmt:5( |
| 2558 |
Ellipsis)))) |
| 2559 |
|
| 2560 |
[case testSyntaxError9] |
| 2561 |
class A |
| 2562 |
|
| 2563 |
def f(): pass |
| 2564 |
[out] |
| 2565 |
1:8: error: Expected `:`, found newline |
| 2566 |
3:1: error: Expected an indented block after `class` definition |
| 2567 |
MypyFile:1( |
| 2568 |
ClassDef:1( |
| 2569 |
A) |
| 2570 |
FuncDef:3( |
| 2571 |
f |
| 2572 |
Block:3( |
| 2573 |
PassStmt:3()))) |
| 2574 |
|
| 2575 |
[case testArgConstructorTooManyArgs] |
| 2576 |
from typing import Callable |
| 2577 |
from mypy_extensions import Arg |
| 2578 |
def f(x: Callable[[Arg(int, 'x', 'extra')], bool]) -> None: |
| 2579 |
pass |
| 2580 |
[out] |
| 2581 |
3:19: error: Too many arguments for argument constructor |
| 2582 |
MypyFile:1( |
| 2583 |
ImportFrom:1(typing, [Callable]) |
| 2584 |
ImportFrom:2(mypy_extensions, [Arg]) |
| 2585 |
FuncDef:3( |
| 2586 |
f |
| 2587 |
Args( |
| 2588 |
Var(x)) |
| 2589 |
def (x: Callable?[<TypeList Arg(int?, x)>, bool?]) -> None? |
| 2590 |
Block:4( |
| 2591 |
PassStmt:4()))) |
| 2592 |
|
| 2593 |
[case testArgConstructorMultipleValuesForName] |
| 2594 |
from typing import Callable |
| 2595 |
from mypy_extensions import Arg |
| 2596 |
def f(x: Callable[[Arg(int, 'x', name='y')], bool]) -> None: |
| 2597 |
pass |
| 2598 |
[out] |
| 2599 |
3:19: error: "Arg" gets multiple values for keyword argument "name" |
| 2600 |
MypyFile:1( |
| 2601 |
ImportFrom:1(typing, [Callable]) |
| 2602 |
ImportFrom:2(mypy_extensions, [Arg]) |
| 2603 |
FuncDef:3( |
| 2604 |
f |
| 2605 |
Args( |
| 2606 |
Var(x)) |
| 2607 |
def (x: Callable?[<TypeList Arg(int?, y)>, bool?]) -> None? |
| 2608 |
Block:4( |
| 2609 |
PassStmt:4()))) |
| 2610 |
|
| 2611 |
[case testArgConstructorMultipleValuesForType] |
| 2612 |
from typing import Callable |
| 2613 |
from mypy_extensions import Arg |
| 2614 |
def f(x: Callable[[Arg(int, type=str)], bool]) -> None: |
| 2615 |
pass |
| 2616 |
[out] |
| 2617 |
3:19: error: "Arg" gets multiple values for keyword argument "type" |
| 2618 |
MypyFile:1( |
| 2619 |
ImportFrom:1(typing, [Callable]) |
| 2620 |
ImportFrom:2(mypy_extensions, [Arg]) |
| 2621 |
FuncDef:3( |
| 2622 |
f |
| 2623 |
Args( |
| 2624 |
Var(x)) |
| 2625 |
def (x: Callable?[<TypeList Arg(str?)>, bool?]) -> None? |
| 2626 |
Block:4( |
| 2627 |
PassStmt:4()))) |
| 2628 |
|
| 2629 |
[case testArgConstructorUnexpectedArg] |
| 2630 |
from typing import Callable |
| 2631 |
from mypy_extensions import Arg |
| 2632 |
def f(x: Callable[[Arg(int, foo='bar')], bool]) -> None: |
| 2633 |
pass |
| 2634 |
[out] |
| 2635 |
3:19: error: Unexpected argument "foo" for argument constructor |
| 2636 |
MypyFile:1( |
| 2637 |
ImportFrom:1(typing, [Callable]) |
| 2638 |
ImportFrom:2(mypy_extensions, [Arg]) |
| 2639 |
FuncDef:3( |
| 2640 |
f |
| 2641 |
Args( |
| 2642 |
Var(x)) |
| 2643 |
def (x: Callable?[<TypeList Arg(int?)>, bool?]) -> None? |
| 2644 |
Block:4( |
| 2645 |
PassStmt:4()))) |
| 2646 |
|
| 2647 |
[case testArgConstructorMultipleErrors] |
| 2648 |
from typing import Callable |
| 2649 |
from mypy_extensions import Arg |
| 2650 |
def f(x: Callable[[Arg(int, 'x', 'extra', foo='bar', name='y')], bool]) -> None: |
| 2651 |
pass |
| 2652 |
[out] |
| 2653 |
3:19: error: Too many arguments for argument constructor |
| 2654 |
3:19: error: Unexpected argument "foo" for argument constructor |
| 2655 |
3:19: error: "Arg" gets multiple values for keyword argument "name" |
| 2656 |
MypyFile:1( |
| 2657 |
ImportFrom:1(typing, [Callable]) |
| 2658 |
ImportFrom:2(mypy_extensions, [Arg]) |
| 2659 |
FuncDef:3( |
| 2660 |
f |
| 2661 |
Args( |
| 2662 |
Var(x)) |
| 2663 |
def (x: Callable?[<TypeList Arg(int?, y)>, bool?]) -> None? |
| 2664 |
Block:4( |
| 2665 |
PassStmt:4()))) |
| 2666 |
|
| 2667 |
[case testArgConstructorValidSyntax] |
| 2668 |
from typing import Callable |
| 2669 |
from mypy_extensions import Arg, DefaultArg, VarArg, KwArg |
| 2670 |
def f(x: Callable[[Arg(int, 'x'), DefaultArg(str, 'y'), VarArg(bool), KwArg(float)], None]) -> None: |
| 2671 |
pass |
| 2672 |
[out] |
| 2673 |
MypyFile:1( |
| 2674 |
ImportFrom:1(typing, [Callable]) |
| 2675 |
ImportFrom:2(mypy_extensions, [Arg, DefaultArg, VarArg, KwArg]) |
| 2676 |
FuncDef:3( |
| 2677 |
f |
| 2678 |
Args( |
| 2679 |
Var(x)) |
| 2680 |
def (x: Callable?[<TypeList Arg(int?, x), DefaultArg(str?, y), VarArg(bool?), KwArg(float?)>, None?]) -> None? |
| 2681 |
Block:4( |
| 2682 |
PassStmt:4()))) |
| 2683 |
[case testInvalidTypeFloatLiteral] |
| 2684 |
x: 3.14 |
| 2685 |
[out] |
| 2686 |
MypyFile:1( |
| 2687 |
AssignmentStmt:1( |
| 2688 |
NameExpr(x) |
| 2689 |
TempNode:1( |
| 2690 |
Any) |
| 2691 |
None)) |
| 2692 |
|
| 2693 |
[case testInvalidTypeComplexLiteral] |
| 2694 |
y: 1j |
| 2695 |
[out] |
| 2696 |
MypyFile:1( |
| 2697 |
AssignmentStmt:1( |
| 2698 |
NameExpr(y) |
| 2699 |
TempNode:1( |
| 2700 |
Any) |
| 2701 |
None)) |
| 2702 |
|
| 2703 |
[case testInvalidTypeBinaryOperatorAdd] |
| 2704 |
z: int + str |
| 2705 |
[out] |
| 2706 |
MypyFile:1( |
| 2707 |
AssignmentStmt:1( |
| 2708 |
NameExpr(z) |
| 2709 |
TempNode:1( |
| 2710 |
Any) |
| 2711 |
None)) |
| 2712 |
|
| 2713 |
[case testInvalidTypeBinaryOperatorMul] |
| 2714 |
a: int * str |
| 2715 |
[out] |
| 2716 |
MypyFile:1( |
| 2717 |
AssignmentStmt:1( |
| 2718 |
NameExpr(a) |
| 2719 |
TempNode:1( |
| 2720 |
Any) |
| 2721 |
None)) |
| 2722 |
|
| 2723 |
[case testInvalidTypeUnaryOperatorNot] |
| 2724 |
b: not int |
| 2725 |
[out] |
| 2726 |
MypyFile:1( |
| 2727 |
AssignmentStmt:1( |
| 2728 |
NameExpr(b) |
| 2729 |
TempNode:1( |
| 2730 |
Any) |
| 2731 |
None)) |
| 2732 |
|
| 2733 |
[case testInvalidTypeUnaryOperatorInvert] |
| 2734 |
c: ~int |
| 2735 |
[out] |
| 2736 |
MypyFile:1( |
| 2737 |
AssignmentStmt:1( |
| 2738 |
NameExpr(c) |
| 2739 |
TempNode:1( |
| 2740 |
Any) |
| 2741 |
None)) |
| 2742 |
|
| 2743 |
[case testInvalidTypeSetExpression] |
| 2744 |
f: {1, 2, 3} |
| 2745 |
[out] |
| 2746 |
MypyFile:1( |
| 2747 |
AssignmentStmt:1( |
| 2748 |
NameExpr(f) |
| 2749 |
TempNode:1( |
| 2750 |
Any) |
| 2751 |
None)) |
| 2752 |
|
| 2753 |
[case testInvalidTypeListComprehension] |
| 2754 |
g: [x for x in range(10)] |
| 2755 |
[out] |
| 2756 |
MypyFile:1( |
| 2757 |
AssignmentStmt:1( |
| 2758 |
NameExpr(g) |
| 2759 |
TempNode:1( |
| 2760 |
Any) |
| 2761 |
None)) |
| 2762 |
|
| 2763 |
[case testInvalidTypeLambda] |
| 2764 |
h: lambda x: x |
| 2765 |
[out] |
| 2766 |
MypyFile:1( |
| 2767 |
AssignmentStmt:1( |
| 2768 |
NameExpr(h) |
| 2769 |
TempNode:1( |
| 2770 |
Any) |
| 2771 |
None)) |
| 2772 |
|
| 2773 |
[case testInvalidTypeIfExpression] |
| 2774 |
i: int if True else str |
| 2775 |
[out] |
| 2776 |
MypyFile:1( |
| 2777 |
AssignmentStmt:1( |
| 2778 |
NameExpr(i) |
| 2779 |
TempNode:1( |
| 2780 |
Any) |
| 2781 |
None)) |
| 2782 |
|
| 2783 |
[case testInvalidTypeComparisonExpression] |
| 2784 |
j: int < str |
| 2785 |
[out] |
| 2786 |
MypyFile:1( |
| 2787 |
AssignmentStmt:1( |
| 2788 |
NameExpr(j) |
| 2789 |
TempNode:1( |
| 2790 |
Any) |
| 2791 |
None)) |
| 2792 |
|
| 2793 |
[case testInvalidTypePositiveUnaryOp] |
| 2794 |
k: +5 |
| 2795 |
[out] |
| 2796 |
MypyFile:1( |
| 2797 |
AssignmentStmt:1( |
| 2798 |
NameExpr(k) |
| 2799 |
TempNode:1( |
| 2800 |
Any) |
| 2801 |
5)) |
| 2802 |
|
| 2803 |
[case testConditionalOverload1] |
| 2804 |
@overload |
| 2805 |
def foo(x: int): ... |
| 2806 |
if sys.version_info[0] > 2: |
| 2807 |
@overload |
| 2808 |
def foo(x: str): ... |
| 2809 |
def foo(x): pass |
| 2810 |
[out] |
| 2811 |
MypyFile:1( |
| 2812 |
IfStmt:3( |
| 2813 |
If( |
| 2814 |
ComparisonExpr:3( |
| 2815 |
> |
| 2816 |
IndexExpr:3( |
| 2817 |
MemberExpr:3( |
| 2818 |
NameExpr(sys) |
| 2819 |
version_info) |
| 2820 |
IntExpr(0)) |
| 2821 |
IntExpr(2))) |
| 2822 |
Then() |
| 2823 |
Else()) |
| 2824 |
OverloadedFuncDef:1( |
| 2825 |
Decorator:1( |
| 2826 |
Var(foo) |
| 2827 |
NameExpr(overload) |
| 2828 |
FuncDef:2( |
| 2829 |
foo |
| 2830 |
Args( |
| 2831 |
Var(x)) |
| 2832 |
def (x: int?) -> Any |
| 2833 |
Block:2( |
| 2834 |
ExpressionStmt:2( |
| 2835 |
Ellipsis)))) |
| 2836 |
Decorator:4( |
| 2837 |
Var(foo) |
| 2838 |
NameExpr(overload) |
| 2839 |
FuncDef:5( |
| 2840 |
foo |
| 2841 |
Args( |
| 2842 |
Var(x)) |
| 2843 |
def (x: str?) -> Any |
| 2844 |
Block:5( |
| 2845 |
ExpressionStmt:5( |
| 2846 |
Ellipsis)))) |
| 2847 |
FuncDef:6( |
| 2848 |
foo |
| 2849 |
Args( |
| 2850 |
Var(x)) |
| 2851 |
Block:6( |
| 2852 |
PassStmt:6())))) |
| 2853 |
|
| 2854 |
[case testConditionalOverload2] |
| 2855 |
@overload |
| 2856 |
def foo(x: int): ... |
| 2857 |
if sys.platform == "foo": |
| 2858 |
@overload |
| 2859 |
def foo(x: str): ... |
| 2860 |
def foo(x): pass |
| 2861 |
[out] |
| 2862 |
MypyFile:1( |
| 2863 |
IfStmt:3( |
| 2864 |
If( |
| 2865 |
ComparisonExpr:3( |
| 2866 |
== |
| 2867 |
MemberExpr:3( |
| 2868 |
NameExpr(sys) |
| 2869 |
platform) |
| 2870 |
StrExpr(foo))) |
| 2871 |
Then()) |
| 2872 |
OverloadedFuncDef:1( |
| 2873 |
Decorator:1( |
| 2874 |
Var(foo) |
| 2875 |
NameExpr(overload) |
| 2876 |
FuncDef:2( |
| 2877 |
foo |
| 2878 |
Args( |
| 2879 |
Var(x)) |
| 2880 |
def (x: int?) -> Any |
| 2881 |
Block:2( |
| 2882 |
ExpressionStmt:2( |
| 2883 |
Ellipsis)))) |
| 2884 |
FuncDef:6( |
| 2885 |
foo |
| 2886 |
Args( |
| 2887 |
Var(x)) |
| 2888 |
Block:6( |
| 2889 |
PassStmt:6())))) |
| 2890 |
|
| 2891 |
[case testConditionalOverload3] |
| 2892 |
if sys.version_info[0] > 2: |
| 2893 |
@overload |
| 2894 |
def foo(x: str): ... |
| 2895 |
@overload |
| 2896 |
def foo(x: int): ... |
| 2897 |
def foo(x): pass |
| 2898 |
[out] |
| 2899 |
MypyFile:1( |
| 2900 |
IfStmt:1( |
| 2901 |
If( |
| 2902 |
ComparisonExpr:1( |
| 2903 |
> |
| 2904 |
IndexExpr:1( |
| 2905 |
MemberExpr:1( |
| 2906 |
NameExpr(sys) |
| 2907 |
version_info) |
| 2908 |
IntExpr(0)) |
| 2909 |
IntExpr(2))) |
| 2910 |
Then() |
| 2911 |
Else()) |
| 2912 |
OverloadedFuncDef:2( |
| 2913 |
Decorator:2( |
| 2914 |
Var(foo) |
| 2915 |
NameExpr(overload) |
| 2916 |
FuncDef:3( |
| 2917 |
foo |
| 2918 |
Args( |
| 2919 |
Var(x)) |
| 2920 |
def (x: str?) -> Any |
| 2921 |
Block:3( |
| 2922 |
ExpressionStmt:3( |
| 2923 |
Ellipsis)))) |
| 2924 |
Decorator:4( |
| 2925 |
Var(foo) |
| 2926 |
NameExpr(overload) |
| 2927 |
FuncDef:5( |
| 2928 |
foo |
| 2929 |
Args( |
| 2930 |
Var(x)) |
| 2931 |
def (x: int?) -> Any |
| 2932 |
Block:5( |
| 2933 |
ExpressionStmt:5( |
| 2934 |
Ellipsis)))) |
| 2935 |
FuncDef:6( |
| 2936 |
foo |
| 2937 |
Args( |
| 2938 |
Var(x)) |
| 2939 |
Block:6( |
| 2940 |
PassStmt:6())))) |
| 2941 |
|
| 2942 |
[case testMatchStmt] |
| 2943 |
match x: |
| 2944 |
case foo(y): |
| 2945 |
pass |
| 2946 |
case _: |
| 2947 |
pass |
| 2948 |
[out] |
| 2949 |
MypyFile:1( |
| 2950 |
MatchStmt:1( |
| 2951 |
NameExpr(x) |
| 2952 |
Pattern( |
| 2953 |
ClassPattern:2( |
| 2954 |
NameExpr(foo) |
| 2955 |
Positionals( |
| 2956 |
AsPattern:2( |
| 2957 |
NameExpr(y))))) |
| 2958 |
Body( |
| 2959 |
PassStmt:3()) |
| 2960 |
Pattern( |
| 2961 |
AsPattern:4()) |
| 2962 |
Body( |
| 2963 |
PassStmt:5()))) |
| 2964 |
|
| 2965 |
[case testMatchLiteralPatterns] |
| 2966 |
match x: |
| 2967 |
case 1: |
| 2968 |
pass |
| 2969 |
case "hello": |
| 2970 |
pass |
| 2971 |
case True: |
| 2972 |
pass |
| 2973 |
case None: |
| 2974 |
pass |
| 2975 |
[out] |
| 2976 |
MypyFile:1( |
| 2977 |
MatchStmt:1( |
| 2978 |
NameExpr(x) |
| 2979 |
Pattern( |
| 2980 |
ValuePattern:2( |
| 2981 |
IntExpr(1))) |
| 2982 |
Body( |
| 2983 |
PassStmt:3()) |
| 2984 |
Pattern( |
| 2985 |
ValuePattern:4( |
| 2986 |
StrExpr(hello))) |
| 2987 |
Body( |
| 2988 |
PassStmt:5()) |
| 2989 |
Pattern( |
| 2990 |
SingletonPattern:6( |
| 2991 |
True)) |
| 2992 |
Body( |
| 2993 |
PassStmt:7()) |
| 2994 |
Pattern( |
| 2995 |
SingletonPattern:8()) |
| 2996 |
Body( |
| 2997 |
PassStmt:9()))) |
| 2998 |
|
| 2999 |
[case testMatchOrPattern] |
| 3000 |
match x: |
| 3001 |
case 1 | 2 | 3: |
| 3002 |
pass |
| 3003 |
[out] |
| 3004 |
MypyFile:1( |
| 3005 |
MatchStmt:1( |
| 3006 |
NameExpr(x) |
| 3007 |
Pattern( |
| 3008 |
OrPattern:2( |
| 3009 |
ValuePattern:2( |
| 3010 |
IntExpr(1)) |
| 3011 |
ValuePattern:2( |
| 3012 |
IntExpr(2)) |
| 3013 |
ValuePattern:2( |
| 3014 |
IntExpr(3)))) |
| 3015 |
Body( |
| 3016 |
PassStmt:3()))) |
| 3017 |
|
| 3018 |
[case testMatchSequencePattern] |
| 3019 |
match x: |
| 3020 |
case [a, *rest, b]: |
| 3021 |
pass |
| 3022 |
[out] |
| 3023 |
MypyFile:1( |
| 3024 |
MatchStmt:1( |
| 3025 |
NameExpr(x) |
| 3026 |
Pattern( |
| 3027 |
SequencePattern:2( |
| 3028 |
AsPattern:2( |
| 3029 |
NameExpr(a)) |
| 3030 |
StarredPattern:2( |
| 3031 |
NameExpr(rest)) |
| 3032 |
AsPattern:2( |
| 3033 |
NameExpr(b)))) |
| 3034 |
Body( |
| 3035 |
PassStmt:3()))) |
| 3036 |
|
| 3037 |
[case testMatchMappingPattern] |
| 3038 |
match x: |
| 3039 |
case {"key": value, "x": y}: |
| 3040 |
pass |
| 3041 |
[out] |
| 3042 |
MypyFile:1( |
| 3043 |
MatchStmt:1( |
| 3044 |
NameExpr(x) |
| 3045 |
Pattern( |
| 3046 |
MappingPattern:2( |
| 3047 |
Key( |
| 3048 |
StrExpr(key)) |
| 3049 |
Value( |
| 3050 |
AsPattern:2( |
| 3051 |
NameExpr(value))) |
| 3052 |
Key( |
| 3053 |
StrExpr(x)) |
| 3054 |
Value( |
| 3055 |
AsPattern:2( |
| 3056 |
NameExpr(y))))) |
| 3057 |
Body( |
| 3058 |
PassStmt:3()))) |
| 3059 |
|
| 3060 |
[case testMatchGuard] |
| 3061 |
match x: |
| 3062 |
case y if y > 0: |
| 3063 |
pass |
| 3064 |
[out] |
| 3065 |
MypyFile:1( |
| 3066 |
MatchStmt:1( |
| 3067 |
NameExpr(x) |
| 3068 |
Pattern( |
| 3069 |
AsPattern:2( |
| 3070 |
NameExpr(y))) |
| 3071 |
Guard( |
| 3072 |
ComparisonExpr:2( |
| 3073 |
> |
| 3074 |
NameExpr(y) |
| 3075 |
IntExpr(0))) |
| 3076 |
Body( |
| 3077 |
PassStmt:3()))) |
| 3078 |
|
| 3079 |
[case testTypeCommentLastLine] |
| 3080 |
d = [ |
| 3081 |
# Placeholder for items |
| 3082 |
] # type: list[int] |
| 3083 |
[out] |
| 3084 |
MypyFile:1( |
| 3085 |
AssignmentStmt:1( |
| 3086 |
NameExpr(d) |
| 3087 |
ListExpr:1() |
| 3088 |
list?[int?])) |
| 3089 |
|
| 3090 |
[case testDebugFString] |
| 3091 |
f"test {x=}" |
| 3092 |
[out] |
| 3093 |
MypyFile:1( |
| 3094 |
ExpressionStmt:1( |
| 3095 |
CallExpr:1( |
| 3096 |
MemberExpr:1( |
| 3097 |
StrExpr() |
| 3098 |
join) |
| 3099 |
Args( |
| 3100 |
ListExpr:1( |
| 3101 |
StrExpr(test x=) |
| 3102 |
CallExpr:1( |
| 3103 |
MemberExpr:1( |
| 3104 |
StrExpr({!r:{}}) |
| 3105 |
format) |
| 3106 |
Args( |
| 3107 |
NameExpr(x) |
| 3108 |
StrExpr()))))))) |