| 1 |
-- Test cases for generating dependencies between ASTs nodes. |
| 2 |
-- |
| 3 |
-- The dependencies are used for fined-grained incremental checking and |
| 4 |
-- the daemon mode. |
| 5 |
-- |
| 6 |
-- The output of each test case includes the dependency map for whitelisted |
| 7 |
-- modules (includes the main module and the modules 'pkg' and 'pkg.mod' at |
| 8 |
-- least). |
| 9 |
-- |
| 10 |
-- Dependencies are formatted as "<trigger> -> affected locations". |
| 11 |
-- |
| 12 |
-- Look at the docstring of mypy.server.deps for an explanation of |
| 13 |
-- how fine-grained dependencies are represented. |
| 14 |
|
| 15 |
[case testCallFunction] |
| 16 |
def f() -> None: |
| 17 |
g() |
| 18 |
def g() -> None: |
| 19 |
pass |
| 20 |
[out] |
| 21 |
<m.g> -> m.f |
| 22 |
|
| 23 |
[case testCallMethod] |
| 24 |
def f(a: A) -> None: |
| 25 |
a.g() |
| 26 |
class A: |
| 27 |
def g(self) -> None: pass |
| 28 |
[out] |
| 29 |
<m.A.g> -> m.f |
| 30 |
<m.A> -> <m.f>, m.A, m.f |
| 31 |
|
| 32 |
[case testAccessAttribute] |
| 33 |
def f(a: A) -> None: |
| 34 |
a.x |
| 35 |
class A: |
| 36 |
def g(self) -> None: |
| 37 |
self.x = 1 |
| 38 |
[out] |
| 39 |
<m.A.x> -> m.A.g, m.f |
| 40 |
<m.A> -> <m.f>, m.A, m.f |
| 41 |
|
| 42 |
[case testConstructInstance] |
| 43 |
def f() -> None: |
| 44 |
A() |
| 45 |
class A: pass |
| 46 |
[out] |
| 47 |
<m.A.__init__> -> m.f |
| 48 |
<m.A.__new__> -> m.f |
| 49 |
<m.A> -> m.A, m.f |
| 50 |
|
| 51 |
[case testAccessModuleAttribute] |
| 52 |
class A: pass |
| 53 |
x = A() |
| 54 |
def f() -> None: |
| 55 |
x |
| 56 |
[out] |
| 57 |
<m.A.__init__> -> m |
| 58 |
<m.A.__new__> -> m |
| 59 |
<m.A> -> <m.x>, m, m.A |
| 60 |
<m.x> -> m, m.f |
| 61 |
|
| 62 |
[case testAccessModuleAttribute2] |
| 63 |
import n |
| 64 |
def f() -> None: |
| 65 |
n.x |
| 66 |
[file n.py] |
| 67 |
x = 1 |
| 68 |
[out] |
| 69 |
<n.x> -> m.f |
| 70 |
<n> -> m, m.f |
| 71 |
|
| 72 |
[case testImport] |
| 73 |
import n |
| 74 |
[file n.py] |
| 75 |
x = 1 |
| 76 |
[out] |
| 77 |
<n> -> m |
| 78 |
|
| 79 |
[case testCallImportedFunction] |
| 80 |
import n |
| 81 |
n.f() |
| 82 |
[file n.py] |
| 83 |
def f() -> None: pass |
| 84 |
[out] |
| 85 |
<n.f> -> m |
| 86 |
<n> -> m |
| 87 |
|
| 88 |
[case testImportModuleAs] |
| 89 |
import n as x |
| 90 |
x.f() |
| 91 |
[file n.py] |
| 92 |
def f() -> None: pass |
| 93 |
[out] |
| 94 |
<n.f> -> m |
| 95 |
<n> -> m |
| 96 |
|
| 97 |
[case testCallImportedFunctionInFunction] |
| 98 |
import n |
| 99 |
def g() -> None: |
| 100 |
n.f() |
| 101 |
[file n.py] |
| 102 |
def f() -> None: pass |
| 103 |
[out] |
| 104 |
<n.f> -> m.g |
| 105 |
<n> -> m, m.g |
| 106 |
|
| 107 |
[case testInheritanceSimple] |
| 108 |
class A: |
| 109 |
pass |
| 110 |
class B(A): |
| 111 |
pass |
| 112 |
[out] |
| 113 |
<m.A.(abstract)> -> <m.B.__init__>, m |
| 114 |
<m.A.__init__> -> <m.B.__init__> |
| 115 |
<m.A.__new__> -> <m.B.__new__> |
| 116 |
<m.A> -> m, m.A, m.B |
| 117 |
<m.B> -> m.B |
| 118 |
|
| 119 |
[case testInheritanceWithMethodAndAttribute] |
| 120 |
class A: |
| 121 |
pass |
| 122 |
class B(A): |
| 123 |
def f(self) -> None: |
| 124 |
self.x = 1 |
| 125 |
[out] |
| 126 |
<m.A.(abstract)> -> <m.B.__init__>, m |
| 127 |
<m.A.__init__> -> <m.B.__init__> |
| 128 |
<m.A.__new__> -> <m.B.__new__> |
| 129 |
<m.A.f> -> m.B.f |
| 130 |
<m.A.x> -> <m.B.x> |
| 131 |
<m.A> -> m, m.A, m.B |
| 132 |
<m.B.x> -> m.B.f |
| 133 |
<m.B> -> m.B |
| 134 |
|
| 135 |
[case testInheritanceWithMethodAndAttributeAndDeepHierarchy] |
| 136 |
class A: |
| 137 |
pass |
| 138 |
class B(A): |
| 139 |
pass |
| 140 |
class C(B): |
| 141 |
def f(self) -> None: |
| 142 |
self.x = 1 |
| 143 |
[out] |
| 144 |
<m.A.(abstract)> -> <m.B.__init__>, <m.C.__init__>, m |
| 145 |
<m.A.__init__> -> <m.B.__init__>, <m.C.__init__> |
| 146 |
<m.A.__new__> -> <m.B.__new__>, <m.C.__new__> |
| 147 |
<m.A.f> -> m.C.f |
| 148 |
<m.A.x> -> <m.C.x> |
| 149 |
<m.A> -> m, m.A, m.B |
| 150 |
<m.B.(abstract)> -> <m.C.__init__>, m |
| 151 |
<m.B.__init__> -> <m.C.__init__> |
| 152 |
<m.B.__new__> -> <m.C.__new__> |
| 153 |
<m.B.f> -> m.C.f |
| 154 |
<m.B.x> -> <m.C.x> |
| 155 |
<m.B> -> m, m.B, m.C |
| 156 |
<m.C.x> -> m.C.f |
| 157 |
<m.C> -> m.C |
| 158 |
|
| 159 |
[case testInheritAttribute] |
| 160 |
import n |
| 161 |
class B(n.A): |
| 162 |
def f(self) -> None: |
| 163 |
a = 1 |
| 164 |
a = self.x |
| 165 |
[file n.py] |
| 166 |
class A: |
| 167 |
def g(self) -> None: |
| 168 |
self.x = 1 |
| 169 |
[out] |
| 170 |
<m.B.x> -> m.B.f |
| 171 |
<m.B> -> m.B |
| 172 |
<n.A.(abstract)> -> <m.B.__init__>, m |
| 173 |
<n.A.__init__> -> <m.B.__init__> |
| 174 |
<n.A.__new__> -> <m.B.__new__> |
| 175 |
<n.A.f> -> m.B.f |
| 176 |
<n.A.g> -> <m.B.g> |
| 177 |
<n.A.x> -> <m.B.x> |
| 178 |
<n.A> -> m, m.B |
| 179 |
<n> -> m |
| 180 |
|
| 181 |
[case testInheritMethod] |
| 182 |
class A: |
| 183 |
def g(self) -> None: pass |
| 184 |
class B(A): |
| 185 |
def f(self) -> None: |
| 186 |
self.g() |
| 187 |
[out] |
| 188 |
<m.A.(abstract)> -> <m.B.__init__>, m |
| 189 |
<m.A.__init__> -> <m.B.__init__> |
| 190 |
<m.A.__new__> -> <m.B.__new__> |
| 191 |
<m.A.f> -> m.B.f |
| 192 |
<m.A.g> -> <m.B.g> |
| 193 |
<m.A> -> m, m.A, m.B |
| 194 |
<m.B.g> -> m.B.f |
| 195 |
<m.B> -> m.B |
| 196 |
|
| 197 |
[case testPackage] |
| 198 |
import a.b |
| 199 |
def f() -> None: |
| 200 |
a.b.g() |
| 201 |
[file a/__init__.py] |
| 202 |
[file a/b.py] |
| 203 |
def g() -> None: pass |
| 204 |
[out] |
| 205 |
<a.b.g> -> m.f |
| 206 |
<a.b> -> m, m.f |
| 207 |
<a> -> m.f |
| 208 |
|
| 209 |
[case testClassInPackage] |
| 210 |
import a.b |
| 211 |
def f(x: a.b.A) -> None: |
| 212 |
x.g() |
| 213 |
x.y |
| 214 |
[file a/__init__.py] |
| 215 |
[file a/b.py] |
| 216 |
class A: |
| 217 |
def g(self) -> None: |
| 218 |
self.y = 1 |
| 219 |
[out] |
| 220 |
<a.b.A.g> -> m.f |
| 221 |
<a.b.A.y> -> m.f |
| 222 |
<a.b.A> -> <m.f>, m.f |
| 223 |
<a.b> -> m |
| 224 |
|
| 225 |
[case testPackage__init__] |
| 226 |
import a |
| 227 |
def f() -> None: |
| 228 |
a.g() |
| 229 |
[file a/__init__.py] |
| 230 |
def g() -> None: pass |
| 231 |
[out] |
| 232 |
<a.g> -> m.f |
| 233 |
<a> -> m, m.f |
| 234 |
|
| 235 |
[case testClassInPackage__init__] |
| 236 |
import a |
| 237 |
def f(x: a.A) -> None: |
| 238 |
x.g() |
| 239 |
x.y |
| 240 |
[file a/__init__.py] |
| 241 |
class A: |
| 242 |
def g(self) -> None: |
| 243 |
self.y = 1 |
| 244 |
[out] |
| 245 |
<a.A.g> -> m.f |
| 246 |
<a.A.y> -> m.f |
| 247 |
<a.A> -> <m.f>, m.f |
| 248 |
<a> -> m |
| 249 |
|
| 250 |
[case testConstructor] |
| 251 |
class A: |
| 252 |
def __init__(self, x: C) -> None: pass |
| 253 |
class C: pass |
| 254 |
def f() -> None: |
| 255 |
A(C()) |
| 256 |
[out] |
| 257 |
<m.A.__init__> -> m.f |
| 258 |
<m.A.__new__> -> m.f |
| 259 |
<m.A> -> m.A, m.f |
| 260 |
<m.C.__init__> -> m.f |
| 261 |
<m.C.__new__> -> m.f |
| 262 |
<m.C> -> <m.A.__init__>, m.A.__init__, m.C, m.f |
| 263 |
|
| 264 |
[case testNonTrivialConstructor] |
| 265 |
class C: |
| 266 |
def __init__(self) -> None: |
| 267 |
self.x = 1 |
| 268 |
[out] |
| 269 |
<m.C.x> -> m.C.__init__ |
| 270 |
<m.C> -> m.C |
| 271 |
|
| 272 |
[case testImportFrom] |
| 273 |
from n import f |
| 274 |
|
| 275 |
def g() -> None: |
| 276 |
f() |
| 277 |
[file n.py] |
| 278 |
def f() -> None: pass |
| 279 |
[out] |
| 280 |
<n.f> -> m, m.g |
| 281 |
<n> -> m |
| 282 |
|
| 283 |
[case testImportFromAs] |
| 284 |
from n import f as ff |
| 285 |
|
| 286 |
def g() -> None: |
| 287 |
ff() |
| 288 |
[file n.py] |
| 289 |
def f() -> None: pass |
| 290 |
[out] |
| 291 |
<n.f> -> m, m.g |
| 292 |
<n> -> m |
| 293 |
|
| 294 |
[case testNestedClass] |
| 295 |
def f() -> None: |
| 296 |
b = A.B() |
| 297 |
b.f() |
| 298 |
class A: |
| 299 |
class B: |
| 300 |
def f(self) -> None: pass |
| 301 |
[out] |
| 302 |
<m.A.B.__init__> -> m.f |
| 303 |
<m.A.B.__new__> -> m.f |
| 304 |
<m.A.B.f> -> m.f |
| 305 |
<m.A.B> -> m.A.B, m.f |
| 306 |
<m.A> -> m.A, m.f |
| 307 |
|
| 308 |
[case testNestedClassAttribute] |
| 309 |
def f() -> None: |
| 310 |
b = A.B() |
| 311 |
b.x |
| 312 |
class A: |
| 313 |
class B: |
| 314 |
def f(self) -> None: |
| 315 |
self.x = 1 |
| 316 |
[out] |
| 317 |
<m.A.B.__init__> -> m.f |
| 318 |
<m.A.B.__new__> -> m.f |
| 319 |
<m.A.B.x> -> m.A.B.f, m.f |
| 320 |
<m.A.B> -> m.A.B, m.f |
| 321 |
<m.A> -> m.A, m.f |
| 322 |
|
| 323 |
[case testNestedClassInAnnotation] |
| 324 |
def f(x: A.B) -> None: |
| 325 |
pass |
| 326 |
class A: |
| 327 |
class B: pass |
| 328 |
[out] |
| 329 |
<m.A.B> -> <m.f>, m.A.B, m.f |
| 330 |
<m.A> -> m.A |
| 331 |
|
| 332 |
[case testNestedClassInAnnotation2] |
| 333 |
def f(x: A.B) -> None: |
| 334 |
x.f() |
| 335 |
class A: |
| 336 |
class B: |
| 337 |
def f(self) -> None: pass |
| 338 |
[out] |
| 339 |
<m.A.B.f> -> m.f |
| 340 |
<m.A.B> -> <m.f>, m.A.B, m.f |
| 341 |
<m.A> -> m.A |
| 342 |
|
| 343 |
[case NestedFunctionType] |
| 344 |
from mod import A, B, C, D |
| 345 |
def outer() -> None: |
| 346 |
def inner(x: A, *args: B, **kwds: C) -> D: |
| 347 |
pass |
| 348 |
[file mod.py] |
| 349 |
class A: pass |
| 350 |
class B: pass |
| 351 |
class C: pass |
| 352 |
class D: pass |
| 353 |
[builtins fixtures/dict.pyi] |
| 354 |
[out] |
| 355 |
<mod.A> -> <m.outer>, m, m.outer |
| 356 |
<mod.B> -> <m.outer>, m, m.outer |
| 357 |
<mod.C> -> <m.outer>, m, m.outer |
| 358 |
<mod.D> -> <m.outer>, m, m.outer |
| 359 |
<mod> -> m |
| 360 |
|
| 361 |
[case NestedFunctionBody] |
| 362 |
from mod import A, B, C |
| 363 |
def outer() -> None: |
| 364 |
def inner() -> None: |
| 365 |
A() |
| 366 |
x: B |
| 367 |
y: C |
| 368 |
y.x |
| 369 |
[file mod.py] |
| 370 |
class A: pass |
| 371 |
class B: pass |
| 372 |
class C: |
| 373 |
x: int |
| 374 |
[builtins fixtures/dict.pyi] |
| 375 |
[out] |
| 376 |
<mod.A.__init__> -> m.outer |
| 377 |
<mod.A.__new__> -> m.outer |
| 378 |
<mod.A> -> m, m.outer |
| 379 |
<mod.B> -> m, m.outer |
| 380 |
<mod.C.x> -> m.outer |
| 381 |
<mod.C> -> m, m.outer |
| 382 |
<mod> -> m |
| 383 |
|
| 384 |
[case testDefaultArgValue] |
| 385 |
def f1(x: int) -> int: pass |
| 386 |
def f2() -> int: pass |
| 387 |
def g(x: int = f1(f2())) -> None: pass |
| 388 |
[out] |
| 389 |
<m.f1> -> m.g |
| 390 |
<m.f2> -> m.g |
| 391 |
|
| 392 |
[case testIsInstance] |
| 393 |
class A: |
| 394 |
def g(self) -> None: pass |
| 395 |
|
| 396 |
def f(x: object) -> None: |
| 397 |
if isinstance(x, A): |
| 398 |
x.g() |
| 399 |
def ff(x: object) -> None: |
| 400 |
if isinstance(x, A): |
| 401 |
pass |
| 402 |
[builtins fixtures/isinstancelist.pyi] |
| 403 |
[out] |
| 404 |
-- The dependencies on the ctor are basically spurious but not a problem |
| 405 |
<m.A.g> -> m.f |
| 406 |
<m.A> -> m.A, m.f, m.ff |
| 407 |
|
| 408 |
[case testUnreachableIsInstance] |
| 409 |
class A: |
| 410 |
x: int |
| 411 |
|
| 412 |
class B: |
| 413 |
x: str |
| 414 |
|
| 415 |
def f(x: A) -> None: |
| 416 |
if isinstance(x, B): |
| 417 |
x.y |
| 418 |
[builtins fixtures/isinstancelist.pyi] |
| 419 |
[out] |
| 420 |
<m.A> -> <m.f>, m.A, m.f |
| 421 |
<m.B> -> m.B, m.f |
| 422 |
|
| 423 |
[case testIsInstanceAdHocIntersectionDeps] |
| 424 |
class A: |
| 425 |
x: int |
| 426 |
|
| 427 |
class B: |
| 428 |
y: int |
| 429 |
|
| 430 |
def f(x: A) -> None: |
| 431 |
if isinstance(x, B): |
| 432 |
x.y |
| 433 |
[builtins fixtures/isinstancelist.pyi] |
| 434 |
[out] |
| 435 |
<m.<subclass of "m.A" and "m.B">.y> -> m.f |
| 436 |
<m.A> -> <m.f>, m.A, m.f |
| 437 |
<m.B> -> m.B, m.f |
| 438 |
|
| 439 |
[case testAttributeWithClassType1] |
| 440 |
from n import A |
| 441 |
|
| 442 |
class B: |
| 443 |
def h(self, z: A) -> None: |
| 444 |
self.z = z |
| 445 |
[file n.py] |
| 446 |
class A: pass |
| 447 |
[out] |
| 448 |
<m.B.z> -> m.B.h |
| 449 |
<m.B> -> m.B |
| 450 |
<n.A> -> <m.B.h>, <m.B.z>, m, m.B.h |
| 451 |
<n> -> m |
| 452 |
|
| 453 |
[case testAttributeWithClassType2] |
| 454 |
from m import A |
| 455 |
|
| 456 |
class B: |
| 457 |
def f(self) -> None: |
| 458 |
self.x = A() |
| 459 |
[file m.py] |
| 460 |
class A: pass |
| 461 |
[out] |
| 462 |
<m.B.x> -> m.B.f |
| 463 |
<m.B> -> m.B |
| 464 |
<m.A.__init__> -> m.B.f |
| 465 |
<m.A.__new__> -> m.B.f |
| 466 |
<m.A> -> <m.B.x>, m, m.B.f |
| 467 |
<m> -> m |
| 468 |
|
| 469 |
[case testAttributeWithClassType3] |
| 470 |
from n import A, x |
| 471 |
|
| 472 |
class B: |
| 473 |
def g(self) -> None: |
| 474 |
self.x = x |
| 475 |
[file n.py] |
| 476 |
class A: pass |
| 477 |
|
| 478 |
x = A() |
| 479 |
[out] |
| 480 |
<m.B.x> -> m.B.g |
| 481 |
<m.B> -> m.B |
| 482 |
<n.A> -> <m.B.x>, m |
| 483 |
<n.x> -> m, m.B.g |
| 484 |
<n> -> m |
| 485 |
|
| 486 |
[case testAttributeWithClassType4] |
| 487 |
from n import A |
| 488 |
|
| 489 |
class B: |
| 490 |
def g(self) -> None: |
| 491 |
self.x: A |
| 492 |
[file n.py] |
| 493 |
class A: pass |
| 494 |
[out] |
| 495 |
<m.B.x> -> m.B.g |
| 496 |
<m.B> -> m.B |
| 497 |
<n.A> -> <m.B.x>, m, m.B.g |
| 498 |
<n> -> m |
| 499 |
|
| 500 |
[case testClassBody] |
| 501 |
def f() -> int: pass |
| 502 |
def g() -> int: pass |
| 503 |
def h() -> int: pass |
| 504 |
|
| 505 |
class A: |
| 506 |
h() |
| 507 |
if f(): |
| 508 |
g() |
| 509 |
[out] |
| 510 |
<m.A> -> m.A |
| 511 |
<m.f> -> m |
| 512 |
<m.g> -> m |
| 513 |
<m.h> -> m |
| 514 |
|
| 515 |
[case testVariableInitializedInClass] |
| 516 |
from n import A |
| 517 |
|
| 518 |
class B: |
| 519 |
x = None # type: A # type: ignore |
| 520 |
[file n.py] |
| 521 |
class A: pass |
| 522 |
[out] |
| 523 |
<m.B> -> m.B |
| 524 |
<n.A> -> <m.B.x>, m |
| 525 |
<n> -> m |
| 526 |
|
| 527 |
[case testVariableAnnotationInClass] |
| 528 |
from n import A |
| 529 |
|
| 530 |
class B: |
| 531 |
x: A |
| 532 |
|
| 533 |
def f(self) -> None: |
| 534 |
y = self.x |
| 535 |
[file n.py] |
| 536 |
class A: pass |
| 537 |
[out] |
| 538 |
<m.B.x> -> m.B.f |
| 539 |
<m.B> -> m.B |
| 540 |
<n.A> -> <m.B.x>, m |
| 541 |
<n> -> m |
| 542 |
|
| 543 |
[case testGlobalVariableInitialized] |
| 544 |
from n import A |
| 545 |
|
| 546 |
x = A() |
| 547 |
[file n.py] |
| 548 |
class A: pass |
| 549 |
[out] |
| 550 |
<m.x> -> m |
| 551 |
<n.A.__init__> -> m |
| 552 |
<n.A.__new__> -> m |
| 553 |
<n.A> -> <m.x>, m |
| 554 |
<n> -> m |
| 555 |
|
| 556 |
[case testGlobalVariableAnnotation] |
| 557 |
from n import A |
| 558 |
|
| 559 |
x: A |
| 560 |
[file n.py] |
| 561 |
class A: pass |
| 562 |
[out] |
| 563 |
<m.x> -> m |
| 564 |
<n.A> -> <m.x>, m |
| 565 |
<n> -> m |
| 566 |
|
| 567 |
[case testProperty] |
| 568 |
class B: pass |
| 569 |
|
| 570 |
class A: |
| 571 |
@property |
| 572 |
def x(self) -> B: pass |
| 573 |
|
| 574 |
def f(a: A) -> None: |
| 575 |
b = a.x |
| 576 |
[builtins fixtures/property.pyi] |
| 577 |
[out] |
| 578 |
<m.A.x> -> m, m.f |
| 579 |
<m.A> -> <m.f>, m.A, m.f |
| 580 |
<m.B> -> <m.A.x>, m.A.x, m.B |
| 581 |
|
| 582 |
[case testUnreachableAssignment] |
| 583 |
from typing import List, Tuple |
| 584 |
|
| 585 |
def f() -> None: pass |
| 586 |
|
| 587 |
class C: |
| 588 |
def __init__(self, x: int) -> None: |
| 589 |
if isinstance(x, int): |
| 590 |
self.y = 1 |
| 591 |
else: |
| 592 |
self.y = f() |
| 593 |
[builtins fixtures/isinstancelist.pyi] |
| 594 |
[out] |
| 595 |
<m.C.y> -> m.C.__init__ |
| 596 |
<m.C> -> m.C |
| 597 |
<m.f> -> m.C.__init__ |
| 598 |
|
| 599 |
[case testPartialNoneTypeAttributeCrash1] |
| 600 |
# flags: --no-local-partial-types |
| 601 |
class C: pass |
| 602 |
|
| 603 |
class A: |
| 604 |
x = None |
| 605 |
|
| 606 |
def f(self) -> None: |
| 607 |
self.x = C() |
| 608 |
[out] |
| 609 |
<m.A.x> -> m.A.f |
| 610 |
<m.A> -> m.A |
| 611 |
<m.C.__init__> -> m.A.f |
| 612 |
<m.C.__new__> -> m.A.f |
| 613 |
<m.C> -> <m.A.x>, m.A.f, m.C |
| 614 |
|
| 615 |
[case testPartialNoneTypeAttributeCrash2] |
| 616 |
# flags: --no-local-partial-types |
| 617 |
class C: pass |
| 618 |
|
| 619 |
class A: |
| 620 |
x = None |
| 621 |
|
| 622 |
def f(self) -> None: |
| 623 |
self.x = C() |
| 624 |
[out] |
| 625 |
<m.A.x> -> m.A.f |
| 626 |
<m.A> -> m.A |
| 627 |
<m.C.__init__> -> m.A.f |
| 628 |
<m.C.__new__> -> m.A.f |
| 629 |
<m.C> -> <m.A.x>, m.A.f, m.C |
| 630 |
|
| 631 |
[case testRelativeImport] |
| 632 |
import pkg # Magic package name in test runner |
| 633 |
[file pkg/__init__.py] |
| 634 |
from . import mod |
| 635 |
from .a import x |
| 636 |
[file pkg/mod.py] |
| 637 |
from . import a |
| 638 |
[file pkg/a.py] |
| 639 |
x = 1 |
| 640 |
[out] |
| 641 |
<pkg.a.x> -> pkg |
| 642 |
<pkg.a> -> pkg, pkg.mod |
| 643 |
<pkg.mod> -> pkg |
| 644 |
<pkg> -> m, pkg, pkg.mod |
| 645 |
|
| 646 |
[case testTypedDict] |
| 647 |
from typing import TypedDict |
| 648 |
Point = TypedDict('Point', {'x': int, 'y': int}) |
| 649 |
p = Point(dict(x=42, y=1337)) |
| 650 |
def foo(x: Point) -> int: |
| 651 |
return x['x'] + x['y'] |
| 652 |
[builtins fixtures/dict.pyi] |
| 653 |
[typing fixtures/typing-typeddict.pyi] |
| 654 |
[out] |
| 655 |
<m.Point.__init__> -> m |
| 656 |
<m.Point.__new__> -> m |
| 657 |
<m.Point> -> <m.foo>, <m.p>, m, m.foo |
| 658 |
<m.p> -> m |
| 659 |
|
| 660 |
[case testTypedDict2] |
| 661 |
from typing import TypedDict |
| 662 |
class A: pass |
| 663 |
Point = TypedDict('Point', {'x': int, 'y': A}) |
| 664 |
p = Point(dict(x=42, y=A())) |
| 665 |
def foo(x: Point) -> int: |
| 666 |
return x['x'] |
| 667 |
[builtins fixtures/dict.pyi] |
| 668 |
[typing fixtures/typing-typeddict.pyi] |
| 669 |
[out] |
| 670 |
<m.A.__init__> -> m |
| 671 |
<m.A.__new__> -> m |
| 672 |
<m.A> -> <m.Point>, <m.foo>, <m.p>, m, m.A, m.foo |
| 673 |
<m.Point.__init__> -> m |
| 674 |
<m.Point.__new__> -> m |
| 675 |
<m.Point> -> <m.foo>, <m.p>, m, m.foo |
| 676 |
<m.p> -> m |
| 677 |
|
| 678 |
[case testTypedDict3] |
| 679 |
from typing import TypedDict |
| 680 |
class A: pass |
| 681 |
class Point(TypedDict): |
| 682 |
x: int |
| 683 |
y: A |
| 684 |
p = Point(dict(x=42, y=A())) |
| 685 |
def foo(x: Point) -> int: |
| 686 |
return x['x'] |
| 687 |
[builtins fixtures/dict.pyi] |
| 688 |
[typing fixtures/typing-typeddict.pyi] |
| 689 |
[out] |
| 690 |
<m.A.__init__> -> m |
| 691 |
<m.A.__new__> -> m |
| 692 |
<m.A> -> <m.Point>, <m.foo>, <m.p>, m, m.A, m.foo |
| 693 |
<m.Point.__init__> -> m |
| 694 |
<m.Point.__new__> -> m |
| 695 |
<m.Point> -> <m.foo>, <m.p>, m, m.Point, m.foo |
| 696 |
<m.p> -> m |
| 697 |
|
| 698 |
[case testImportStar] |
| 699 |
from a import * |
| 700 |
[file a.py] |
| 701 |
x = 0 |
| 702 |
[out] |
| 703 |
<a[wildcard]> -> m |
| 704 |
|
| 705 |
[case testDecoratorDepsMod] |
| 706 |
import mod |
| 707 |
|
| 708 |
@mod.deca |
| 709 |
@mod.decb(mod.C()) |
| 710 |
def func(x: int) -> int: |
| 711 |
pass |
| 712 |
[file mod.py] |
| 713 |
from typing import Callable, TypeVar |
| 714 |
F = TypeVar('F', bound=Callable) |
| 715 |
|
| 716 |
def deca(func: Callable[[int], int]) -> Callable[[str], str]: |
| 717 |
pass |
| 718 |
def decb(arg: C) -> Callable[[F], F]: |
| 719 |
pass |
| 720 |
class C: |
| 721 |
pass |
| 722 |
[out] |
| 723 |
<m.func> -> m |
| 724 |
<mod.C.__init__> -> m |
| 725 |
<mod.C.__new__> -> m |
| 726 |
<mod.C> -> m |
| 727 |
<mod.deca> -> m |
| 728 |
<mod.decb> -> m |
| 729 |
<mod> -> m |
| 730 |
|
| 731 |
[case testDecoratorDepsFunc] |
| 732 |
import mod |
| 733 |
|
| 734 |
def outer() -> None: |
| 735 |
@mod.deca |
| 736 |
@mod.decb(mod.C()) |
| 737 |
def func(x: int) -> int: |
| 738 |
pass |
| 739 |
[file mod.py] |
| 740 |
from typing import Callable, TypeVar |
| 741 |
F = TypeVar('F', bound=Callable) |
| 742 |
|
| 743 |
def deca(func: Callable[[int], int]) -> Callable[[str], str]: |
| 744 |
pass |
| 745 |
def decb(arg: C) -> Callable[[F], F]: |
| 746 |
pass |
| 747 |
class C: |
| 748 |
pass |
| 749 |
[out] |
| 750 |
<mod.C.__init__> -> m.outer |
| 751 |
<mod.C.__new__> -> m.outer |
| 752 |
<mod.C> -> m.outer |
| 753 |
<mod.deca> -> m.outer |
| 754 |
<mod.decb> -> m.outer |
| 755 |
<mod> -> m, m.outer |
| 756 |
|
| 757 |
[case testDecoratorDepsDeepNested] |
| 758 |
import mod |
| 759 |
|
| 760 |
def outer() -> None: |
| 761 |
def inner() -> None: |
| 762 |
@mod.dec |
| 763 |
def func(x: int) -> int: |
| 764 |
pass |
| 765 |
[file mod.py] |
| 766 |
from typing import Callable |
| 767 |
def dec(func: Callable[[int], int]) -> Callable[[str], str]: |
| 768 |
pass |
| 769 |
[out] |
| 770 |
<mod.dec> -> m.outer |
| 771 |
<mod> -> m, m.outer |
| 772 |
|
| 773 |
[case testDecoratorDepsNestedClass] |
| 774 |
import mod |
| 775 |
|
| 776 |
class Outer: |
| 777 |
class Inner: |
| 778 |
c = mod.C() |
| 779 |
@c.dec |
| 780 |
def func(self, x: int) -> int: |
| 781 |
pass |
| 782 |
[file mod.py] |
| 783 |
from typing import Callable |
| 784 |
class C: |
| 785 |
def dec(self, func: Callable[..., int]) -> Callable[..., str]: |
| 786 |
pass |
| 787 |
[out] |
| 788 |
<m.Outer.Inner.func> -> m |
| 789 |
<m.Outer.Inner> -> m.Outer.Inner |
| 790 |
<m.Outer> -> m.Outer |
| 791 |
<mod.C.__init__> -> m |
| 792 |
<mod.C.__new__> -> m |
| 793 |
<mod.C.dec> -> m |
| 794 |
<mod.C> -> <m.Outer.Inner.c>, m |
| 795 |
<mod> -> m |
| 796 |
|
| 797 |
[case testDecoratorDepsClassInFunction] |
| 798 |
import mod |
| 799 |
|
| 800 |
def outer() -> None: |
| 801 |
class Inner: |
| 802 |
c = mod.C() |
| 803 |
@c.dec |
| 804 |
def func(self, x: int) -> int: |
| 805 |
pass |
| 806 |
[file mod.py] |
| 807 |
from typing import Callable |
| 808 |
class C: |
| 809 |
def dec(self, func: Callable[..., int]) -> Callable[..., str]: |
| 810 |
pass |
| 811 |
[out] |
| 812 |
<m.outer> -> m.outer |
| 813 |
<mod.C.__init__> -> m.outer |
| 814 |
<mod.C.__new__> -> m.outer |
| 815 |
<mod.C.dec> -> m.outer |
| 816 |
<mod.C> -> <m.outer.c>, m.outer |
| 817 |
<mod> -> m, m.outer |
| 818 |
|
| 819 |
[case DecoratorDepsMethod] |
| 820 |
import mod |
| 821 |
|
| 822 |
class D: |
| 823 |
@mod.deca |
| 824 |
@mod.decb(mod.C()) |
| 825 |
def func(self, x: int) -> int: |
| 826 |
pass |
| 827 |
[file mod.py] |
| 828 |
from typing import Callable, TypeVar |
| 829 |
F = TypeVar('F', bound=Callable) |
| 830 |
|
| 831 |
def deca(func: Callable[..., int]) -> Callable[..., str]: |
| 832 |
pass |
| 833 |
def decb(arg: C) -> Callable[[F], F]: |
| 834 |
pass |
| 835 |
class C: |
| 836 |
pass |
| 837 |
[out] |
| 838 |
<m.D.func> -> m |
| 839 |
<m.D> -> m.D |
| 840 |
<mod.C.__init__> -> m |
| 841 |
<mod.C.__new__> -> m |
| 842 |
<mod.C> -> m |
| 843 |
<mod.deca> -> m |
| 844 |
<mod.decb> -> m |
| 845 |
<mod> -> m |
| 846 |
|
| 847 |
[case testMissingModuleClass1] |
| 848 |
from b import A # type: ignore |
| 849 |
def f(x: A) -> None: |
| 850 |
x.foo() |
| 851 |
[out] |
| 852 |
<m.A> -> <m.f>, m.f |
| 853 |
<b.A> -> m |
| 854 |
<b> -> m |
| 855 |
|
| 856 |
[case testMissingModuleClass2] |
| 857 |
from p.b import A # type: ignore |
| 858 |
def f(x: A) -> None: |
| 859 |
x.foo() |
| 860 |
[out] |
| 861 |
<m.A> -> <m.f>, m.f |
| 862 |
<p.b.A> -> m |
| 863 |
<p.b> -> m |
| 864 |
|
| 865 |
[case testIgnoredMissingModuleAttribute] |
| 866 |
import a |
| 867 |
a.x # type: ignore |
| 868 |
|
| 869 |
import b.c |
| 870 |
b.c.x # type: ignore |
| 871 |
|
| 872 |
from b import c |
| 873 |
c.y # type: ignore |
| 874 |
[file a.py] |
| 875 |
[file b/__init__.py] |
| 876 |
[file b/c.py] |
| 877 |
[builtins fixtures/module.pyi] |
| 878 |
[out] |
| 879 |
<a.x> -> m |
| 880 |
<a> -> m |
| 881 |
<b.c.x> -> m |
| 882 |
<b.c.y> -> m |
| 883 |
<b.c> -> m |
| 884 |
<b> -> m |
| 885 |
<types.ModuleType.__await__> -> <types.ModuleType> |
| 886 |
<types.ModuleType> -> typing.Awaitable |
| 887 |
|
| 888 |
[case testIgnoredMissingInstanceAttribute] |
| 889 |
from a import C |
| 890 |
C().x # type: ignore |
| 891 |
[file a.py] |
| 892 |
class C: pass |
| 893 |
[out] |
| 894 |
<a.C.__await__> -> <a.C> |
| 895 |
<a.C.__init__> -> m |
| 896 |
<a.C.__new__> -> m |
| 897 |
<a.C.x> -> m |
| 898 |
<a.C> -> m, typing.Awaitable |
| 899 |
<a> -> m |
| 900 |
|
| 901 |
[case testIgnoredMissingClassAttribute] |
| 902 |
from a import C |
| 903 |
C.x # type: ignore |
| 904 |
[file a.py] |
| 905 |
class C: pass |
| 906 |
[out] |
| 907 |
<a.C.x> -> m |
| 908 |
<a.C> -> m |
| 909 |
<a> -> m |
| 910 |
|
| 911 |
[case testDepsFromOverloadMod] |
| 912 |
# __dump_all__ |
| 913 |
import mod |
| 914 |
x = mod.f |
| 915 |
[file mod.py] |
| 916 |
from typing import overload, Any |
| 917 |
import submod |
| 918 |
@overload |
| 919 |
def f(x: int) -> submod.A: pass |
| 920 |
@overload |
| 921 |
def f(x: str) -> submod.B: pass |
| 922 |
def f(x) -> Any: |
| 923 |
y: submod.C |
| 924 |
y.x |
| 925 |
[file submod.py] |
| 926 |
class A: pass |
| 927 |
class B: pass |
| 928 |
class C: |
| 929 |
x: D |
| 930 |
class D: pass |
| 931 |
[out] |
| 932 |
<m.x> -> m |
| 933 |
<mod.f> -> m |
| 934 |
<mod> -> m |
| 935 |
<submod.A> -> <m.x>, <mod.f>, mod.f, submod.A |
| 936 |
<submod.B> -> <m.x>, <mod.f>, mod.f, submod.B |
| 937 |
<submod.C.x> -> mod.f |
| 938 |
<submod.C> -> mod.f, submod.C |
| 939 |
<submod.D> -> <submod.C.x>, submod, submod.D |
| 940 |
<submod> -> mod |
| 941 |
|
| 942 |
[case testDepsFromOverloadFunc] |
| 943 |
import mod |
| 944 |
def f() -> None: |
| 945 |
x = mod.f |
| 946 |
[file mod.py] |
| 947 |
from typing import overload |
| 948 |
@overload |
| 949 |
def f(x: int) -> None: pass |
| 950 |
@overload |
| 951 |
def f(x: str) -> str: pass |
| 952 |
def f(x): |
| 953 |
pass |
| 954 |
[out] |
| 955 |
<mod.f> -> m.f |
| 956 |
<mod> -> m, m.f |
| 957 |
|
| 958 |
[case testDepsToOverloadMod] |
| 959 |
from typing import overload, Any |
| 960 |
import mod |
| 961 |
@overload |
| 962 |
def f(x: int) -> None: pass |
| 963 |
@overload |
| 964 |
def f(x: str) -> str: pass |
| 965 |
def f(x: Any) -> Any: |
| 966 |
mod.g() |
| 967 |
[file mod.py] |
| 968 |
def g() -> int: |
| 969 |
pass |
| 970 |
[out] |
| 971 |
<mod.g> -> m.f |
| 972 |
<mod> -> m, m.f |
| 973 |
|
| 974 |
[case testDepsToOverloadFunc] |
| 975 |
from typing import overload, Any |
| 976 |
import mod |
| 977 |
def outer() -> None: |
| 978 |
@overload |
| 979 |
def f(x: int) -> mod.A: pass |
| 980 |
@overload |
| 981 |
def f(x: str) -> mod.B: pass |
| 982 |
def f(x: Any) -> Any: |
| 983 |
mod.g() |
| 984 |
[file mod.py] |
| 985 |
def g() -> int: |
| 986 |
pass |
| 987 |
class A: pass |
| 988 |
class B: pass |
| 989 |
[out] |
| 990 |
<mod.A> -> <m.outer>, m.outer |
| 991 |
<mod.B> -> <m.outer>, m.outer |
| 992 |
<mod.g> -> m.outer |
| 993 |
<mod> -> m, m.outer |
| 994 |
|
| 995 |
[case testDepsFromOverloadToOverload] |
| 996 |
from typing import overload, Any |
| 997 |
import mod |
| 998 |
def outer() -> None: |
| 999 |
@overload |
| 1000 |
def f(x: int) -> None: pass |
| 1001 |
@overload |
| 1002 |
def f(x: str) -> str: pass |
| 1003 |
def f(x: Any) -> Any: |
| 1004 |
mod.g(str()) |
| 1005 |
[file mod.py] |
| 1006 |
from typing import overload |
| 1007 |
@overload |
| 1008 |
def g(x: int) -> None: pass |
| 1009 |
@overload |
| 1010 |
def g(x: str) -> str: pass |
| 1011 |
def g(x): |
| 1012 |
pass |
| 1013 |
[out] |
| 1014 |
<mod.g> -> m.outer |
| 1015 |
<mod> -> m, m.outer |
| 1016 |
|
| 1017 |
[case testDepsFromOverloadToOverloadDefaultClass] |
| 1018 |
from typing import overload, Any |
| 1019 |
import mod |
| 1020 |
class Outer: |
| 1021 |
@overload |
| 1022 |
def f(self, x: int) -> None: pass |
| 1023 |
@overload |
| 1024 |
def f(self, x: str, cb=mod.g) -> str: pass |
| 1025 |
def f(self, *args: Any, **kwargs: Any) -> Any: |
| 1026 |
pass |
| 1027 |
[file mod.py] |
| 1028 |
from typing import overload |
| 1029 |
@overload |
| 1030 |
def g(x: int) -> None: pass |
| 1031 |
@overload |
| 1032 |
def g(x: str) -> str: pass |
| 1033 |
def g(x): |
| 1034 |
pass |
| 1035 |
[builtins fixtures/dict.pyi] |
| 1036 |
[out] |
| 1037 |
<m.Outer> -> m.Outer |
| 1038 |
<mod.g> -> m.Outer.f |
| 1039 |
<mod> -> m, m.Outer.f |
| 1040 |
|
| 1041 |
[case testDepsFromOverloadToOverloadDefaultNested] |
| 1042 |
from typing import overload, Any |
| 1043 |
import mod |
| 1044 |
def outer() -> None: |
| 1045 |
@overload |
| 1046 |
def f(x: int) -> None: pass |
| 1047 |
@overload |
| 1048 |
def f(x: str, cb=mod.g) -> str: pass |
| 1049 |
def f(*args: Any, **kwargs: Any) -> Any: |
| 1050 |
pass |
| 1051 |
[file mod.py] |
| 1052 |
from typing import overload |
| 1053 |
@overload |
| 1054 |
def g(x: int) -> None: pass |
| 1055 |
@overload |
| 1056 |
def g(x: str) -> str: pass |
| 1057 |
def g(x): |
| 1058 |
pass |
| 1059 |
[builtins fixtures/dict.pyi] |
| 1060 |
[out] |
| 1061 |
<mod.g> -> m.outer |
| 1062 |
<mod> -> m, m.outer |
| 1063 |
|
| 1064 |
[case testDepsToOverloadGeneric] |
| 1065 |
# __dump_all__ |
| 1066 |
import mod |
| 1067 |
from typing import overload, Any |
| 1068 |
@overload |
| 1069 |
def f(x: mod.TA) -> mod.TA: pass |
| 1070 |
@overload |
| 1071 |
def f(x: mod.TB, y: int) -> mod.TB: pass |
| 1072 |
def f(*args: Any, **kwargs: Any) -> Any: |
| 1073 |
pass |
| 1074 |
[file mod.py] |
| 1075 |
from typing import TypeVar |
| 1076 |
import submod |
| 1077 |
TA = TypeVar('TA', submod.A, submod.B) |
| 1078 |
TB = TypeVar('TB', bound=submod.C) |
| 1079 |
[file submod.py] |
| 1080 |
class A: pass |
| 1081 |
class B: pass |
| 1082 |
class C: pass |
| 1083 |
[builtins fixtures/dict.pyi] |
| 1084 |
[out] |
| 1085 |
<mod.TA> -> <m.f>, m.f |
| 1086 |
<mod.TB> -> <m.f>, m.f |
| 1087 |
<mod> -> m |
| 1088 |
<submod.A> -> <m.f>, <mod.TA>, m.f, mod, submod.A |
| 1089 |
<submod.B> -> <m.f>, <mod.TA>, m.f, mod, submod.B |
| 1090 |
<submod.C> -> <m.f>, <mod.TB>, m.f, mod, submod.C |
| 1091 |
<submod> -> mod |
| 1092 |
|
| 1093 |
[case testDepsOverloadBothExternalAndImplementationType] |
| 1094 |
import mod |
| 1095 |
from typing import overload |
| 1096 |
@overload |
| 1097 |
def f(x: mod.A) -> mod.A: pass |
| 1098 |
@overload |
| 1099 |
def f(x: mod.B) -> mod.B: pass |
| 1100 |
def f(x: mod.Base) -> mod.Base: |
| 1101 |
pass |
| 1102 |
[file mod.py] |
| 1103 |
class Base: |
| 1104 |
pass |
| 1105 |
class A(Base): |
| 1106 |
pass |
| 1107 |
class B(Base): |
| 1108 |
pass |
| 1109 |
[out] |
| 1110 |
<mod.A> -> <m.f>, m.f |
| 1111 |
<mod.B> -> <m.f>, m.f |
| 1112 |
<mod.Base> -> <m.f>, m.f |
| 1113 |
<mod> -> m |
| 1114 |
|
| 1115 |
[case testCustomIterator] |
| 1116 |
class A: |
| 1117 |
def __iter__(self) -> B: pass |
| 1118 |
class B: |
| 1119 |
def __iter__(self) -> B: pass |
| 1120 |
def __next__(self) -> C: pass |
| 1121 |
class C: |
| 1122 |
pass |
| 1123 |
def f() -> None: |
| 1124 |
for x in A(): pass |
| 1125 |
[out] |
| 1126 |
<m.A.__getitem__> -> m.f |
| 1127 |
<m.A.__init__> -> m.f |
| 1128 |
<m.A.__iter__> -> m.f |
| 1129 |
<m.A.__new__> -> m.f |
| 1130 |
<m.A> -> m.A, m.f |
| 1131 |
<m.B.__next__> -> m.f |
| 1132 |
<m.B> -> <m.A.__iter__>, <m.B.__iter__>, m.A.__iter__, m.B, m.B.__iter__ |
| 1133 |
<m.C> -> <m.B.__next__>, m.B.__next__, m.C |
| 1134 |
|
| 1135 |
[case testDepsLiskovClass] |
| 1136 |
from mod import A, C |
| 1137 |
class D(C): |
| 1138 |
x: A |
| 1139 |
[file mod.py] |
| 1140 |
class C: |
| 1141 |
x: B |
| 1142 |
class B: |
| 1143 |
pass |
| 1144 |
class A(B): |
| 1145 |
pass |
| 1146 |
[out] |
| 1147 |
<m.D.x> -> m |
| 1148 |
<m.D> -> m.D |
| 1149 |
<mod.A> -> <m.D.x>, m |
| 1150 |
<mod.C.(abstract)> -> <m.D.__init__>, m |
| 1151 |
<mod.C.__init__> -> <m.D.__init__> |
| 1152 |
<mod.C.__new__> -> <m.D.__new__> |
| 1153 |
<mod.C.x> -> <m.D.x> |
| 1154 |
<mod.C> -> m, m.D |
| 1155 |
<mod> -> m |
| 1156 |
|
| 1157 |
[case testDepsLiskovMethod] |
| 1158 |
from mod import A, C |
| 1159 |
class D(C): |
| 1160 |
def __init__(self) -> None: |
| 1161 |
self.x: A |
| 1162 |
[file mod.py] |
| 1163 |
class C: |
| 1164 |
def __init__(self) -> None: |
| 1165 |
self.x: B |
| 1166 |
class B: |
| 1167 |
pass |
| 1168 |
class A(B): |
| 1169 |
pass |
| 1170 |
[out] |
| 1171 |
<m.D.x> -> m.D.__init__ |
| 1172 |
<m.D> -> m.D |
| 1173 |
<mod.A> -> <m.D.x>, m, m.D.__init__ |
| 1174 |
<mod.C.(abstract)> -> <m.D.__init__>, m |
| 1175 |
<mod.C.__init__> -> <m.D.__init__>, m.D.__init__ |
| 1176 |
<mod.C.__new__> -> <m.D.__new__> |
| 1177 |
<mod.C.x> -> <m.D.x> |
| 1178 |
<mod.C> -> m, m.D |
| 1179 |
<mod> -> m |
| 1180 |
|
| 1181 |
[case testIndexedStarLvalue] |
| 1182 |
from typing import List, Tuple |
| 1183 |
|
| 1184 |
class B: |
| 1185 |
def __setitem__(self, i: int, v: List[str]) -> None: pass |
| 1186 |
|
| 1187 |
def g() -> Tuple[int, str, str]: pass |
| 1188 |
|
| 1189 |
def f(b: B) -> None: |
| 1190 |
a, *b[0] = g() |
| 1191 |
[builtins fixtures/list.pyi] |
| 1192 |
[out] |
| 1193 |
<m.B.__getitem__> -> m.f |
| 1194 |
<m.B.__setitem__> -> m.f |
| 1195 |
<m.B> -> <m.f>, m.B, m.f |
| 1196 |
<m.g> -> m.f |
| 1197 |
|
| 1198 |
[case testLogicalDecorator] |
| 1199 |
# flags: --logical-deps |
| 1200 |
from mod import dec |
| 1201 |
@dec |
| 1202 |
def f() -> None: |
| 1203 |
pass |
| 1204 |
[file mod.py] |
| 1205 |
from typing import Callable |
| 1206 |
def dec(f: Callable[[], None]) -> Callable[[], None]: |
| 1207 |
pass |
| 1208 |
[out] |
| 1209 |
<mod.dec> -> <m.f>, m |
| 1210 |
|
| 1211 |
[case testLogicalDecoratorWithArgs] |
| 1212 |
# flags: --logical-deps |
| 1213 |
from mod import dec |
| 1214 |
@dec(str()) |
| 1215 |
def f() -> None: |
| 1216 |
pass |
| 1217 |
[file mod.py] |
| 1218 |
from typing import Callable |
| 1219 |
def dec(arg: str) -> Callable[[Callable[[], None]], Callable[[], None]]: |
| 1220 |
pass |
| 1221 |
[out] |
| 1222 |
<mod.dec> -> <m.f>, m |
| 1223 |
|
| 1224 |
[case testLogicalDecoratorMember] |
| 1225 |
# flags: --logical-deps |
| 1226 |
import mod |
| 1227 |
@mod.dec |
| 1228 |
def f() -> None: |
| 1229 |
pass |
| 1230 |
[file mod.py] |
| 1231 |
from typing import Callable |
| 1232 |
def dec(f: Callable[[], None]) -> Callable[[], None]: |
| 1233 |
pass |
| 1234 |
[out] |
| 1235 |
<mod.dec> -> <m.f>, m |
| 1236 |
<mod> -> m |
| 1237 |
|
| 1238 |
[case testLogicalDefinition] |
| 1239 |
# flags: --logical-deps |
| 1240 |
from mod import func |
| 1241 |
b = func() |
| 1242 |
[file mod.py] |
| 1243 |
def func() -> int: |
| 1244 |
pass |
| 1245 |
[out] |
| 1246 |
<m.b> -> m |
| 1247 |
<mod.func> -> <m.b>, m |
| 1248 |
|
| 1249 |
[case testLogicalDefinitionIrrelevant] |
| 1250 |
# flags: --logical-deps |
| 1251 |
from mod import func |
| 1252 |
def outer() -> None: |
| 1253 |
a = func() |
| 1254 |
b: int = func() |
| 1255 |
c = int() |
| 1256 |
c = func() |
| 1257 |
[file mod.py] |
| 1258 |
def func() -> int: |
| 1259 |
pass |
| 1260 |
[out] |
| 1261 |
<m.b> -> m |
| 1262 |
<m.c> -> m |
| 1263 |
<mod.func> -> m, m.outer |
| 1264 |
|
| 1265 |
[case testLogicalDefinitionMember] |
| 1266 |
# flags: --logical-deps |
| 1267 |
import mod |
| 1268 |
b = mod.func() |
| 1269 |
[file mod.py] |
| 1270 |
def func() -> int: |
| 1271 |
pass |
| 1272 |
[out] |
| 1273 |
<m.b> -> m |
| 1274 |
<mod.func> -> <m.b>, m |
| 1275 |
<mod> -> m |
| 1276 |
|
| 1277 |
[case testLogicalDefinitionClass] |
| 1278 |
# flags: --logical-deps |
| 1279 |
from mod import Cls |
| 1280 |
b = Cls() |
| 1281 |
[file mod.py] |
| 1282 |
class Base: |
| 1283 |
def __init__(self) -> None: pass |
| 1284 |
class Cls(Base): pass |
| 1285 |
[out] |
| 1286 |
<m.b> -> m |
| 1287 |
<mod.Base.__init__> -> <m.b> |
| 1288 |
<mod.Cls.__init__> -> m |
| 1289 |
<mod.Cls.__new__> -> m |
| 1290 |
<mod.Cls> -> <m.b>, m |
| 1291 |
|
| 1292 |
[case testLogicalBaseAttribute] |
| 1293 |
# flags: --logical-deps |
| 1294 |
from mod import C |
| 1295 |
class D(C): |
| 1296 |
x: int |
| 1297 |
[file mod.py] |
| 1298 |
class C: |
| 1299 |
x: int |
| 1300 |
y: int |
| 1301 |
[out] |
| 1302 |
<m.D.x> -> m |
| 1303 |
<m.D> -> m.D |
| 1304 |
<mod.C.x> -> <m.D.x> |
| 1305 |
<mod.C> -> m, m.D |
| 1306 |
|
| 1307 |
[case testLogicalIgnoredImport1] |
| 1308 |
# flags: --logical-deps --ignore-missing-imports |
| 1309 |
import foo |
| 1310 |
def f() -> None: |
| 1311 |
foo.x |
| 1312 |
[out] |
| 1313 |
<foo.x> -> m.f |
| 1314 |
<foo> -> m, m.f |
| 1315 |
|
| 1316 |
[case testLogicalIgnoredImport2] |
| 1317 |
# flags: --logical-deps --ignore-missing-imports |
| 1318 |
import foo.bar |
| 1319 |
import a.b.c.d |
| 1320 |
def f() -> None: |
| 1321 |
foo.bar.x |
| 1322 |
foo.bar.x.y |
| 1323 |
a.b.c.d.e |
| 1324 |
[out] |
| 1325 |
<a.b.c.d.e> -> m.f |
| 1326 |
<a.b.c.d> -> m, m.f |
| 1327 |
<a.b.c> -> m.f |
| 1328 |
<a.b> -> m.f |
| 1329 |
<a> -> m.f |
| 1330 |
<foo.bar.x.y> -> m.f |
| 1331 |
<foo.bar.x> -> m.f |
| 1332 |
<foo.bar> -> m, m.f |
| 1333 |
<foo> -> m.f |
| 1334 |
|
| 1335 |
[case testLogicalIgnoredFromImport] |
| 1336 |
# flags: --logical-deps --ignore-missing-imports |
| 1337 |
from foo.bar import f, C |
| 1338 |
def g() -> None: |
| 1339 |
f() |
| 1340 |
C.ff() |
| 1341 |
def gg(x: C) -> None: |
| 1342 |
z = x.y |
| 1343 |
z.zz |
| 1344 |
[out] |
| 1345 |
<foo.bar.C.ff> -> m.g |
| 1346 |
<foo.bar.C.y> -> m.gg |
| 1347 |
<foo.bar.C> -> <m.gg>, m.g, m.gg |
| 1348 |
<foo.bar.f> -> m.g |
| 1349 |
|
| 1350 |
[case testLogical__init__] |
| 1351 |
# flags: --logical-deps |
| 1352 |
class A: |
| 1353 |
def __init__(self) -> None: pass |
| 1354 |
class B(A): pass |
| 1355 |
class C(B): pass |
| 1356 |
class D(A): |
| 1357 |
def __init__(self, x: int) -> None: pass |
| 1358 |
def f() -> None: |
| 1359 |
A() |
| 1360 |
def g() -> None: |
| 1361 |
C() |
| 1362 |
def h() -> None: |
| 1363 |
D(1) |
| 1364 |
[out] |
| 1365 |
<m.A.__init__> -> m.f |
| 1366 |
<m.A.__new__> -> m.f |
| 1367 |
<m.A> -> m, m.A, m.B, m.D, m.f |
| 1368 |
<m.B> -> m, m.B, m.C |
| 1369 |
<m.C.__init__> -> m.g |
| 1370 |
<m.C.__new__> -> m.g |
| 1371 |
<m.C> -> m.C, m.g |
| 1372 |
<m.D.__init__> -> m.h |
| 1373 |
<m.D.__new__> -> m.h |
| 1374 |
<m.D> -> m.D, m.h |
| 1375 |
|
| 1376 |
[case testDataclassDeps] |
| 1377 |
from dataclasses import dataclass |
| 1378 |
|
| 1379 |
Z = int |
| 1380 |
|
| 1381 |
@dataclass |
| 1382 |
class A: |
| 1383 |
x: Z |
| 1384 |
|
| 1385 |
@dataclass |
| 1386 |
class B(A): |
| 1387 |
y: int |
| 1388 |
[builtins fixtures/dataclasses.pyi] |
| 1389 |
|
| 1390 |
[out] |
| 1391 |
<m.A.(abstract)> -> <m.B.__init__>, m |
| 1392 |
<m.A.__dataclass_fields__> -> <m.B.__dataclass_fields__> |
| 1393 |
<m.A.__init__> -> <m.B.__init__>, m.B.__init__ |
| 1394 |
<m.A.__match_args__> -> <m.B.__match_args__> |
| 1395 |
<m.A.__mypy-replace> -> <m.B.__mypy-replace>, m, m.B.__mypy-replace |
| 1396 |
<m.A.__new__> -> <m.B.__new__> |
| 1397 |
<m.A.x> -> <m.B.x> |
| 1398 |
<m.A.y> -> <m.B.y> |
| 1399 |
<m.A> -> m, m.A, m.B |
| 1400 |
<m.A[wildcard]> -> m |
| 1401 |
<m.B.__mypy-replace> -> m |
| 1402 |
<m.B.y> -> m |
| 1403 |
<m.B> -> m.B |
| 1404 |
<m.Z> -> m |
| 1405 |
<dataclasses.dataclass> -> m |
| 1406 |
<dataclasses> -> m |
| 1407 |
|
| 1408 |
[case testPEP695TypeAliasDeps] |
| 1409 |
# flags: --python-version=3.12 |
| 1410 |
from a import C, E |
| 1411 |
type A = C |
| 1412 |
type A2 = A |
| 1413 |
type A3 = E |
| 1414 |
[file a.py] |
| 1415 |
class C: pass |
| 1416 |
class D: pass |
| 1417 |
type E = D |
| 1418 |
[out] |
| 1419 |
<m.A2> -> m |
| 1420 |
<m.A3> -> m |
| 1421 |
<m.A> -> m |
| 1422 |
<a.C.__init__> -> m |
| 1423 |
<a.C.__new__> -> m |
| 1424 |
<a.C> -> m |
| 1425 |
<a.E> -> m |
| 1426 |
<a> -> m |
| 1427 |
[builtins fixtures/tuple.pyi] |
| 1428 |
[typing fixtures/typing-full.pyi] |