| 1 |
-- Test cases for generating fine-grained dependencies between types. |
| 2 |
-- |
| 3 |
-- The dependencies are used for fined-grained incremental checking. |
| 4 |
-- |
| 5 |
-- See the comment at the top of deps.test for more documentation. |
| 6 |
|
| 7 |
[case testFilterOutBuiltInTypes] |
| 8 |
class A: pass |
| 9 |
|
| 10 |
def f(x: int, y: str, z: A) -> None: |
| 11 |
pass |
| 12 |
[out] |
| 13 |
<m.A> -> <m.f>, m.A, m.f |
| 14 |
|
| 15 |
[case testTupleType] |
| 16 |
from typing import Tuple |
| 17 |
|
| 18 |
class A: pass |
| 19 |
class B: pass |
| 20 |
|
| 21 |
def f(x: Tuple[A, B]) -> None: |
| 22 |
pass |
| 23 |
[builtins fixtures/tuple.pyi] |
| 24 |
[out] |
| 25 |
<m.A> -> <m.f>, m.A, m.f |
| 26 |
<m.B> -> <m.f>, m.B, m.f |
| 27 |
|
| 28 |
[case testUnionType] |
| 29 |
from typing import Union |
| 30 |
|
| 31 |
class A: pass |
| 32 |
class B: pass |
| 33 |
|
| 34 |
def f() -> None: |
| 35 |
x: Union[int, A, B] |
| 36 |
[out] |
| 37 |
<m.A> -> m.A, m.f |
| 38 |
<m.B> -> m.B, m.f |
| 39 |
|
| 40 |
[case testCallableType] |
| 41 |
from typing import Callable |
| 42 |
|
| 43 |
class A: pass |
| 44 |
class B: pass |
| 45 |
|
| 46 |
def f() -> None: |
| 47 |
x: Callable[[int, A], None] |
| 48 |
y: Callable[[int, str], B] |
| 49 |
[out] |
| 50 |
<m.A> -> m.A, m.f |
| 51 |
<m.B> -> m.B, m.f |
| 52 |
|
| 53 |
[case testTypeType] |
| 54 |
from typing import Type |
| 55 |
|
| 56 |
class A: pass |
| 57 |
|
| 58 |
def f() -> None: |
| 59 |
x: Type[A] |
| 60 |
y: Type[int] |
| 61 |
[out] |
| 62 |
<m.A.__init__> -> m.f |
| 63 |
<m.A.__new__> -> m.f |
| 64 |
<m.A> -> m.A, m.f |
| 65 |
|
| 66 |
[case testTypeTypeAttribute] |
| 67 |
from typing import Type |
| 68 |
|
| 69 |
class A: |
| 70 |
@staticmethod |
| 71 |
def f() -> None: pass |
| 72 |
|
| 73 |
def f(x: Type[A]) -> None: |
| 74 |
x.f() |
| 75 |
[builtins fixtures/staticmethod.pyi] |
| 76 |
[out] |
| 77 |
<m.A.__init__> -> <m.f>, m.f |
| 78 |
<m.A.__new__> -> <m.f>, m.f |
| 79 |
<m.A.f> -> m, m.f |
| 80 |
<m.A> -> <m.f>, m.A, m.f |
| 81 |
|
| 82 |
[case testComplexNestedType] |
| 83 |
from typing import Union, Callable, Type |
| 84 |
|
| 85 |
class A: pass |
| 86 |
class B: pass |
| 87 |
class C: pass |
| 88 |
|
| 89 |
def f() -> None: |
| 90 |
x: Union[int, Callable[[Type[A]], B], C] |
| 91 |
[out] |
| 92 |
<m.A.__init__> -> m.f |
| 93 |
<m.A.__new__> -> m.f |
| 94 |
<m.A> -> m.A, m.f |
| 95 |
<m.B> -> m.B, m.f |
| 96 |
<m.C> -> m.C, m.f |
| 97 |
|
| 98 |
[case testUnionTypeAttributeAccess] |
| 99 |
from typing import Union |
| 100 |
|
| 101 |
class A: |
| 102 |
def f(self) -> None: |
| 103 |
self.x = 0 |
| 104 |
|
| 105 |
class B: |
| 106 |
def f(self) -> None: |
| 107 |
self.x = '' |
| 108 |
|
| 109 |
def f(a: Union[A, B]) -> None: |
| 110 |
a.x |
| 111 |
a.f() |
| 112 |
[out] |
| 113 |
<m.A.f> -> m.f |
| 114 |
<m.A.x> -> m.A.f, m.f |
| 115 |
<m.A> -> <m.f>, m.A, m.f |
| 116 |
<m.B.f> -> m.f |
| 117 |
<m.B.x> -> m.B.f, m.f |
| 118 |
<m.B> -> <m.f>, m.B, m.f |
| 119 |
|
| 120 |
[case testTupleTypeAttributeAccess] |
| 121 |
from typing import Tuple |
| 122 |
|
| 123 |
class C(Tuple[int, str]): |
| 124 |
def f(self) -> None: pass |
| 125 |
|
| 126 |
def f(c: C) -> None: |
| 127 |
c.f() |
| 128 |
[builtins fixtures/tuple.pyi] |
| 129 |
[out] |
| 130 |
<m.C.f> -> m.f |
| 131 |
<m.C> -> <m.f>, m.C, m.f |
| 132 |
|
| 133 |
[case testOverloaded] |
| 134 |
from typing import overload |
| 135 |
|
| 136 |
class A: pass |
| 137 |
class B: pass |
| 138 |
|
| 139 |
def g() -> None: pass |
| 140 |
|
| 141 |
@overload |
| 142 |
def f(x: A) -> A: pass |
| 143 |
@overload |
| 144 |
def f(x: B) -> B: pass |
| 145 |
|
| 146 |
def f(x): |
| 147 |
g() |
| 148 |
|
| 149 |
ff = f |
| 150 |
|
| 151 |
def h() -> None: |
| 152 |
f(A()) |
| 153 |
ff(A()) |
| 154 |
[out] |
| 155 |
<m.A.__init__> -> m.h |
| 156 |
<m.A.__new__> -> m.h |
| 157 |
<m.A> -> <m.f>, <m.ff>, m.A, m.f, m.h |
| 158 |
<m.B> -> <m.f>, <m.ff>, m.B, m.f |
| 159 |
<m.f> -> m, m.h |
| 160 |
<m.ff> -> m, m.h |
| 161 |
<m.g> -> m.f |
| 162 |
|
| 163 |
[case testMetaclassAttributes] |
| 164 |
from mod import C |
| 165 |
from typing import Type |
| 166 |
def f(arg: Type[C]) -> None: |
| 167 |
arg.x |
| 168 |
[file mod.py] |
| 169 |
class M(type): |
| 170 |
x: int |
| 171 |
class C(metaclass=M): |
| 172 |
pass |
| 173 |
[out] |
| 174 |
<mod.C.__init__> -> <m.f>, m.f |
| 175 |
<mod.C.__new__> -> <m.f>, m.f |
| 176 |
<mod.C.x> -> m.f |
| 177 |
<mod.C> -> <m.f>, m, m.f |
| 178 |
<mod.M.x> -> m.f |
| 179 |
<mod> -> m |
| 180 |
|
| 181 |
[case testMetaclassAttributesDirect] |
| 182 |
from mod import C |
| 183 |
def f() -> None: |
| 184 |
C.x |
| 185 |
[file mod.py] |
| 186 |
class M(type): |
| 187 |
x: int |
| 188 |
class C(metaclass=M): |
| 189 |
pass |
| 190 |
[out] |
| 191 |
<mod.C.x> -> m.f |
| 192 |
<mod.C> -> m, m.f |
| 193 |
<mod.M.x> -> m.f |
| 194 |
<mod> -> m |
| 195 |
|
| 196 |
[case testMetaclassOperators] |
| 197 |
from mod import C |
| 198 |
from typing import Type |
| 199 |
def f(arg: Type[C]) -> None: |
| 200 |
arg + arg |
| 201 |
[file mod.py] |
| 202 |
class M(type): |
| 203 |
def __add__(self, other: M) -> M: |
| 204 |
pass |
| 205 |
class C(metaclass=M): |
| 206 |
pass |
| 207 |
[out] |
| 208 |
<mod.C.__init__> -> <m.f>, m.f |
| 209 |
<mod.C.__new__> -> <m.f>, m.f |
| 210 |
<mod.C> -> <m.f>, m, m.f |
| 211 |
<mod.M.__add__> -> m.f |
| 212 |
<mod.M.__radd__> -> m.f |
| 213 |
<mod> -> m |
| 214 |
|
| 215 |
[case testMetaclassOperatorsDirect] |
| 216 |
from mod import C |
| 217 |
def f() -> None: |
| 218 |
C + C |
| 219 |
[file mod.py] |
| 220 |
class M(type): |
| 221 |
def __add__(self, other: M) -> M: |
| 222 |
pass |
| 223 |
class C(metaclass=M): |
| 224 |
pass |
| 225 |
[out] |
| 226 |
<mod.C.__init__> -> m.f |
| 227 |
<mod.C.__new__> -> m.f |
| 228 |
<mod.C> -> m, m.f |
| 229 |
<mod.M.__add__> -> m.f |
| 230 |
<mod.M.__radd__> -> m.f |
| 231 |
<mod> -> m |
| 232 |
|
| 233 |
[case testMetaclassDepsDeclared] |
| 234 |
import mod |
| 235 |
class C(metaclass=mod.M): |
| 236 |
pass |
| 237 |
[file mod.py] |
| 238 |
class M(type): |
| 239 |
pass |
| 240 |
[out] |
| 241 |
<m.C> -> m.C |
| 242 |
<mod.M> -> <m.C>, m |
| 243 |
<mod> -> m |
| 244 |
|
| 245 |
[case testMetaclassDepsDeclaredNested] |
| 246 |
import mod |
| 247 |
|
| 248 |
def func() -> None: |
| 249 |
class C(metaclass=mod.M): |
| 250 |
pass |
| 251 |
[file mod.py] |
| 252 |
class M(type): |
| 253 |
pass |
| 254 |
[out] |
| 255 |
<m.func> -> m.func |
| 256 |
<mod.M> -> <m.func>, m.func |
| 257 |
<mod> -> m, m.func |
| 258 |
|
| 259 |
-- Type aliases |
| 260 |
|
| 261 |
[case testAliasDepsNormalMod] |
| 262 |
from mod import I |
| 263 |
A = I |
| 264 |
x: A |
| 265 |
[file mod.py] |
| 266 |
class I: pass |
| 267 |
[out] |
| 268 |
<m.A> -> m |
| 269 |
<m.x> -> m |
| 270 |
<mod.I.__init__> -> m |
| 271 |
<mod.I.__new__> -> m |
| 272 |
<mod.I> -> <m.x>, m |
| 273 |
<mod> -> m |
| 274 |
|
| 275 |
[case testAliasDepsNormalModExtended] |
| 276 |
# __dump_all__ |
| 277 |
import a |
| 278 |
x: a.A |
| 279 |
[file a.py] |
| 280 |
from mod import I |
| 281 |
A = I |
| 282 |
[file mod.py] |
| 283 |
class I: pass |
| 284 |
[out] |
| 285 |
<m.x> -> m |
| 286 |
<a.A> -> m |
| 287 |
<a> -> m |
| 288 |
<mod.I.__init__> -> a |
| 289 |
<mod.I.__new__> -> a |
| 290 |
<mod.I> -> <m.x>, m, a, mod.I |
| 291 |
<mod> -> a |
| 292 |
|
| 293 |
[case testAliasDepsNormalFunc] |
| 294 |
from mod import I |
| 295 |
A = I |
| 296 |
def f(x: A) -> None: |
| 297 |
pass |
| 298 |
[file mod.py] |
| 299 |
class I: pass |
| 300 |
[out] |
| 301 |
<m.A> -> m.f |
| 302 |
<mod.I.__init__> -> m |
| 303 |
<mod.I.__new__> -> m |
| 304 |
<mod.I> -> <m.f>, m, m.f |
| 305 |
<mod> -> m |
| 306 |
|
| 307 |
[case testAliasDepsNormalFuncExtended] |
| 308 |
# __dump_all__ |
| 309 |
import a |
| 310 |
def f(x: a.A) -> None: |
| 311 |
pass |
| 312 |
[file a.py] |
| 313 |
from mod import I |
| 314 |
A = I |
| 315 |
[file mod.py] |
| 316 |
class I: pass |
| 317 |
[out] |
| 318 |
<a.A> -> m.f |
| 319 |
<a> -> m |
| 320 |
<mod.I.__init__> -> a |
| 321 |
<mod.I.__new__> -> a |
| 322 |
<mod.I> -> <m.f>, m.f, a, mod.I |
| 323 |
<mod> -> a |
| 324 |
|
| 325 |
[case testAliasDepsNormalClass] |
| 326 |
from a import A |
| 327 |
class C: |
| 328 |
x: A |
| 329 |
[file a.py] |
| 330 |
from mod import I |
| 331 |
A = I |
| 332 |
[file mod.py] |
| 333 |
class I: pass |
| 334 |
[out] |
| 335 |
<m.C> -> m.C |
| 336 |
<a.A> -> m |
| 337 |
<a> -> m |
| 338 |
<mod.I> -> <m.C.x>, m |
| 339 |
|
| 340 |
[case testAliasDepsNormalClassBases] |
| 341 |
from a import A |
| 342 |
class C(A): |
| 343 |
pass |
| 344 |
[file a.py] |
| 345 |
from mod import I |
| 346 |
A = I |
| 347 |
[file mod.py] |
| 348 |
class I: pass |
| 349 |
[out] |
| 350 |
<m.C> -> m.C |
| 351 |
<a.A> -> m |
| 352 |
<a> -> m |
| 353 |
<mod.I.(abstract)> -> <m.C.__init__>, m |
| 354 |
<mod.I.__init__> -> <m.C.__init__> |
| 355 |
<mod.I.__new__> -> <m.C.__new__> |
| 356 |
<mod.I> -> m.C |
| 357 |
|
| 358 |
[case testAliasDepsGenericMod] |
| 359 |
from mod import I, S, D |
| 360 |
A = D[I, S] |
| 361 |
x: A |
| 362 |
[file mod.py] |
| 363 |
from typing import TypeVar, Generic |
| 364 |
T = TypeVar('T') |
| 365 |
U = TypeVar('U') |
| 366 |
class D(Generic[T, U]): pass |
| 367 |
class I: pass |
| 368 |
class S: pass |
| 369 |
[out] |
| 370 |
<m.A> -> m |
| 371 |
<m.x> -> m |
| 372 |
<mod.D.__init__> -> m |
| 373 |
<mod.D.__new__> -> m |
| 374 |
<mod.D> -> <m.x>, m |
| 375 |
<mod.I> -> <m.x>, m |
| 376 |
<mod.S> -> <m.x>, m |
| 377 |
<mod> -> m |
| 378 |
|
| 379 |
[case testAliasDepsGenericFunc] |
| 380 |
from mod import I, S, D |
| 381 |
A = D[S, I] |
| 382 |
def f(x: A) -> None: |
| 383 |
pass |
| 384 |
[file mod.py] |
| 385 |
from typing import TypeVar, Generic |
| 386 |
T = TypeVar('T') |
| 387 |
U = TypeVar('U') |
| 388 |
class D(Generic[T, U]): pass |
| 389 |
class I: pass |
| 390 |
class S: pass |
| 391 |
[out] |
| 392 |
<m.A> -> <m.f>, m.f |
| 393 |
<mod.D.__init__> -> m |
| 394 |
<mod.D.__new__> -> m |
| 395 |
<mod.D> -> <m.f>, m, m.f |
| 396 |
<mod.I> -> <m.f>, m, m.f |
| 397 |
<mod.S> -> <m.f>, m, m.f |
| 398 |
<mod> -> m |
| 399 |
|
| 400 |
[case testAliasDepsGenericFuncExtended] |
| 401 |
import a |
| 402 |
def f(x: a.A) -> None: |
| 403 |
pass |
| 404 |
[file a.py] |
| 405 |
from mod import I, S, D |
| 406 |
A = D[S, I] |
| 407 |
[file mod.py] |
| 408 |
from typing import TypeVar, Generic |
| 409 |
T = TypeVar('T') |
| 410 |
U = TypeVar('U') |
| 411 |
class D(Generic[T, U]): pass |
| 412 |
class I: pass |
| 413 |
class S: pass |
| 414 |
[out] |
| 415 |
<a.A> -> <m.f>, m.f |
| 416 |
<a> -> m |
| 417 |
<mod.D> -> <m.f>, m.f |
| 418 |
<mod.I> -> <m.f>, m.f |
| 419 |
<mod.S> -> <m.f>, m.f |
| 420 |
|
| 421 |
[case testAliasDepsGenericClass] |
| 422 |
from mod import I, D, S, T |
| 423 |
A = D[S, T] |
| 424 |
class C: |
| 425 |
x: A[I] |
| 426 |
[file mod.py] |
| 427 |
from typing import TypeVar, Generic |
| 428 |
T = TypeVar('T') |
| 429 |
U = TypeVar('U') |
| 430 |
class D(Generic[T, U]): pass |
| 431 |
class I: pass |
| 432 |
class S: pass |
| 433 |
[out] |
| 434 |
<m.A> -> m |
| 435 |
<m.C> -> m.C |
| 436 |
<mod.D.__init__> -> m |
| 437 |
<mod.D.__new__> -> m |
| 438 |
<mod.D> -> <m.C.x>, m |
| 439 |
<mod.I> -> <m.C.x>, m |
| 440 |
<mod.S> -> <m.C.x>, m |
| 441 |
<mod.T> -> m |
| 442 |
<mod> -> m |
| 443 |
|
| 444 |
[case testAliasDepsForwardMod] |
| 445 |
from mod import I |
| 446 |
x: A |
| 447 |
A = I |
| 448 |
[file mod.py] |
| 449 |
from typing import TypeVar, Generic |
| 450 |
class I: pass |
| 451 |
[out] |
| 452 |
<m.A> -> m |
| 453 |
<m.x> -> m |
| 454 |
<mod.I.__init__> -> m |
| 455 |
<mod.I.__new__> -> m |
| 456 |
<mod.I> -> <m.x>, m |
| 457 |
<mod> -> m |
| 458 |
|
| 459 |
[case testAliasDepsForwardFunc] |
| 460 |
from mod import I |
| 461 |
def f(x: A) -> None: |
| 462 |
pass |
| 463 |
A = I |
| 464 |
[file mod.py] |
| 465 |
class I: pass |
| 466 |
[out] |
| 467 |
<m.A> -> m.f |
| 468 |
<mod.I.__init__> -> m |
| 469 |
<mod.I.__new__> -> m |
| 470 |
<mod.I> -> <m.f>, m, m.f |
| 471 |
<mod> -> m |
| 472 |
|
| 473 |
[case testAliasDepsForwardClass] |
| 474 |
from mod import I |
| 475 |
class C: |
| 476 |
x: A |
| 477 |
A = I |
| 478 |
[file mod.py] |
| 479 |
class I: pass |
| 480 |
[out] |
| 481 |
<m.A> -> m |
| 482 |
<m.C> -> m.C |
| 483 |
<mod.I.__init__> -> m |
| 484 |
<mod.I.__new__> -> m |
| 485 |
<mod.I> -> <m.C.x>, m |
| 486 |
<mod> -> m |
| 487 |
|
| 488 |
[case testAliasDepsChainedMod] |
| 489 |
from mod import I |
| 490 |
A = I |
| 491 |
B = A |
| 492 |
x: B |
| 493 |
[file mod.py] |
| 494 |
class I: pass |
| 495 |
[out] |
| 496 |
<m.A> -> m |
| 497 |
<m.B> -> m |
| 498 |
<m.x> -> m |
| 499 |
<mod.I.__init__> -> m |
| 500 |
<mod.I.__new__> -> m |
| 501 |
<mod.I> -> <m.x>, m |
| 502 |
<mod> -> m |
| 503 |
|
| 504 |
[case testAliasDepsChainedFunc] |
| 505 |
from mod import I |
| 506 |
A = I |
| 507 |
B = A |
| 508 |
def f(x: B) -> None: |
| 509 |
pass |
| 510 |
[file mod.py] |
| 511 |
class I: pass |
| 512 |
[out] |
| 513 |
<m.A> -> m |
| 514 |
<m.B> -> m.f |
| 515 |
<mod.I.__init__> -> m |
| 516 |
<mod.I.__new__> -> m |
| 517 |
<mod.I> -> <m.f>, m, m.f |
| 518 |
<mod> -> m |
| 519 |
|
| 520 |
[case testAliasDepsChainedFuncExtended] |
| 521 |
import a |
| 522 |
B = a.A |
| 523 |
def f(x: B) -> None: |
| 524 |
pass |
| 525 |
[file a.py] |
| 526 |
from mod import I |
| 527 |
A = I |
| 528 |
[file mod.py] |
| 529 |
class I: pass |
| 530 |
[out] |
| 531 |
<m.B> -> m.f |
| 532 |
<a.A> -> m |
| 533 |
<a> -> m |
| 534 |
<mod.I.__init__> -> m |
| 535 |
<mod.I.__new__> -> m |
| 536 |
<mod.I> -> <m.f>, m, m.f |
| 537 |
|
| 538 |
[case testAliasDepsChainedClass] |
| 539 |
from mod import I |
| 540 |
A = I |
| 541 |
B = A |
| 542 |
class C(B): |
| 543 |
pass |
| 544 |
[file mod.py] |
| 545 |
class I: pass |
| 546 |
[out] |
| 547 |
<m.A> -> m |
| 548 |
<m.B> -> m |
| 549 |
<m.C> -> m.C |
| 550 |
<mod.I.(abstract)> -> <m.C.__init__>, m |
| 551 |
<mod.I.__init__> -> <m.C.__init__>, m |
| 552 |
<mod.I.__new__> -> <m.C.__new__>, m |
| 553 |
<mod.I> -> m, m.C |
| 554 |
<mod> -> m |
| 555 |
|
| 556 |
[case testAliasDepsNestedMod] |
| 557 |
from mod import I, S, D |
| 558 |
A = D[S, I] |
| 559 |
B = D[S, A] |
| 560 |
x: B |
| 561 |
[file mod.py] |
| 562 |
from typing import TypeVar, Generic |
| 563 |
T = TypeVar('T') |
| 564 |
U = TypeVar('U') |
| 565 |
class D(Generic[T, U]): pass |
| 566 |
class I: pass |
| 567 |
class S: pass |
| 568 |
[out] |
| 569 |
<m.A> -> <m.x>, m |
| 570 |
<m.B> -> m |
| 571 |
<m.x> -> m |
| 572 |
<mod.D.__init__> -> m |
| 573 |
<mod.D.__new__> -> m |
| 574 |
<mod.D> -> <m.x>, m |
| 575 |
<mod.I> -> <m.x>, m |
| 576 |
<mod.S> -> <m.x>, m |
| 577 |
<mod> -> m |
| 578 |
|
| 579 |
[case testAliasDepsNestedModExtended] |
| 580 |
# __dump_all__ |
| 581 |
from mod import S, D |
| 582 |
import a |
| 583 |
B = D[S, a.A] |
| 584 |
x: B |
| 585 |
[file a.py] |
| 586 |
from mod import I, S, D |
| 587 |
A = D[S, I] |
| 588 |
[file mod.py] |
| 589 |
from typing import TypeVar, Generic |
| 590 |
T = TypeVar('T') |
| 591 |
U = TypeVar('U') |
| 592 |
class D(Generic[T, U]): pass |
| 593 |
class I: pass |
| 594 |
class S: pass |
| 595 |
[out] |
| 596 |
<m.B> -> m |
| 597 |
<m.x> -> m |
| 598 |
<a.A> -> <m.x>, m |
| 599 |
<a> -> m |
| 600 |
<mod.D.__init__> -> m, a |
| 601 |
<mod.D.__new__> -> m, a |
| 602 |
<mod.D> -> <m.x>, m, a, mod.D |
| 603 |
<mod.I> -> <m.x>, m, a, mod.I |
| 604 |
<mod.S> -> <m.x>, m, a, mod.S |
| 605 |
<mod.T> -> mod.D |
| 606 |
<mod.U> -> mod.D |
| 607 |
<mod> -> m, a |
| 608 |
|
| 609 |
[case testAliasDepsNestedFunc] |
| 610 |
from mod import I, S, D |
| 611 |
A = D[S, I] |
| 612 |
B = D[S, A] |
| 613 |
def f(x: B) -> None: |
| 614 |
pass |
| 615 |
[file mod.py] |
| 616 |
from typing import TypeVar, Generic |
| 617 |
T = TypeVar('T') |
| 618 |
U = TypeVar('U') |
| 619 |
class D(Generic[T, U]): pass |
| 620 |
class I: pass |
| 621 |
class S: pass |
| 622 |
[out] |
| 623 |
<m.A> -> <m.f>, m, m.f |
| 624 |
<m.B> -> <m.f>, m.f |
| 625 |
<mod.D.__init__> -> m |
| 626 |
<mod.D.__new__> -> m |
| 627 |
<mod.D> -> <m.f>, m, m.f |
| 628 |
<mod.I> -> <m.f>, m, m.f |
| 629 |
<mod.S> -> <m.f>, m, m.f |
| 630 |
<mod> -> m |
| 631 |
|
| 632 |
[case testAliasDepsNestedFuncExtended] |
| 633 |
# __dump_all__ |
| 634 |
from mod import S, D |
| 635 |
import a |
| 636 |
B = D[S, a.A] |
| 637 |
def f(x: B) -> None: |
| 638 |
pass |
| 639 |
[file a.py] |
| 640 |
from mod import I, S, D |
| 641 |
A = D[S, I] |
| 642 |
[file mod.py] |
| 643 |
from typing import TypeVar, Generic |
| 644 |
T = TypeVar('T') |
| 645 |
U = TypeVar('U') |
| 646 |
class D(Generic[T, U]): pass |
| 647 |
class I: pass |
| 648 |
class S: pass |
| 649 |
[out] |
| 650 |
<m.B> -> <m.f>, m.f |
| 651 |
<a.A> -> <m.f>, m, m.f |
| 652 |
<a> -> m |
| 653 |
<mod.D.__init__> -> m, a |
| 654 |
<mod.D.__new__> -> m, a |
| 655 |
<mod.D> -> <m.f>, m, m.f, a, mod.D |
| 656 |
<mod.I> -> <m.f>, m, m.f, a, mod.I |
| 657 |
<mod.S> -> <m.f>, m, m.f, a, mod.S |
| 658 |
<mod.T> -> mod.D |
| 659 |
<mod.U> -> mod.D |
| 660 |
<mod> -> m, a |
| 661 |
|
| 662 |
[case testAliasDepsNestedFuncDirect] |
| 663 |
from mod import I, S, D |
| 664 |
A = D[S, I] |
| 665 |
E = D |
| 666 |
def f(x: E[S, A]) -> None: |
| 667 |
pass |
| 668 |
[file mod.py] |
| 669 |
from typing import TypeVar, Generic |
| 670 |
T = TypeVar('T') |
| 671 |
U = TypeVar('U') |
| 672 |
class D(Generic[T, U]): pass |
| 673 |
class I: pass |
| 674 |
class S: pass |
| 675 |
[out] |
| 676 |
<m.A> -> <m.f>, m.f |
| 677 |
<m.E> -> m.f |
| 678 |
<mod.D.__init__> -> m |
| 679 |
<mod.D.__new__> -> m |
| 680 |
<mod.D> -> <m.f>, m, m.f |
| 681 |
<mod.I> -> <m.f>, m, m.f |
| 682 |
<mod.S> -> <m.f>, m, m.f |
| 683 |
<mod.T> -> m |
| 684 |
<mod.U> -> m |
| 685 |
<mod> -> m |
| 686 |
|
| 687 |
[case testAliasDepsNestedClass] |
| 688 |
from mod import I, S, D |
| 689 |
A = D[S, I] |
| 690 |
B = D[S, A] |
| 691 |
class C: |
| 692 |
x: B |
| 693 |
[file mod.py] |
| 694 |
from typing import TypeVar, Generic |
| 695 |
T = TypeVar('T') |
| 696 |
U = TypeVar('U') |
| 697 |
class D(Generic[T, U]): pass |
| 698 |
class I: pass |
| 699 |
class S: pass |
| 700 |
[out] |
| 701 |
<m.A> -> <m.C.x>, m |
| 702 |
<m.B> -> m |
| 703 |
<m.C> -> m.C |
| 704 |
<mod.D.__init__> -> m |
| 705 |
<mod.D.__new__> -> m |
| 706 |
<mod.D> -> <m.C.x>, m |
| 707 |
<mod.I> -> <m.C.x>, m |
| 708 |
<mod.S> -> <m.C.x>, m |
| 709 |
<mod> -> m |
| 710 |
|
| 711 |
[case testAliasDepsCast] |
| 712 |
from typing import cast |
| 713 |
from mod import I |
| 714 |
A = I |
| 715 |
def fun() -> None: |
| 716 |
x = cast(A, 42) |
| 717 |
[file mod.py] |
| 718 |
from typing import TypeVar, Generic |
| 719 |
T = TypeVar('T') |
| 720 |
U = TypeVar('U') |
| 721 |
class D(Generic[T, U]): pass |
| 722 |
class I: pass |
| 723 |
class S: pass |
| 724 |
[out] |
| 725 |
<m.A> -> m.fun |
| 726 |
<mod.I.__init__> -> m |
| 727 |
<mod.I.__new__> -> m |
| 728 |
<mod.I> -> m, m.fun |
| 729 |
<mod> -> m |
| 730 |
|
| 731 |
[case testAliasDepsRuntime] |
| 732 |
from mod import I, S, D |
| 733 |
A = I |
| 734 |
x = D[S, A]() |
| 735 |
[file mod.py] |
| 736 |
from typing import TypeVar, Generic |
| 737 |
T = TypeVar('T') |
| 738 |
U = TypeVar('U') |
| 739 |
class D(Generic[T, U]): pass |
| 740 |
class I: pass |
| 741 |
class S: pass |
| 742 |
[out] |
| 743 |
<m.A> -> m |
| 744 |
<m.x> -> m |
| 745 |
<mod.D.__init__> -> m |
| 746 |
<mod.D.__new__> -> m |
| 747 |
<mod.D> -> <m.x>, m |
| 748 |
<mod.I.__init__> -> m |
| 749 |
<mod.I.__new__> -> m |
| 750 |
<mod.I> -> <m.x>, m |
| 751 |
<mod.S> -> <m.x>, m |
| 752 |
<mod> -> m |
| 753 |
|
| 754 |
[case testAliasDepsRuntimeExtended] |
| 755 |
# __dump_all__ |
| 756 |
from mod import I, S, D |
| 757 |
import a |
| 758 |
x = D[S, a.A]() |
| 759 |
[file a.py] |
| 760 |
from mod import I |
| 761 |
A = I |
| 762 |
[file mod.py] |
| 763 |
from typing import TypeVar, Generic |
| 764 |
T = TypeVar('T') |
| 765 |
U = TypeVar('U') |
| 766 |
class D(Generic[T, U]): pass |
| 767 |
class I: pass |
| 768 |
class S: pass |
| 769 |
[out] |
| 770 |
<m.x> -> m |
| 771 |
<a.A> -> m |
| 772 |
<a> -> m |
| 773 |
<mod.D.__init__> -> m |
| 774 |
<mod.D.__new__> -> m |
| 775 |
<mod.D> -> <m.x>, m, mod.D |
| 776 |
<mod.I.__init__> -> a |
| 777 |
<mod.I.__new__> -> a |
| 778 |
<mod.I> -> <m.x>, m, a, mod.I |
| 779 |
<mod.S> -> <m.x>, m, mod.S |
| 780 |
<mod.T> -> mod.D |
| 781 |
<mod.U> -> mod.D |
| 782 |
<mod> -> m, a |
| 783 |
|
| 784 |
[case testAliasDepsNamedTuple] |
| 785 |
from typing import NamedTuple |
| 786 |
from mod import I |
| 787 |
A = I |
| 788 |
class P(NamedTuple): |
| 789 |
x: A |
| 790 |
[file mod.py] |
| 791 |
class I: pass |
| 792 |
[builtins fixtures/tuple.pyi] |
| 793 |
[out] |
| 794 |
<m.A> -> m |
| 795 |
<m.P> -> m.P |
| 796 |
<mod.I.__init__> -> m |
| 797 |
<mod.I.__new__> -> m |
| 798 |
<mod.I> -> <m.P.x>, <m.P>, m, m.P |
| 799 |
<mod> -> m |
| 800 |
|
| 801 |
[case testAliasDepsNamedTupleFunctional] |
| 802 |
# __dump_all__ |
| 803 |
from typing import NamedTuple |
| 804 |
import a |
| 805 |
P = NamedTuple('P', [('x', a.A)]) |
| 806 |
[file a.py] |
| 807 |
from mod import I |
| 808 |
A = I |
| 809 |
[file mod.py] |
| 810 |
class I: pass |
| 811 |
[builtins fixtures/tuple.pyi] |
| 812 |
[out] |
| 813 |
<a.A> -> m |
| 814 |
<a> -> m |
| 815 |
<mod.I.__init__> -> a |
| 816 |
<mod.I.__new__> -> a |
| 817 |
<mod.I> -> <m.P.x>, <m.P>, m, a, mod.I |
| 818 |
<mod> -> a |
| 819 |
|
| 820 |
[case testAliasDepsTypedDict] |
| 821 |
from typing import TypedDict |
| 822 |
from mod import I |
| 823 |
A = I |
| 824 |
class P(TypedDict): |
| 825 |
x: A |
| 826 |
[file mod.py] |
| 827 |
class I: pass |
| 828 |
[builtins fixtures/dict.pyi] |
| 829 |
[typing fixtures/typing-typeddict.pyi] |
| 830 |
[out] |
| 831 |
<m.A> -> m |
| 832 |
<m.P> -> m.P |
| 833 |
<mod.I.__init__> -> m |
| 834 |
<mod.I.__new__> -> m |
| 835 |
<mod.I> -> <m.P>, m |
| 836 |
<mod> -> m |
| 837 |
|
| 838 |
[case testAliasDepsTypedDictFunctional] |
| 839 |
# __dump_all__ |
| 840 |
from typing import TypedDict |
| 841 |
import a |
| 842 |
P = TypedDict('P', {'x': a.A}) |
| 843 |
[file a.py] |
| 844 |
from mod import I |
| 845 |
A = I |
| 846 |
[file mod.py] |
| 847 |
class I: pass |
| 848 |
[builtins fixtures/dict.pyi] |
| 849 |
[typing fixtures/typing-typeddict.pyi] |
| 850 |
[out] |
| 851 |
<a.A> -> m |
| 852 |
<a> -> m |
| 853 |
<mod.I.__init__> -> a |
| 854 |
<mod.I.__new__> -> a |
| 855 |
<mod.I> -> <m.P>, a, mod.I |
| 856 |
<mod> -> a |
| 857 |
|
| 858 |
[case testAliasDepsClassInFunction] |
| 859 |
from mod import I |
| 860 |
A = I |
| 861 |
def f() -> None: |
| 862 |
class C: |
| 863 |
x: A |
| 864 |
[file mod.py] |
| 865 |
class I: pass |
| 866 |
[out] |
| 867 |
<m.A> -> m.f |
| 868 |
<m.f> -> m.f |
| 869 |
<mod.I.__init__> -> m |
| 870 |
<mod.I.__new__> -> m |
| 871 |
<mod.I> -> <m.f.x>, m, m.f |
| 872 |
<mod> -> m |
| 873 |
|
| 874 |
[case testAliasDepsFromImportUnqualified] |
| 875 |
from a import C |
| 876 |
x: C |
| 877 |
def f() -> None: |
| 878 |
C() |
| 879 |
class A: |
| 880 |
def meth(self) -> None: |
| 881 |
def inner() -> C: |
| 882 |
pass |
| 883 |
[file a.py] |
| 884 |
from b import D |
| 885 |
C = D |
| 886 |
[file b.py] |
| 887 |
class D: |
| 888 |
pass |
| 889 |
[out] |
| 890 |
<m.A> -> m.A |
| 891 |
<m.x> -> m |
| 892 |
<a.C> -> m, m.A.meth, m.f |
| 893 |
<a> -> m |
| 894 |
<b.D.__init__> -> m.f |
| 895 |
<b.D.__new__> -> m.f |
| 896 |
<b.D> -> <m.A.meth>, <m.x>, m, m.A.meth |
| 897 |
|
| 898 |
[case testFuncBasedEnum] |
| 899 |
from enum import Enum |
| 900 |
from mod import B |
| 901 |
|
| 902 |
A = Enum('A', [('X', B())]) |
| 903 |
|
| 904 |
def f(a: A) -> None: |
| 905 |
pass |
| 906 |
def g() -> None: |
| 907 |
A.X |
| 908 |
[file mod.py] |
| 909 |
class B: pass |
| 910 |
[builtins fixtures/tuple.pyi] |
| 911 |
[out] |
| 912 |
<m.A.X> -> m.g |
| 913 |
<m.A> -> <m.f>, m.f, m.g |
| 914 |
<mod.B> -> m |
| 915 |
<mod> -> m |
| 916 |
|
| 917 |
[case testProtocolDepsWildcard] |
| 918 |
# __dump_all__ |
| 919 |
import mod |
| 920 |
x: mod.P |
| 921 |
[file mod.py] |
| 922 |
from typing import Protocol |
| 923 |
class P(Protocol): |
| 924 |
x: int |
| 925 |
[out] |
| 926 |
<m.x> -> m |
| 927 |
<mod.P> -> <m.x>, m, mod.P |
| 928 |
<mod.P[wildcard]> -> <mod.P> |
| 929 |
<mod> -> m |
| 930 |
|
| 931 |
[case testProtocolDepsWildcardSupertype] |
| 932 |
# __dump_all__ |
| 933 |
import mod |
| 934 |
x: mod.P |
| 935 |
[file mod.py] |
| 936 |
from typing import Protocol |
| 937 |
class PBase(Protocol): |
| 938 |
x: int |
| 939 |
class P(PBase, Protocol): |
| 940 |
y: int |
| 941 |
[out] |
| 942 |
<m.x> -> m |
| 943 |
<mod.P.y> -> mod |
| 944 |
<mod.P> -> <m.x>, m, mod.P |
| 945 |
<mod.PBase.(abstract)> -> <mod.P.__init__>, mod |
| 946 |
<mod.PBase.__init__> -> <mod.P.__init__> |
| 947 |
<mod.PBase.__new__> -> <mod.P.__new__> |
| 948 |
<mod.PBase.x> -> <mod.P.x> |
| 949 |
<mod.PBase.y> -> <mod.P.y> |
| 950 |
<mod.PBase> -> mod, mod.P, mod.PBase |
| 951 |
<mod.PBase[wildcard]> -> <mod.P>, <mod.PBase> |
| 952 |
<mod.P[wildcard]> -> <mod.P> |
| 953 |
<mod> -> m |
| 954 |
|
| 955 |
[case testProtocolDepsPositive] |
| 956 |
# __dump_all__ |
| 957 |
import mod |
| 958 |
class C: |
| 959 |
x: int |
| 960 |
x: mod.P = C() |
| 961 |
[file mod.py] |
| 962 |
from typing import Protocol |
| 963 |
class P(Protocol): |
| 964 |
x: int |
| 965 |
[out] |
| 966 |
<m.C.__init__> -> m |
| 967 |
<m.C.__new__> -> m |
| 968 |
<m.C.x> -> <m.C> |
| 969 |
<m.C> -> m, m.C, mod.P |
| 970 |
<m.x> -> m |
| 971 |
<mod.P> -> <m.x>, m, mod.P |
| 972 |
<mod.P[wildcard]> -> <mod.P> |
| 973 |
<mod> -> m |
| 974 |
|
| 975 |
[case testProtocolDepsNegative] |
| 976 |
# __dump_all__ |
| 977 |
import mod |
| 978 |
from typing import overload |
| 979 |
class C: |
| 980 |
y: int |
| 981 |
@overload |
| 982 |
def func(x: C) -> int: ... |
| 983 |
@overload |
| 984 |
def func(x: mod.P) -> str: ... |
| 985 |
def func(x): |
| 986 |
pass |
| 987 |
|
| 988 |
func(C()) |
| 989 |
[file mod.py] |
| 990 |
from typing import Protocol |
| 991 |
class P(Protocol): |
| 992 |
x: int |
| 993 |
[out] |
| 994 |
<m.C.__init__> -> m |
| 995 |
<m.C.__new__> -> m |
| 996 |
<m.C.x> -> <m.C> |
| 997 |
<m.C> -> <m.func>, m, m.C, m.func, mod.P |
| 998 |
<m.func> -> m |
| 999 |
<mod.P> -> <m.func>, m.func, mod.P |
| 1000 |
<mod.P[wildcard]> -> <mod.P> |
| 1001 |
<mod> -> m |
| 1002 |
|
| 1003 |
[case testProtocolDepsConcreteSuperclass] |
| 1004 |
# __dump_all__ |
| 1005 |
import mod |
| 1006 |
class B: |
| 1007 |
x: int |
| 1008 |
class C(B): |
| 1009 |
pass |
| 1010 |
x: mod.P = C() |
| 1011 |
[file mod.py] |
| 1012 |
from typing import Protocol |
| 1013 |
class P(Protocol): |
| 1014 |
x: int |
| 1015 |
[out] |
| 1016 |
<m.B.(abstract)> -> <m.C.__init__>, m |
| 1017 |
<m.B.__init__> -> <m.C.__init__> |
| 1018 |
<m.B.__new__> -> <m.C.__new__> |
| 1019 |
<m.B.x> -> <m.C.x>, <m.C> |
| 1020 |
<m.B> -> m, m.B, m.C |
| 1021 |
<m.C.__init__> -> m |
| 1022 |
<m.C.__new__> -> m |
| 1023 |
<m.C.x> -> <m.C> |
| 1024 |
<m.C> -> m, m.C, mod.P |
| 1025 |
<m.x> -> m |
| 1026 |
<mod.P> -> <m.x>, m, mod.P |
| 1027 |
<mod.P[wildcard]> -> <mod.P> |
| 1028 |
<mod> -> m |