| 1 |
-- Checks for incremental mode (see testcheck.py). |
| 2 |
-- Each test is run at least twice, once with a cold cache, once with a warm cache. |
| 3 |
-- Before the tests are run again, in step N any *.py.N files are copied to |
| 4 |
-- *.py. There are at least two runs; more as long as there are *.py.N files. |
| 5 |
-- |
| 6 |
-- You can add an empty section like `[delete mod.py.2]` to delete `mod.py` |
| 7 |
-- before the second run. |
| 8 |
-- |
| 9 |
-- Errors expected in the first run should be in the `[out1]` section, and |
| 10 |
-- errors expected in the second run should be in the `[out2]` section, and so on. |
| 11 |
-- If a section is omitted, it is expected there are no errors on that run. |
| 12 |
-- The number of runs is determined by the highest N in all [outN] sections, but |
| 13 |
-- there are always at least two runs. (Note that [out] is equivalent to [out1].) |
| 14 |
-- |
| 15 |
-- The list of modules to be checked can be specified using |
| 16 |
-- # cmd: mypy -m mod1 mod2 mod3 |
| 17 |
-- To check a different list on the second run, use |
| 18 |
-- # cmd2: mypy -m mod1 mod3 |
| 19 |
-- (and cmd3 for the third run, and so on). |
| 20 |
-- |
| 21 |
-- Extra command line flags may be specified using |
| 22 |
-- # flags: --some-flag |
| 23 |
-- If the second run requires different flags, those can be specified using |
| 24 |
-- # flags2: --another-flag |
| 25 |
-- (and flags3 for the third run, and so on). |
| 26 |
-- |
| 27 |
-- Incremental tests involving plugins that get updated are also supported. |
| 28 |
-- All plugin files that are updated *must* end in '_plugin', so they will |
| 29 |
-- be unloaded from 'sys.modules' between incremental steps. |
| 30 |
-- |
| 31 |
-- Any files that we expect to be rechecked should be annotated in the [rechecked] |
| 32 |
-- annotation, and any files expect to be stale (aka have a modified interface) |
| 33 |
-- should be annotated in the [stale] annotation. Note that a file that ends up |
| 34 |
-- producing an error has its caches deleted and is marked stale automatically. |
| 35 |
-- Such files do not need to be included in [stale ...] list. |
| 36 |
-- |
| 37 |
-- The test suite will automatically assume that __main__ is stale and rechecked in |
| 38 |
-- all cases so we can avoid constantly having to annotate it. The list of |
| 39 |
-- rechecked/stale files can be in any arbitrary order, or can be left empty |
| 40 |
-- if no files should be rechecked/stale. |
| 41 |
-- |
| 42 |
-- There are additional incremental mode test cases in check-serialize.test. |
| 43 |
|
| 44 |
[case testIncrementalEmpty] |
| 45 |
[rechecked] |
| 46 |
[stale] |
| 47 |
|
| 48 |
[case testIncrementalBasics] |
| 49 |
import m |
| 50 |
[file m.py] |
| 51 |
def foo(): |
| 52 |
pass |
| 53 |
[file m.py.2] |
| 54 |
def foo() -> None: |
| 55 |
pass |
| 56 |
[rechecked m] |
| 57 |
[stale m] |
| 58 |
|
| 59 |
[case testIncrementalError] |
| 60 |
import m |
| 61 |
[file m.py] |
| 62 |
def foo() -> None: |
| 63 |
pass |
| 64 |
[file m.py.2] |
| 65 |
def foo() -> None: |
| 66 |
bar() |
| 67 |
[rechecked m] |
| 68 |
[stale] |
| 69 |
[out2] |
| 70 |
tmp/m.py:2: error: Name "bar" is not defined |
| 71 |
|
| 72 |
[case testIncrementalSimpleImportSequence] |
| 73 |
import mod1 |
| 74 |
mod1.func1() |
| 75 |
|
| 76 |
[file mod1.py] |
| 77 |
import mod2 |
| 78 |
def func1() -> None: mod2.func2() |
| 79 |
|
| 80 |
[file mod2.py] |
| 81 |
import mod3 |
| 82 |
def func2() -> None: mod3.func3() |
| 83 |
|
| 84 |
[file mod3.py] |
| 85 |
def func3() -> None: pass |
| 86 |
|
| 87 |
[rechecked] |
| 88 |
[stale] |
| 89 |
|
| 90 |
|
| 91 |
[case testIncrementalInternalChangeOnly] |
| 92 |
import mod1 |
| 93 |
mod1.func1() |
| 94 |
|
| 95 |
[file mod1.py] |
| 96 |
import mod2 |
| 97 |
def func1() -> None: mod2.func2() |
| 98 |
|
| 99 |
[file mod2.py] |
| 100 |
import mod3 |
| 101 |
def func2() -> None: mod3.func3() |
| 102 |
|
| 103 |
[file mod3.py] |
| 104 |
def func3() -> None: pass |
| 105 |
|
| 106 |
[file mod3.py.2] |
| 107 |
def func3() -> None: 3 + 2 |
| 108 |
|
| 109 |
[rechecked mod3] |
| 110 |
[stale] |
| 111 |
|
| 112 |
|
| 113 |
[case testIncrementalImportGone] |
| 114 |
import mod1 |
| 115 |
|
| 116 |
[file mod1.py] |
| 117 |
from mod2 import A |
| 118 |
def func1() -> A: pass |
| 119 |
|
| 120 |
[file mod2.py] |
| 121 |
class A: pass |
| 122 |
|
| 123 |
[file mod1.py.2] |
| 124 |
def func1() -> A: pass |
| 125 |
|
| 126 |
[rechecked mod1] |
| 127 |
[stale mod1] |
| 128 |
[out2] |
| 129 |
tmp/mod1.py:1: error: Name "A" is not defined |
| 130 |
|
| 131 |
[case testIncrementalCallable] |
| 132 |
import mod1 |
| 133 |
|
| 134 |
[file mod1.py] |
| 135 |
from typing import Callable |
| 136 |
from mypy_extensions import Arg |
| 137 |
def func1() -> Callable[[Arg(int, 'x')], int]: pass |
| 138 |
|
| 139 |
[file mod1.py.2] |
| 140 |
from typing import Callable |
| 141 |
from mypy_extensions import Arg |
| 142 |
def func1() -> Callable[[Arg(int, 'x')], int]: ... |
| 143 |
|
| 144 |
|
| 145 |
[rechecked mod1] |
| 146 |
[stale] |
| 147 |
|
| 148 |
[builtins fixtures/dict.pyi] |
| 149 |
|
| 150 |
[case testIncrementalSameNameChange] |
| 151 |
import mod1 |
| 152 |
|
| 153 |
[file mod1.py] |
| 154 |
from mod2 import A |
| 155 |
def func1() -> A: pass |
| 156 |
|
| 157 |
[file mod2.py] |
| 158 |
class A: pass |
| 159 |
|
| 160 |
[file mod2.py.2] |
| 161 |
class Parent: pass |
| 162 |
class A(Parent): pass |
| 163 |
|
| 164 |
[rechecked mod1, mod2] |
| 165 |
[stale mod2] |
| 166 |
|
| 167 |
[case testIncrementalPartialInterfaceChange] |
| 168 |
import mod1 |
| 169 |
mod1.func1() |
| 170 |
|
| 171 |
[file mod1.py] |
| 172 |
import mod2 |
| 173 |
def func1() -> None: mod2.func2() |
| 174 |
|
| 175 |
[file mod2.py] |
| 176 |
import mod3 |
| 177 |
def func2() -> None: mod3.func3() |
| 178 |
|
| 179 |
[file mod3.py] |
| 180 |
def func3() -> None: pass |
| 181 |
|
| 182 |
[file mod3.py.2] |
| 183 |
def func3() -> int: return 2 |
| 184 |
|
| 185 |
[rechecked mod2, mod3] |
| 186 |
[stale mod3] |
| 187 |
|
| 188 |
[case testIncrementalInternalFunctionDefinitionChange] |
| 189 |
import mod1 |
| 190 |
|
| 191 |
[file mod1.py] |
| 192 |
import mod2 |
| 193 |
def accepts_int(a: int) -> int: return a |
| 194 |
accepts_int(mod2.foo()) |
| 195 |
|
| 196 |
[file mod2.py] |
| 197 |
def foo() -> int: |
| 198 |
def inner() -> int: |
| 199 |
return 42 |
| 200 |
return inner() |
| 201 |
|
| 202 |
[file mod2.py.2] |
| 203 |
def foo() -> int: |
| 204 |
def inner2() -> str: |
| 205 |
return "foo" |
| 206 |
return inner2() |
| 207 |
|
| 208 |
[rechecked mod2] |
| 209 |
[stale] |
| 210 |
[out2] |
| 211 |
tmp/mod2.py:4: error: Incompatible return value type (got "str", expected "int") |
| 212 |
|
| 213 |
[case testIncrementalInternalScramble] |
| 214 |
import mod1 |
| 215 |
|
| 216 |
[file mod1.py] |
| 217 |
import mod2 |
| 218 |
mod2.foo() |
| 219 |
|
| 220 |
[file mod2.py] |
| 221 |
def baz() -> int: |
| 222 |
return 3 |
| 223 |
|
| 224 |
def bar() -> int: |
| 225 |
return baz() |
| 226 |
|
| 227 |
def foo() -> int: |
| 228 |
return bar() |
| 229 |
|
| 230 |
[file mod2.py.2] |
| 231 |
def foo() -> int: |
| 232 |
return baz() |
| 233 |
|
| 234 |
def bar() -> int: |
| 235 |
return bar() |
| 236 |
|
| 237 |
def baz() -> int: |
| 238 |
return 42 |
| 239 |
[rechecked mod2] |
| 240 |
[stale] |
| 241 |
|
| 242 |
[case testIncrementalMethodInterfaceChange] |
| 243 |
import mod1 |
| 244 |
|
| 245 |
[file mod1.py] |
| 246 |
import mod2 |
| 247 |
|
| 248 |
[file mod2.py] |
| 249 |
class Foo: |
| 250 |
def bar(self, a: str) -> str: |
| 251 |
return "a" |
| 252 |
|
| 253 |
[file mod2.py.2] |
| 254 |
class Foo: |
| 255 |
def bar(self, a: float) -> str: |
| 256 |
return "a" |
| 257 |
|
| 258 |
[rechecked mod1, mod2] |
| 259 |
[stale mod2] |
| 260 |
|
| 261 |
[case testIncrementalBaseClassChange] |
| 262 |
import mod1 |
| 263 |
|
| 264 |
[file mod1.py] |
| 265 |
from mod2 import Child |
| 266 |
Child().good_method() |
| 267 |
|
| 268 |
[file mod2.py] |
| 269 |
class Good: |
| 270 |
def good_method(self) -> int: return 1 |
| 271 |
class Bad: pass |
| 272 |
class Child(Good): pass |
| 273 |
|
| 274 |
[file mod2.py.2] |
| 275 |
class Good: |
| 276 |
def good_method(self) -> int: return 1 |
| 277 |
class Bad: pass |
| 278 |
class Child(Bad): pass |
| 279 |
|
| 280 |
[rechecked mod1, mod2] |
| 281 |
[stale mod2] |
| 282 |
[out2] |
| 283 |
tmp/mod1.py:2: error: "Child" has no attribute "good_method" |
| 284 |
|
| 285 |
[case testIncrementalCascadingChange] |
| 286 |
import mod1 |
| 287 |
|
| 288 |
[file mod1.py] |
| 289 |
from mod2 import A |
| 290 |
def accepts_int(a: int) -> None: pass |
| 291 |
accepts_int(A) |
| 292 |
|
| 293 |
[file mod2.py] |
| 294 |
from mod3 import B |
| 295 |
A = B |
| 296 |
|
| 297 |
[file mod3.py] |
| 298 |
from mod4 import C |
| 299 |
B = C |
| 300 |
|
| 301 |
[file mod4.py] |
| 302 |
C = 3 |
| 303 |
|
| 304 |
[file mod4.py.2] |
| 305 |
C = "A" |
| 306 |
|
| 307 |
[rechecked mod1, mod2, mod3, mod4] |
| 308 |
[stale mod2, mod3, mod4] |
| 309 |
[out2] |
| 310 |
tmp/mod1.py:3: error: Argument 1 to "accepts_int" has incompatible type "str"; expected "int" |
| 311 |
|
| 312 |
[case testIncrementalBrokenCascade] |
| 313 |
import mod1 |
| 314 |
|
| 315 |
[file mod1.py] |
| 316 |
import mod2 |
| 317 |
def accept_int(a: int) -> int: return a |
| 318 |
accept_int(mod2.mod3.mod4.const) |
| 319 |
|
| 320 |
[file mod2.py] |
| 321 |
import mod3 |
| 322 |
|
| 323 |
[file mod3.py] |
| 324 |
import mod4 |
| 325 |
|
| 326 |
[file mod4.py] |
| 327 |
const = 3 |
| 328 |
|
| 329 |
[file mod3.py.2] |
| 330 |
# Import to mod4 is gone! |
| 331 |
|
| 332 |
[rechecked mod1, mod2, mod3] |
| 333 |
[stale mod3] |
| 334 |
[builtins fixtures/module.pyi] |
| 335 |
[out2] |
| 336 |
tmp/mod1.py:3: error: Module has no attribute "mod4" |
| 337 |
|
| 338 |
[case testIncrementalLongBrokenCascade] |
| 339 |
import mod1 |
| 340 |
|
| 341 |
[file mod1.py] |
| 342 |
import mod2 |
| 343 |
def accept_int(a: int) -> int: return a |
| 344 |
accept_int(mod2.mod3.mod4.mod5.mod6.mod7.const) |
| 345 |
|
| 346 |
[file mod2.py] |
| 347 |
import mod3 |
| 348 |
|
| 349 |
[file mod3.py] |
| 350 |
import mod4 |
| 351 |
|
| 352 |
[file mod4.py] |
| 353 |
import mod5 |
| 354 |
|
| 355 |
[file mod5.py] |
| 356 |
import mod6 |
| 357 |
|
| 358 |
[file mod6.py] |
| 359 |
import mod7 |
| 360 |
|
| 361 |
[file mod7.py] |
| 362 |
const = 3 |
| 363 |
|
| 364 |
[file mod6.py.2] |
| 365 |
# Import to mod7 is gone! |
| 366 |
|
| 367 |
[rechecked mod1, mod5, mod6] |
| 368 |
[stale mod6] |
| 369 |
[builtins fixtures/module.pyi] |
| 370 |
[out2] |
| 371 |
tmp/mod1.py:3: error: Module has no attribute "mod7" |
| 372 |
|
| 373 |
[case testIncrementalNestedBrokenCascade] |
| 374 |
import mod1 |
| 375 |
|
| 376 |
[file mod1.py] |
| 377 |
import mod2 |
| 378 |
def accept_int(a: int) -> int: return a |
| 379 |
accept_int(mod2.mod3.mod4.const) |
| 380 |
|
| 381 |
[file mod2/__init__.py] |
| 382 |
import mod2.mod3 as mod3 |
| 383 |
|
| 384 |
[file mod2/mod3/__init__.py] |
| 385 |
import mod2.mod3.mod4 as mod4 |
| 386 |
|
| 387 |
[file mod2/mod3/__init__.py.2] |
| 388 |
# Import is gone! |
| 389 |
|
| 390 |
[file mod2/mod3/mod4.py] |
| 391 |
const = 3 |
| 392 |
|
| 393 |
[rechecked mod1, mod2, mod2.mod3] |
| 394 |
[stale mod2.mod3] |
| 395 |
[builtins fixtures/module.pyi] |
| 396 |
[out2] |
| 397 |
tmp/mod1.py:3: error: Module has no attribute "mod4" |
| 398 |
|
| 399 |
[case testIncrementalNestedBrokenCascadeWithType1] |
| 400 |
import mod1, mod2.mod3.mod5 |
| 401 |
|
| 402 |
[file mod1.py] |
| 403 |
import mod2 |
| 404 |
def accept_int(x: int) -> None: pass |
| 405 |
def produce() -> mod2.CustomType: |
| 406 |
return mod2.CustomType() |
| 407 |
a = produce() |
| 408 |
accept_int(a.foo()) |
| 409 |
|
| 410 |
[file mod2/__init__.py] |
| 411 |
from mod2.mod3 import CustomType |
| 412 |
|
| 413 |
[file mod2/mod3/__init__.py] |
| 414 |
from mod2.mod3.mod4 import CustomType |
| 415 |
|
| 416 |
[file mod2/mod3/__init__.py.2] |
| 417 |
# Import a different class that also happens to be called 'CustomType' |
| 418 |
from mod2.mod3.mod5 import CustomType |
| 419 |
def produce() -> CustomType: |
| 420 |
return CustomType() |
| 421 |
|
| 422 |
[file mod2/mod3/mod4.py] |
| 423 |
class CustomType: |
| 424 |
def foo(self) -> int: return 1 |
| 425 |
|
| 426 |
[file mod2/mod3/mod5.py] |
| 427 |
class CustomType: |
| 428 |
def foo(self) -> str: return "a" |
| 429 |
|
| 430 |
[rechecked mod1, mod2, mod2.mod3] |
| 431 |
[stale mod1, mod2, mod2.mod3] |
| 432 |
[builtins fixtures/module.pyi] |
| 433 |
[out1] |
| 434 |
[out2] |
| 435 |
tmp/mod1.py:6: error: Argument 1 to "accept_int" has incompatible type "str"; expected "int" |
| 436 |
|
| 437 |
[case testIncrementalNestedBrokenCascadeWithType2] |
| 438 |
import mod1, mod2.mod3.mod5 |
| 439 |
|
| 440 |
[file mod1.py] |
| 441 |
from mod2 import produce |
| 442 |
def accept_int(x: int) -> None: pass |
| 443 |
a = produce() |
| 444 |
accept_int(a.foo()) |
| 445 |
|
| 446 |
[file mod2/__init__.py] |
| 447 |
from mod2.mod3 import produce |
| 448 |
|
| 449 |
[file mod2/mod3/__init__.py] |
| 450 |
from mod2.mod3.mod4 import CustomType |
| 451 |
def produce() -> CustomType: |
| 452 |
return CustomType() |
| 453 |
|
| 454 |
[file mod2/mod3/__init__.py.2] |
| 455 |
# Import a different class that also happens to be called 'CustomType' |
| 456 |
from mod2.mod3.mod5 import CustomType |
| 457 |
def produce() -> CustomType: |
| 458 |
return CustomType() |
| 459 |
|
| 460 |
[file mod2/mod3/mod4.py] |
| 461 |
class CustomType: |
| 462 |
def foo(self) -> int: return 1 |
| 463 |
|
| 464 |
[file mod2/mod3/mod5.py] |
| 465 |
class CustomType: |
| 466 |
def foo(self) -> str: return "a" |
| 467 |
|
| 468 |
[rechecked mod1, mod2, mod2.mod3] |
| 469 |
[stale mod1, mod2.mod3] |
| 470 |
[builtins fixtures/module.pyi] |
| 471 |
[out1] |
| 472 |
[out2] |
| 473 |
tmp/mod1.py:4: error: Argument 1 to "accept_int" has incompatible type "str"; expected "int" |
| 474 |
|
| 475 |
[case testIncrementalRemoteChange] |
| 476 |
import mod1 |
| 477 |
|
| 478 |
[file mod1.py] |
| 479 |
import mod2 |
| 480 |
def accepts_int(a: int) -> None: pass |
| 481 |
accepts_int(mod2.mod3.mod4.const) |
| 482 |
|
| 483 |
[file mod2.py] |
| 484 |
import mod3 |
| 485 |
|
| 486 |
[file mod3.py] |
| 487 |
import mod4 |
| 488 |
|
| 489 |
[file mod4.py] |
| 490 |
const = 3 |
| 491 |
|
| 492 |
[file mod4.py.2] |
| 493 |
const = "foo" |
| 494 |
|
| 495 |
[rechecked mod1, mod3, mod4] |
| 496 |
[stale mod4] |
| 497 |
[out2] |
| 498 |
tmp/mod1.py:3: error: Argument 1 to "accepts_int" has incompatible type "str"; expected "int" |
| 499 |
|
| 500 |
[case testIncrementalBadChange] |
| 501 |
import mod1 |
| 502 |
|
| 503 |
[file mod1.py] |
| 504 |
from mod2 import func2 |
| 505 |
|
| 506 |
def func1() -> int: |
| 507 |
return func2() |
| 508 |
|
| 509 |
[file mod2.py] |
| 510 |
def func2() -> int: |
| 511 |
return 1 |
| 512 |
|
| 513 |
[file mod2.py.2] |
| 514 |
def func2() -> str: |
| 515 |
return "foo" |
| 516 |
|
| 517 |
[rechecked mod1, mod2] |
| 518 |
[stale mod2] |
| 519 |
[out2] |
| 520 |
tmp/mod1.py:4: error: Incompatible return value type (got "str", expected "int") |
| 521 |
|
| 522 |
[case testIncrementalBadChangeWithSave] |
| 523 |
import mod0 |
| 524 |
|
| 525 |
[file mod0.py] |
| 526 |
import mod1 |
| 527 |
A = mod1.func2() |
| 528 |
|
| 529 |
[file mod1.py] |
| 530 |
from mod2 import func2 |
| 531 |
|
| 532 |
def func1() -> int: |
| 533 |
return func2() |
| 534 |
|
| 535 |
[file mod2.py] |
| 536 |
def func2() -> int: |
| 537 |
return 1 |
| 538 |
|
| 539 |
[file mod2.py.2] |
| 540 |
def func2() -> str: |
| 541 |
return "foo" |
| 542 |
|
| 543 |
[rechecked mod0, mod1, mod2] |
| 544 |
[stale mod0, mod2] |
| 545 |
[out2] |
| 546 |
tmp/mod1.py:4: error: Incompatible return value type (got "str", expected "int") |
| 547 |
|
| 548 |
[case testIncrementalOkChangeWithSave] |
| 549 |
import mod0 |
| 550 |
|
| 551 |
[file mod0.py] |
| 552 |
import mod1 |
| 553 |
A = mod1.func2() |
| 554 |
|
| 555 |
[file mod1.py] |
| 556 |
from mod2 import func2 |
| 557 |
|
| 558 |
def func1() -> int: |
| 559 |
func2() |
| 560 |
return 1 |
| 561 |
|
| 562 |
[file mod2.py] |
| 563 |
def func2() -> int: |
| 564 |
return 1 |
| 565 |
|
| 566 |
[file mod2.py.2] |
| 567 |
def func2() -> str: |
| 568 |
return "foo" |
| 569 |
|
| 570 |
[rechecked mod0, mod1, mod2] |
| 571 |
[stale mod0, mod2] |
| 572 |
[out2] |
| 573 |
|
| 574 |
[case testIncrementalWithComplexDictExpression] |
| 575 |
import mod1 |
| 576 |
|
| 577 |
[file mod1.py] |
| 578 |
import mod1_private |
| 579 |
|
| 580 |
[file mod1_private.py] |
| 581 |
my_dict = { |
| 582 |
'a': [1, 2, 3], |
| 583 |
'b': [4, 5, 6] |
| 584 |
} |
| 585 |
|
| 586 |
[file mod1_private.py.2] |
| 587 |
my_dict = { |
| 588 |
'a': [1, 2, 3], |
| 589 |
'b': [4, 5, 'a'] |
| 590 |
} |
| 591 |
|
| 592 |
[rechecked mod1, mod1_private] |
| 593 |
[stale mod1_private] |
| 594 |
[builtins fixtures/dict.pyi] |
| 595 |
|
| 596 |
[case testIncrementalWithComplexConstantExpressionNoAnnotation] |
| 597 |
import mod1 |
| 598 |
|
| 599 |
[file mod1.py] |
| 600 |
import mod1_private |
| 601 |
|
| 602 |
[file mod1_private.py] |
| 603 |
def foobar() -> int: return 1 |
| 604 |
def baz() -> int: return 2 |
| 605 |
const = 1 + foobar() |
| 606 |
|
| 607 |
[file mod1_private.py.2] |
| 608 |
def foobar() -> int: return 1 |
| 609 |
def baz() -> int: return 2 |
| 610 |
const = 1 + baz() |
| 611 |
|
| 612 |
[rechecked mod1_private] |
| 613 |
[stale] |
| 614 |
|
| 615 |
[case testIncrementalWithComplexConstantExpressionWithAnnotation] |
| 616 |
import mod1 |
| 617 |
|
| 618 |
[file mod1.py] |
| 619 |
import mod1_private |
| 620 |
|
| 621 |
[file mod1_private.py] |
| 622 |
def foobar() -> int: return 1 |
| 623 |
def baz() -> int: return 2 |
| 624 |
const = 1 + foobar() # type: int |
| 625 |
|
| 626 |
[file mod1_private.py.2] |
| 627 |
def foobar() -> int: return 1 |
| 628 |
def baz() -> int: return 2 |
| 629 |
const = 1 + baz() # type: int |
| 630 |
|
| 631 |
[rechecked mod1_private] |
| 632 |
[stale] |
| 633 |
|
| 634 |
[case testIncrementalSmall] |
| 635 |
import mod1 |
| 636 |
|
| 637 |
[file mod1.py] |
| 638 |
import mod1_private |
| 639 |
def accepts_int(a: int) -> None: pass |
| 640 |
accepts_int(mod1_private.some_func(12)) |
| 641 |
|
| 642 |
[file mod1_private.py] |
| 643 |
def some_func(a: int) -> int: |
| 644 |
return 1 |
| 645 |
|
| 646 |
[file mod1_private.py.2] |
| 647 |
def some_func(a: int) -> str: |
| 648 |
return "a" |
| 649 |
|
| 650 |
[rechecked mod1, mod1_private] |
| 651 |
[stale mod1_private] |
| 652 |
[builtins fixtures/ops.pyi] |
| 653 |
[out2] |
| 654 |
tmp/mod1.py:3: error: Argument 1 to "accepts_int" has incompatible type "str"; expected "int" |
| 655 |
|
| 656 |
[case testIncrementalWithDecorators] |
| 657 |
import mod1 |
| 658 |
|
| 659 |
[file mod1.py] |
| 660 |
import mod1_private |
| 661 |
def accepts_int(a: int) -> None: pass |
| 662 |
accepts_int(mod1_private.some_func(12)) |
| 663 |
|
| 664 |
[file mod1_private.py] |
| 665 |
from typing import Callable |
| 666 |
def multiply(f: Callable[[int], int]) -> Callable[[int], int]: |
| 667 |
return lambda a: f(a) * 10 |
| 668 |
|
| 669 |
def stringify(f: Callable[[int], int]) -> Callable[[int], str]: |
| 670 |
return lambda a: str(f(a)) |
| 671 |
|
| 672 |
@multiply |
| 673 |
def some_func(a: int) -> int: |
| 674 |
return a + 2 |
| 675 |
|
| 676 |
[file mod1_private.py.2] |
| 677 |
from typing import Callable |
| 678 |
def multiply(f: Callable[[int], int]) -> Callable[[int], int]: |
| 679 |
return lambda a: f(a) * 10 |
| 680 |
|
| 681 |
def stringify(f: Callable[[int], int]) -> Callable[[int], str]: |
| 682 |
return lambda a: str(f(a)) |
| 683 |
|
| 684 |
@stringify |
| 685 |
def some_func(a: int) -> int: |
| 686 |
return a + 2 |
| 687 |
[rechecked mod1, mod1_private] |
| 688 |
[stale mod1_private] |
| 689 |
[builtins fixtures/ops.pyi] |
| 690 |
[out2] |
| 691 |
tmp/mod1.py:3: error: Argument 1 to "accepts_int" has incompatible type "str"; expected "int" |
| 692 |
|
| 693 |
[case testIncrementalChangingClassAttributes] |
| 694 |
import mod1 |
| 695 |
|
| 696 |
[file mod1.py] |
| 697 |
import mod2 |
| 698 |
mod2.Foo.A |
| 699 |
|
| 700 |
[file mod2.py] |
| 701 |
class Foo: |
| 702 |
A = 3 |
| 703 |
|
| 704 |
[file mod2.py.2] |
| 705 |
class Foo: |
| 706 |
A = "hello" |
| 707 |
|
| 708 |
[rechecked mod1, mod2] |
| 709 |
[stale mod2] |
| 710 |
|
| 711 |
[case testIncrementalChangingFields] |
| 712 |
import mod1 |
| 713 |
|
| 714 |
[file mod1.py] |
| 715 |
import mod2 |
| 716 |
f = mod2.Foo() |
| 717 |
f.A |
| 718 |
|
| 719 |
[file mod2.py] |
| 720 |
class Foo: |
| 721 |
def __init__(self) -> None: |
| 722 |
self.A = 3 |
| 723 |
|
| 724 |
[file mod2.py.2] |
| 725 |
class Foo: |
| 726 |
def __init__(self) -> None: |
| 727 |
self.A = "hello" |
| 728 |
|
| 729 |
[rechecked mod1, mod2] |
| 730 |
[stale mod2] |
| 731 |
[out2] |
| 732 |
|
| 733 |
[case testIncrementalChangingFieldsWithAssignment] |
| 734 |
import mod1 |
| 735 |
|
| 736 |
[file mod1.py] |
| 737 |
import mod2 |
| 738 |
f = mod2.Foo() |
| 739 |
B = f.A |
| 740 |
|
| 741 |
[file mod2.py] |
| 742 |
class Foo: |
| 743 |
def __init__(self) -> None: |
| 744 |
self.A = 3 |
| 745 |
|
| 746 |
[file mod2.py.2] |
| 747 |
class Foo: |
| 748 |
def __init__(self) -> None: |
| 749 |
self.A = "hello" |
| 750 |
|
| 751 |
[rechecked mod1, mod2] |
| 752 |
[stale mod1, mod2] |
| 753 |
|
| 754 |
[case testIncrementalCheckingChangingFields] |
| 755 |
import mod1 |
| 756 |
|
| 757 |
[file mod1.py] |
| 758 |
import mod2 |
| 759 |
def accept_int(a: int) -> int: return a |
| 760 |
f = mod2.Foo() |
| 761 |
accept_int(f.A) |
| 762 |
|
| 763 |
[file mod2.py] |
| 764 |
class Foo: |
| 765 |
def __init__(self) -> None: |
| 766 |
self.A = 3 |
| 767 |
|
| 768 |
[file mod2.py.2] |
| 769 |
class Foo: |
| 770 |
def __init__(self) -> None: |
| 771 |
self.A = "hello" |
| 772 |
|
| 773 |
[rechecked mod1, mod2] |
| 774 |
[stale mod2] |
| 775 |
[out2] |
| 776 |
tmp/mod1.py:4: error: Argument 1 to "accept_int" has incompatible type "str"; expected "int" |
| 777 |
|
| 778 |
[case testIncrementalNestedClassDefinition] |
| 779 |
import mod1 |
| 780 |
|
| 781 |
[file mod1.py] |
| 782 |
import mod2 |
| 783 |
b = mod2.Foo.Bar() |
| 784 |
b.attr |
| 785 |
|
| 786 |
[file mod2.py] |
| 787 |
class Foo: |
| 788 |
class Bar: |
| 789 |
attr = 3 |
| 790 |
|
| 791 |
[file mod2.py.2] |
| 792 |
class Foo: |
| 793 |
class Bar: |
| 794 |
attr = "foo" |
| 795 |
|
| 796 |
[rechecked mod1, mod2] |
| 797 |
[stale mod2] |
| 798 |
|
| 799 |
[case testIncrementalSimpleBranchingModules] |
| 800 |
import mod1 |
| 801 |
import mod2 |
| 802 |
|
| 803 |
[file mod1.py] |
| 804 |
def func() -> None: pass |
| 805 |
|
| 806 |
[file mod2.py] |
| 807 |
def func() -> None: pass |
| 808 |
|
| 809 |
[file mod1.py.2] |
| 810 |
def func() -> int: return 1 |
| 811 |
|
| 812 |
[rechecked mod1] |
| 813 |
[stale mod1] |
| 814 |
|
| 815 |
[case testIncrementalSubmoduleImport] |
| 816 |
from parent.childA import Foo |
| 817 |
|
| 818 |
def func1() -> Foo: |
| 819 |
return Foo() |
| 820 |
|
| 821 |
[file parent/__init__.py] |
| 822 |
from parent.childA import Foo |
| 823 |
from parent.childB import Bar |
| 824 |
|
| 825 |
__all__ = ['Foo', 'Bar'] |
| 826 |
|
| 827 |
[file parent/childA.py] |
| 828 |
import parent |
| 829 |
|
| 830 |
class Foo: |
| 831 |
def test(self) -> int: |
| 832 |
return parent.Bar().test() |
| 833 |
|
| 834 |
[file parent/childB.py] |
| 835 |
class Bar: |
| 836 |
def test(self) -> int: return 3 |
| 837 |
|
| 838 |
[builtins fixtures/module_all.pyi] |
| 839 |
[rechecked] |
| 840 |
[stale] |
| 841 |
|
| 842 |
[case testIncrementalSubmoduleWithAttr] |
| 843 |
import mod.child |
| 844 |
x = mod.child.Foo() |
| 845 |
x.bar() |
| 846 |
|
| 847 |
[file mod/__init__.py] |
| 848 |
|
| 849 |
[file mod/child.py] |
| 850 |
class Foo: |
| 851 |
def bar(self) -> None: pass |
| 852 |
[builtins fixtures/module.pyi] |
| 853 |
[rechecked] |
| 854 |
[stale] |
| 855 |
|
| 856 |
[case testIncrementalNestedSubmoduleImportFromWithAttr] |
| 857 |
from mod1.mod2 import mod3 |
| 858 |
def accept_int(a: int) -> None: pass |
| 859 |
|
| 860 |
accept_int(mod3.val3) |
| 861 |
|
| 862 |
[file mod1/__init__.py] |
| 863 |
val1 = 1 |
| 864 |
|
| 865 |
[file mod1/mod2/__init__.py] |
| 866 |
val2 = 1 |
| 867 |
|
| 868 |
[file mod1/mod2/mod3.py] |
| 869 |
val3 = 1 |
| 870 |
|
| 871 |
[builtins fixtures/module.pyi] |
| 872 |
[rechecked] |
| 873 |
[stale] |
| 874 |
|
| 875 |
[case testIncrementalNestedSubmoduleWithAttr] |
| 876 |
import mod1.mod2.mod3 |
| 877 |
def accept_int(a: int) -> None: pass |
| 878 |
|
| 879 |
accept_int(mod1.mod2.mod3.val3) |
| 880 |
accept_int(mod1.mod2.val2) |
| 881 |
accept_int(mod1.val1) |
| 882 |
|
| 883 |
[file mod1/__init__.py] |
| 884 |
val1 = 1 |
| 885 |
|
| 886 |
[file mod1/mod2/__init__.py] |
| 887 |
val2 = 1 |
| 888 |
|
| 889 |
[file mod1/mod2/mod3.py] |
| 890 |
val3 = 1 |
| 891 |
|
| 892 |
[builtins fixtures/module.pyi] |
| 893 |
[rechecked] |
| 894 |
[stale] |
| 895 |
|
| 896 |
[case testIncrementalSubmoduleParentWithImportFrom] |
| 897 |
import parent |
| 898 |
|
| 899 |
[file parent/__init__.py] |
| 900 |
from parent import a |
| 901 |
|
| 902 |
[file parent/a.py] |
| 903 |
val = 3 |
| 904 |
|
| 905 |
[builtins fixtures/args.pyi] |
| 906 |
[stale] |
| 907 |
|
| 908 |
[case testIncrementalSubmoduleParentBackreference] |
| 909 |
import parent |
| 910 |
|
| 911 |
[file parent/__init__.py] |
| 912 |
from parent import a |
| 913 |
|
| 914 |
[file parent/a.py] |
| 915 |
import parent.b |
| 916 |
|
| 917 |
[file parent/b.py] |
| 918 |
|
| 919 |
[builtins fixtures/args.pyi] |
| 920 |
[stale] |
| 921 |
|
| 922 |
[case testIncrementalSubmoduleParentBackreferenceComplex] |
| 923 |
import parent |
| 924 |
|
| 925 |
[file parent/__init__.py] |
| 926 |
import parent.a |
| 927 |
|
| 928 |
[file parent/a.py] |
| 929 |
import parent.b |
| 930 |
import parent.c |
| 931 |
|
| 932 |
[file parent/b.py] |
| 933 |
import parent.a |
| 934 |
|
| 935 |
[file parent/c.py] |
| 936 |
import parent.a |
| 937 |
|
| 938 |
[builtins fixtures/args.pyi] |
| 939 |
[stale] |
| 940 |
|
| 941 |
[case testIncrementalReferenceNewFileWithImportFrom] |
| 942 |
from parent import a |
| 943 |
|
| 944 |
[file parent/__init__.py] |
| 945 |
|
| 946 |
[file parent/a.py] |
| 947 |
|
| 948 |
[file parent/a.py.2] |
| 949 |
from parent import b |
| 950 |
reveal_type(b.x) |
| 951 |
|
| 952 |
[file parent/b.py.2] |
| 953 |
x = 10 |
| 954 |
|
| 955 |
[stale parent.a, parent.b] |
| 956 |
[rechecked parent.a, parent.b] |
| 957 |
[out2] |
| 958 |
tmp/parent/a.py:2: note: Revealed type is "builtins.int" |
| 959 |
|
| 960 |
[case testIncrementalReferenceExistingFileWithImportFrom] |
| 961 |
from parent import a, b |
| 962 |
|
| 963 |
[file parent/__init__.py] |
| 964 |
|
| 965 |
[file parent/a.py] |
| 966 |
|
| 967 |
[file parent/b.py] |
| 968 |
|
| 969 |
[file parent/a.py.2] |
| 970 |
from parent import b |
| 971 |
|
| 972 |
[stale parent.a] |
| 973 |
|
| 974 |
[case testIncrementalWithTypeIgnoreOnDirectImport] |
| 975 |
import a, b |
| 976 |
|
| 977 |
[file a.py] |
| 978 |
import b # type: ignore |
| 979 |
|
| 980 |
[file b.py] |
| 981 |
import c |
| 982 |
|
| 983 |
[file c.py] |
| 984 |
|
| 985 |
[stale] |
| 986 |
|
| 987 |
[case testIncrementalWithTypeIgnoreOnImportFrom] |
| 988 |
import a, b |
| 989 |
|
| 990 |
[file a.py] |
| 991 |
from b import something # type: ignore |
| 992 |
|
| 993 |
[file b.py] |
| 994 |
import c |
| 995 |
something = 3 |
| 996 |
|
| 997 |
[file c.py] |
| 998 |
|
| 999 |
[stale] |
| 1000 |
|
| 1001 |
[case testIncrementalWithPartialTypeIgnore] |
| 1002 |
import a # type: ignore |
| 1003 |
import a.b |
| 1004 |
|
| 1005 |
[file a/__init__.py] |
| 1006 |
|
| 1007 |
[file a/b.py] |
| 1008 |
|
| 1009 |
[stale] |
| 1010 |
|
| 1011 |
[case testIncrementalAnyIsDifferentFromIgnore] |
| 1012 |
import b |
| 1013 |
|
| 1014 |
[file b.py] |
| 1015 |
from typing import Any |
| 1016 |
import a.b |
| 1017 |
|
| 1018 |
[file b.py.2] |
| 1019 |
from typing import Any |
| 1020 |
|
| 1021 |
a = 3 # type: Any |
| 1022 |
import a.b |
| 1023 |
|
| 1024 |
[file a/__init__.py] |
| 1025 |
|
| 1026 |
[file a/b.py] |
| 1027 |
|
| 1028 |
[stale b] |
| 1029 |
|
| 1030 |
[case testIncrementalSilentImportsAndImportsInClass] |
| 1031 |
# flags: --ignore-missing-imports |
| 1032 |
class MyObject(object): |
| 1033 |
from bar import FooBar |
| 1034 |
[stale] |
| 1035 |
|
| 1036 |
[case testIncrementalSameFileSize] |
| 1037 |
import m |
| 1038 |
|
| 1039 |
[file m.py] |
| 1040 |
def foo(a: int) -> None: pass |
| 1041 |
def bar(a: str) -> None: pass |
| 1042 |
|
| 1043 |
foo(3) |
| 1044 |
|
| 1045 |
[file m.py.2] |
| 1046 |
def foo(a: int) -> None: pass |
| 1047 |
def bar(a: str) -> None: pass |
| 1048 |
|
| 1049 |
bar(3) |
| 1050 |
|
| 1051 |
[rechecked m] |
| 1052 |
[stale] |
| 1053 |
[out2] |
| 1054 |
tmp/m.py:4: error: Argument 1 to "bar" has incompatible type "int"; expected "str" |
| 1055 |
|
| 1056 |
[case testIncrementalUnsilencingModule] |
| 1057 |
# cmd: mypy -m main package.subpackage.mod2 |
| 1058 |
# cmd2: mypy -m main package.subpackage.mod1 |
| 1059 |
# flags: --follow-imports=skip |
| 1060 |
|
| 1061 |
[file main.py] |
| 1062 |
from package.subpackage.mod1 import Class |
| 1063 |
|
| 1064 |
def handle(c: Class) -> None: |
| 1065 |
c.some_attribute |
| 1066 |
|
| 1067 |
[file package/__init__.py] |
| 1068 |
# empty |
| 1069 |
|
| 1070 |
[file package/subpackage/__init__.py] |
| 1071 |
# empty |
| 1072 |
|
| 1073 |
[file package/subpackage/mod1.py] |
| 1074 |
import collections # Any previously unloaded package works here |
| 1075 |
|
| 1076 |
class Class: pass |
| 1077 |
|
| 1078 |
[file package/subpackage/mod2.py] |
| 1079 |
# empty |
| 1080 |
|
| 1081 |
[builtins fixtures/args.pyi] |
| 1082 |
[rechecked collections, main, package.subpackage.mod1] |
| 1083 |
[stale collections, main, package.subpackage.mod1] |
| 1084 |
[out2] |
| 1085 |
tmp/main.py:4: error: "Class" has no attribute "some_attribute" |
| 1086 |
|
| 1087 |
[case testIncrementalWithIgnores] |
| 1088 |
import foo # type: ignore |
| 1089 |
|
| 1090 |
[builtins fixtures/module.pyi] |
| 1091 |
[stale] |
| 1092 |
|
| 1093 |
[case testIncrementalWithSilentImportsAndIgnore] |
| 1094 |
# cmd: mypy -m main b |
| 1095 |
# cmd2: mypy -m main c c.submodule |
| 1096 |
# flags: --follow-imports=skip |
| 1097 |
|
| 1098 |
[file main.py] |
| 1099 |
import a # type: ignore |
| 1100 |
import b |
| 1101 |
import c |
| 1102 |
|
| 1103 |
a.A().foo() |
| 1104 |
b.B().foo() |
| 1105 |
c.C().foo() |
| 1106 |
|
| 1107 |
[file b.py] |
| 1108 |
class B: |
| 1109 |
def foo(self) -> None: pass |
| 1110 |
|
| 1111 |
[file b.py.2] |
| 1112 |
|
| 1113 |
[file c/__init__.py] |
| 1114 |
class C: pass |
| 1115 |
|
| 1116 |
[file c/submodule.py] |
| 1117 |
val = 3 # type: int |
| 1118 |
if int(): |
| 1119 |
val = "foo" |
| 1120 |
|
| 1121 |
[builtins fixtures/module_all.pyi] |
| 1122 |
[rechecked main, c, c.submodule] |
| 1123 |
[stale main, c, c.submodule] |
| 1124 |
[out2] |
| 1125 |
tmp/c/submodule.py:3: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 1126 |
tmp/main.py:7: error: "C" has no attribute "foo" |
| 1127 |
|
| 1128 |
[case testIncrementalRemoteError] |
| 1129 |
import m |
| 1130 |
m.C().foo().bar() |
| 1131 |
[file m.py] |
| 1132 |
import n |
| 1133 |
class C: |
| 1134 |
def foo(self) -> n.A: pass |
| 1135 |
[file n.py] |
| 1136 |
class A: |
| 1137 |
def bar(self): pass |
| 1138 |
[file n.py.2] |
| 1139 |
class A: |
| 1140 |
pass |
| 1141 |
[rechecked m, n] |
| 1142 |
[stale n] |
| 1143 |
[out2] |
| 1144 |
main:2: error: "A" has no attribute "bar" |
| 1145 |
|
| 1146 |
[case testIncrementalRemoteErrorFixed] |
| 1147 |
import m |
| 1148 |
m.C().foo().bar() |
| 1149 |
[file m.py] |
| 1150 |
import n |
| 1151 |
class C: |
| 1152 |
def foo(self) -> n.A: pass |
| 1153 |
[file n.py] |
| 1154 |
class A: |
| 1155 |
pass |
| 1156 |
[file n.py.2] |
| 1157 |
class A: |
| 1158 |
def bar(self): pass |
| 1159 |
[rechecked m, n] |
| 1160 |
[stale n] |
| 1161 |
[out1] |
| 1162 |
main:2: error: "A" has no attribute "bar" |
| 1163 |
|
| 1164 |
[case testIncrementalChangedError] |
| 1165 |
import m |
| 1166 |
[file m.py] |
| 1167 |
import n |
| 1168 |
def accept_int(x: int) -> None: pass |
| 1169 |
accept_int(n.foo) |
| 1170 |
[file n.py] |
| 1171 |
foo = "hello" |
| 1172 |
reveal_type(foo) |
| 1173 |
[file n.py.2] |
| 1174 |
foo = 3.14 |
| 1175 |
reveal_type(foo) |
| 1176 |
[rechecked m, n] |
| 1177 |
[stale n] |
| 1178 |
[out1] |
| 1179 |
tmp/n.py:2: note: Revealed type is "builtins.str" |
| 1180 |
tmp/m.py:3: error: Argument 1 to "accept_int" has incompatible type "str"; expected "int" |
| 1181 |
[out2] |
| 1182 |
tmp/n.py:2: note: Revealed type is "builtins.float" |
| 1183 |
tmp/m.py:3: error: Argument 1 to "accept_int" has incompatible type "float"; expected "int" |
| 1184 |
|
| 1185 |
[case testIncrementalReplacingImports] |
| 1186 |
import good, bad, client |
| 1187 |
|
| 1188 |
[file good.py] |
| 1189 |
def foo(a: int) -> None: pass |
| 1190 |
|
| 1191 |
[file bad.py] |
| 1192 |
def foo(a: str) -> None: pass |
| 1193 |
|
| 1194 |
[file client.py] |
| 1195 |
import good |
| 1196 |
import bad |
| 1197 |
from good import foo |
| 1198 |
foo(3) |
| 1199 |
|
| 1200 |
[file client.py.2] |
| 1201 |
import good |
| 1202 |
import bad |
| 1203 |
from bad import foo |
| 1204 |
foo(3) |
| 1205 |
|
| 1206 |
[rechecked client] |
| 1207 |
[stale client] |
| 1208 |
[out2] |
| 1209 |
tmp/client.py:4: error: Argument 1 to "foo" has incompatible type "int"; expected "str" |
| 1210 |
|
| 1211 |
[case testIncrementalChangingAlias] |
| 1212 |
import m1, m2, m3, m4, m5 |
| 1213 |
|
| 1214 |
[file m1.py] |
| 1215 |
from m2 import A |
| 1216 |
def accepts_int(x: int) -> None: pass |
| 1217 |
accepts_int(A()) |
| 1218 |
|
| 1219 |
[file m2.py] |
| 1220 |
from m3 import A |
| 1221 |
|
| 1222 |
[file m3.py] |
| 1223 |
from m4 import B |
| 1224 |
A = B |
| 1225 |
|
| 1226 |
[file m3.py.2] |
| 1227 |
from m5 import C |
| 1228 |
A = C |
| 1229 |
|
| 1230 |
[file m4.py] |
| 1231 |
def B() -> int: |
| 1232 |
return 42 |
| 1233 |
|
| 1234 |
[file m5.py] |
| 1235 |
def C() -> str: |
| 1236 |
return "hello" |
| 1237 |
|
| 1238 |
[rechecked m1, m2, m3] |
| 1239 |
[stale m3] |
| 1240 |
[out2] |
| 1241 |
tmp/m1.py:3: error: Argument 1 to "accepts_int" has incompatible type "str"; expected "int" |
| 1242 |
|
| 1243 |
[case testIncrementalStoresAliasTypeVars] |
| 1244 |
import a |
| 1245 |
|
| 1246 |
[file mod.py] |
| 1247 |
from typing import TypeVar, Union |
| 1248 |
T = TypeVar('T') |
| 1249 |
Alias = Union[int, T] |
| 1250 |
x: Alias[str] |
| 1251 |
|
| 1252 |
[file a.py] |
| 1253 |
from mod import Alias, x |
| 1254 |
|
| 1255 |
[file a.py.2] |
| 1256 |
from mod import Alias, x |
| 1257 |
|
| 1258 |
reveal_type(x) |
| 1259 |
y: Alias[int] |
| 1260 |
reveal_type(y) |
| 1261 |
[out2] |
| 1262 |
tmp/a.py:3: note: Revealed type is "builtins.int | builtins.str" |
| 1263 |
tmp/a.py:5: note: Revealed type is "builtins.int | builtins.int" |
| 1264 |
|
| 1265 |
[case testIncrementalSilentImportsWithBlatantError] |
| 1266 |
# cmd: mypy -m main |
| 1267 |
# flags: --follow-imports=skip |
| 1268 |
|
| 1269 |
[file main.py] |
| 1270 |
from evil import Hello |
| 1271 |
|
| 1272 |
[file main.py.2] |
| 1273 |
from evil import Hello |
| 1274 |
reveal_type(Hello()) |
| 1275 |
|
| 1276 |
[file evil.py] |
| 1277 |
def accept_int(x: int) -> None: pass |
| 1278 |
accept_int("not an int") |
| 1279 |
|
| 1280 |
[rechecked main] |
| 1281 |
[stale] |
| 1282 |
[out2] |
| 1283 |
tmp/main.py:2: note: Revealed type is "Any" |
| 1284 |
|
| 1285 |
[case testIncrementalImportIsNewlySilenced] |
| 1286 |
# cmd: mypy -m main foo |
| 1287 |
# cmd2: mypy -m main |
| 1288 |
# flags: --follow-imports=skip |
| 1289 |
|
| 1290 |
[file main.py] |
| 1291 |
from foo import bar |
| 1292 |
def accept_int(x: int) -> None: pass |
| 1293 |
accept_int(bar) |
| 1294 |
|
| 1295 |
[file foo.py] |
| 1296 |
bar = 3 |
| 1297 |
|
| 1298 |
[file foo.py.2] |
| 1299 |
# Empty! |
| 1300 |
|
| 1301 |
[rechecked main] |
| 1302 |
[stale main] |
| 1303 |
|
| 1304 |
[case testIncrementalSilencedModuleNoLongerCausesError] |
| 1305 |
# cmd: mypy -m main evil |
| 1306 |
# cmd2: mypy -m main |
| 1307 |
# flags: --follow-imports=skip |
| 1308 |
|
| 1309 |
[file main.py] |
| 1310 |
from evil import bar |
| 1311 |
def accept_int(x: int) -> None: pass |
| 1312 |
accept_int(bar) |
| 1313 |
reveal_type(bar) |
| 1314 |
|
| 1315 |
[file evil.py] |
| 1316 |
bar = "str" |
| 1317 |
|
| 1318 |
[rechecked main] |
| 1319 |
[stale main] |
| 1320 |
[out1] |
| 1321 |
tmp/main.py:3: error: Argument 1 to "accept_int" has incompatible type "str"; expected "int" |
| 1322 |
tmp/main.py:4: note: Revealed type is "builtins.str" |
| 1323 |
[out2] |
| 1324 |
tmp/main.py:4: note: Revealed type is "Any" |
| 1325 |
|
| 1326 |
[case testIncrementalFixedBugCausesPropagation] |
| 1327 |
import mod1 |
| 1328 |
|
| 1329 |
[file mod1.py] |
| 1330 |
from mod2 import A |
| 1331 |
val = A().makeB().makeC().foo() |
| 1332 |
reveal_type(val) |
| 1333 |
|
| 1334 |
[file mod2.py] |
| 1335 |
from mod3 import B |
| 1336 |
class A: |
| 1337 |
def makeB(self) -> B: return B() |
| 1338 |
|
| 1339 |
[file mod3.py] |
| 1340 |
from mod4 import C |
| 1341 |
class B: |
| 1342 |
def makeC(self) -> C: |
| 1343 |
val = 3 # type: int |
| 1344 |
if 1: |
| 1345 |
val = "str" # deliberately triggering error |
| 1346 |
return C() |
| 1347 |
|
| 1348 |
[file mod3.py.2] |
| 1349 |
from mod4 import C |
| 1350 |
class B: |
| 1351 |
def makeC(self) -> C: return C() |
| 1352 |
|
| 1353 |
[file mod4.py] |
| 1354 |
class C: |
| 1355 |
def foo(self) -> int: return 1 |
| 1356 |
|
| 1357 |
[rechecked mod3] |
| 1358 |
[stale] |
| 1359 |
[out1] |
| 1360 |
tmp/mod3.py:6: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 1361 |
tmp/mod1.py:3: note: Revealed type is "builtins.int" |
| 1362 |
|
| 1363 |
[out2] |
| 1364 |
tmp/mod1.py:3: note: Revealed type is "builtins.int" |
| 1365 |
|
| 1366 |
[case testIncrementalIncidentalChangeWithBugCausesPropagation] |
| 1367 |
import mod1 |
| 1368 |
|
| 1369 |
[file mod1.py] |
| 1370 |
from mod2 import A |
| 1371 |
val = A().makeB().makeC().foo() |
| 1372 |
reveal_type(val) |
| 1373 |
|
| 1374 |
[file mod2.py] |
| 1375 |
from mod3 import B |
| 1376 |
class A: |
| 1377 |
def makeB(self) -> B: return B() |
| 1378 |
|
| 1379 |
[file mod3.py] |
| 1380 |
from mod4 import C |
| 1381 |
class B: |
| 1382 |
def makeC(self) -> C: |
| 1383 |
val = 3 # type: int |
| 1384 |
if 1: |
| 1385 |
val = "str" # deliberately triggering error |
| 1386 |
return C() |
| 1387 |
|
| 1388 |
[file mod4.py] |
| 1389 |
class C: |
| 1390 |
def foo(self) -> int: return 1 |
| 1391 |
|
| 1392 |
[file mod4.py.2] |
| 1393 |
class C: |
| 1394 |
def foo(self) -> str: return 'a' |
| 1395 |
|
| 1396 |
[rechecked mod4, mod3, mod1] |
| 1397 |
[stale mod1, mod4] |
| 1398 |
[out1] |
| 1399 |
tmp/mod3.py:6: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 1400 |
tmp/mod1.py:3: note: Revealed type is "builtins.int" |
| 1401 |
[out2] |
| 1402 |
tmp/mod3.py:6: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 1403 |
tmp/mod1.py:3: note: Revealed type is "builtins.str" |
| 1404 |
|
| 1405 |
[case testIncrementalIncidentalChangeWithBugFixCausesPropagation] |
| 1406 |
import mod1 |
| 1407 |
|
| 1408 |
[file mod1.py] |
| 1409 |
from mod2 import A |
| 1410 |
val = A().makeB().makeC().foo() |
| 1411 |
reveal_type(val) |
| 1412 |
|
| 1413 |
[file mod2.py] |
| 1414 |
from mod3 import B |
| 1415 |
class A: |
| 1416 |
def makeB(self) -> B: return B() |
| 1417 |
|
| 1418 |
[file mod3.py] |
| 1419 |
from mod4 import C |
| 1420 |
class B: |
| 1421 |
def makeC(self) -> C: |
| 1422 |
val = 3 # type: int |
| 1423 |
if 1: |
| 1424 |
val = "str" # deliberately triggering error |
| 1425 |
return C() |
| 1426 |
|
| 1427 |
[file mod3.py.2] |
| 1428 |
from mod4 import C |
| 1429 |
class B: |
| 1430 |
def makeC(self) -> C: return C() |
| 1431 |
|
| 1432 |
[file mod4.py] |
| 1433 |
class C: |
| 1434 |
def foo(self) -> int: return 1 |
| 1435 |
|
| 1436 |
[file mod4.py.2] |
| 1437 |
class C: |
| 1438 |
def foo(self) -> str: return 'a' |
| 1439 |
|
| 1440 |
[rechecked mod4, mod3, mod1] |
| 1441 |
[stale mod1, mod4] |
| 1442 |
[out1] |
| 1443 |
tmp/mod3.py:6: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 1444 |
tmp/mod1.py:3: note: Revealed type is "builtins.int" |
| 1445 |
|
| 1446 |
[out2] |
| 1447 |
tmp/mod1.py:3: note: Revealed type is "builtins.str" |
| 1448 |
|
| 1449 |
[case testIncrementalSilentImportsWithInnerImports] |
| 1450 |
# cmd: mypy -m main foo |
| 1451 |
# flags: --ignore-missing-imports |
| 1452 |
|
| 1453 |
[file main.py] |
| 1454 |
from foo import MyClass |
| 1455 |
m = MyClass() |
| 1456 |
|
| 1457 |
[file main.py.2] |
| 1458 |
from foo import MyClass |
| 1459 |
m = MyClass() |
| 1460 |
reveal_type(m.val) |
| 1461 |
|
| 1462 |
[file foo.py] |
| 1463 |
class MyClass: |
| 1464 |
def __init__(self) -> None: |
| 1465 |
import unrelated |
| 1466 |
self.val = unrelated.test() |
| 1467 |
|
| 1468 |
[rechecked main] |
| 1469 |
[stale] |
| 1470 |
[out2] |
| 1471 |
tmp/main.py:3: note: Revealed type is "Any" |
| 1472 |
|
| 1473 |
[case testIncrementalSilentImportsWithInnerImportsAndNewFile] |
| 1474 |
# cmd: mypy -m main foo |
| 1475 |
# cmd2: mypy -m main foo unrelated |
| 1476 |
# flags: --follow-imports=skip |
| 1477 |
|
| 1478 |
[file main.py] |
| 1479 |
from foo import MyClass |
| 1480 |
m = MyClass() |
| 1481 |
|
| 1482 |
[file main.py.2] |
| 1483 |
from foo import MyClass |
| 1484 |
m = MyClass() |
| 1485 |
reveal_type(m.val) |
| 1486 |
|
| 1487 |
[file foo.py] |
| 1488 |
class MyClass: |
| 1489 |
def __init__(self) -> None: |
| 1490 |
import unrelated |
| 1491 |
self.val = unrelated.test() |
| 1492 |
|
| 1493 |
[file unrelated.py] |
| 1494 |
def test() -> str: return "foo" |
| 1495 |
|
| 1496 |
[rechecked main, foo, unrelated] |
| 1497 |
[stale foo, unrelated] |
| 1498 |
[out2] |
| 1499 |
tmp/main.py:3: note: Revealed type is "builtins.str" |
| 1500 |
|
| 1501 |
[case testIncrementalWorksWithNestedClasses] |
| 1502 |
import foo |
| 1503 |
|
| 1504 |
[file foo.py] |
| 1505 |
class MyClass: |
| 1506 |
class NestedClass: |
| 1507 |
pass |
| 1508 |
|
| 1509 |
class_attr = NestedClass() |
| 1510 |
|
| 1511 |
[rechecked] |
| 1512 |
[stale] |
| 1513 |
|
| 1514 |
[case testIncrementalWorksWithBasicProtocols] |
| 1515 |
import a |
| 1516 |
[file a.py] |
| 1517 |
from b import P |
| 1518 |
|
| 1519 |
x: int |
| 1520 |
y: P[int] |
| 1521 |
x = y.meth() |
| 1522 |
|
| 1523 |
class C: |
| 1524 |
def meth(self) -> int: |
| 1525 |
pass |
| 1526 |
y = C() |
| 1527 |
|
| 1528 |
[file a.py.2] |
| 1529 |
from b import P |
| 1530 |
|
| 1531 |
x: str |
| 1532 |
y: P[str] |
| 1533 |
x = y.meth() |
| 1534 |
|
| 1535 |
class C: |
| 1536 |
def meth(self) -> str: |
| 1537 |
pass |
| 1538 |
y = C() |
| 1539 |
[file b.py] |
| 1540 |
from typing import Protocol, TypeVar |
| 1541 |
|
| 1542 |
T = TypeVar('T', covariant=True) |
| 1543 |
class P(Protocol[T]): |
| 1544 |
def meth(self) -> T: |
| 1545 |
pass |
| 1546 |
|
| 1547 |
[case testIncrementalSwitchFromNominalToStructural] |
| 1548 |
import a |
| 1549 |
[file a.py] |
| 1550 |
from b import B, fun |
| 1551 |
class C(B): |
| 1552 |
def x(self) -> int: pass |
| 1553 |
def y(self) -> int: pass |
| 1554 |
fun(C()) |
| 1555 |
|
| 1556 |
[file b.py] |
| 1557 |
from typing import Protocol |
| 1558 |
class B: |
| 1559 |
def x(self) -> float: pass |
| 1560 |
def fun(arg: B) -> None: |
| 1561 |
arg.x() |
| 1562 |
|
| 1563 |
[file b.py.2] |
| 1564 |
from typing import Protocol |
| 1565 |
class B(Protocol): |
| 1566 |
def x(self) -> float: pass |
| 1567 |
def fun(arg: B) -> None: |
| 1568 |
arg.x() |
| 1569 |
|
| 1570 |
[file a.py.3] |
| 1571 |
from b import fun |
| 1572 |
class C: |
| 1573 |
def x(self) -> int: pass |
| 1574 |
def y(self) -> int: pass |
| 1575 |
fun(C()) |
| 1576 |
[out1] |
| 1577 |
[out2] |
| 1578 |
[out3] |
| 1579 |
|
| 1580 |
[case testIncrementalSwitchFromStructuralToNominal] |
| 1581 |
import a |
| 1582 |
[file a.py] |
| 1583 |
from b import fun |
| 1584 |
class C: |
| 1585 |
def x(self) -> int: pass |
| 1586 |
def y(self) -> int: pass |
| 1587 |
fun(C()) |
| 1588 |
|
| 1589 |
[file b.py] |
| 1590 |
from typing import Protocol |
| 1591 |
class B(Protocol): |
| 1592 |
def x(self) -> float: pass |
| 1593 |
def fun(arg: B) -> None: |
| 1594 |
arg.x() |
| 1595 |
|
| 1596 |
[file b.py.2] |
| 1597 |
from typing import Protocol |
| 1598 |
class B: |
| 1599 |
def x(self) -> float: pass |
| 1600 |
def fun(arg: B) -> None: |
| 1601 |
arg.x() |
| 1602 |
|
| 1603 |
[out1] |
| 1604 |
[out2] |
| 1605 |
tmp/a.py:5: error: Argument 1 to "fun" has incompatible type "C"; expected "B" |
| 1606 |
|
| 1607 |
[case testIncrementalWorksWithNamedTuple] |
| 1608 |
import foo |
| 1609 |
|
| 1610 |
[file foo.py] |
| 1611 |
from mid import MyTuple |
| 1612 |
def accept_int(x: int) -> None: pass |
| 1613 |
accept_int(MyTuple(1, "b", "c").a) |
| 1614 |
|
| 1615 |
[file mid.py] |
| 1616 |
from bar import MyTuple |
| 1617 |
|
| 1618 |
[file bar.py] |
| 1619 |
from typing import NamedTuple |
| 1620 |
MyTuple = NamedTuple('MyTuple', [ |
| 1621 |
('a', int), |
| 1622 |
('b', str), |
| 1623 |
('c', str) |
| 1624 |
]) |
| 1625 |
|
| 1626 |
[file bar.py.2] |
| 1627 |
from typing import NamedTuple |
| 1628 |
MyTuple = NamedTuple('MyTuple', [ |
| 1629 |
('b', int), # a and b are swapped |
| 1630 |
('a', str), |
| 1631 |
('c', str) |
| 1632 |
]) |
| 1633 |
|
| 1634 |
[rechecked bar, mid, foo] |
| 1635 |
[stale bar] |
| 1636 |
[builtins fixtures/tuple.pyi] |
| 1637 |
[out2] |
| 1638 |
tmp/foo.py:3: error: Argument 1 to "accept_int" has incompatible type "str"; expected "int" |
| 1639 |
|
| 1640 |
[case testIncrementalWorksWithNestedNamedTuple] |
| 1641 |
import foo |
| 1642 |
|
| 1643 |
[file foo.py] |
| 1644 |
from mid import Outer |
| 1645 |
def accept_int(x: int) -> None: pass |
| 1646 |
accept_int(Outer.MyTuple(1, "b", "c").a) |
| 1647 |
|
| 1648 |
[file mid.py] |
| 1649 |
from bar import Outer |
| 1650 |
|
| 1651 |
[file bar.py] |
| 1652 |
from typing import NamedTuple |
| 1653 |
class Outer: |
| 1654 |
MyTuple = NamedTuple('MyTuple', [ |
| 1655 |
('a', int), |
| 1656 |
('b', str), |
| 1657 |
('c', str) |
| 1658 |
]) |
| 1659 |
|
| 1660 |
[file bar.py.2] |
| 1661 |
from typing import NamedTuple |
| 1662 |
class Outer: |
| 1663 |
MyTuple = NamedTuple('MyTuple', [ |
| 1664 |
('b', int), # a and b are swapped |
| 1665 |
('a', str), |
| 1666 |
('c', str) |
| 1667 |
]) |
| 1668 |
|
| 1669 |
[rechecked bar, mid, foo] |
| 1670 |
[stale bar] |
| 1671 |
[builtins fixtures/tuple.pyi] |
| 1672 |
[out2] |
| 1673 |
tmp/foo.py:3: error: Argument 1 to "accept_int" has incompatible type "str"; expected "int" |
| 1674 |
|
| 1675 |
[case testIncrementalPartialSubmoduleUpdate] |
| 1676 |
# cmd: mypy -m a |
| 1677 |
# cmd2: mypy -m a a.c |
| 1678 |
# flags: --follow-imports=skip |
| 1679 |
|
| 1680 |
[file a/__init__.py] |
| 1681 |
from .b import B |
| 1682 |
from .c import C |
| 1683 |
|
| 1684 |
[file a/b.py] |
| 1685 |
class B: pass |
| 1686 |
|
| 1687 |
[file a/c.py] |
| 1688 |
class C: pass |
| 1689 |
|
| 1690 |
[file a/c.py.2] |
| 1691 |
class C: pass |
| 1692 |
pass |
| 1693 |
|
| 1694 |
[rechecked a, a.c] |
| 1695 |
[stale a, a.c] |
| 1696 |
[out] |
| 1697 |
|
| 1698 |
[case testIncrementalNestedClassRef] |
| 1699 |
import top |
| 1700 |
|
| 1701 |
[file top.py] |
| 1702 |
from funcs import callee |
| 1703 |
from classes import Outer |
| 1704 |
def caller(a: Outer.Inner) -> None: |
| 1705 |
callee(a) |
| 1706 |
|
| 1707 |
[file funcs.py] |
| 1708 |
from classes import Outer |
| 1709 |
def callee(a: Outer.Inner) -> None: |
| 1710 |
pass |
| 1711 |
|
| 1712 |
[file classes.py] |
| 1713 |
class Outer: |
| 1714 |
class Inner: |
| 1715 |
pass |
| 1716 |
|
| 1717 |
[file top.py.2] |
| 1718 |
from funcs import callee |
| 1719 |
from classes import Outer |
| 1720 |
def caller(a: Outer.Inner) -> int: |
| 1721 |
callee(a) |
| 1722 |
return 0 |
| 1723 |
|
| 1724 |
[case testIncrementalLoadsParentAfterChild] |
| 1725 |
# cmd: mypy -m r.s |
| 1726 |
|
| 1727 |
[file r/__init__.py] |
| 1728 |
from . import s |
| 1729 |
|
| 1730 |
[file r/m.py] |
| 1731 |
class R: pass |
| 1732 |
|
| 1733 |
[file r/s.py] |
| 1734 |
from . import m |
| 1735 |
R = m.R |
| 1736 |
a: R |
| 1737 |
|
| 1738 |
[file r/s.py.2] |
| 1739 |
from . import m |
| 1740 |
R = m.R |
| 1741 |
a: R |
| 1742 |
|
| 1743 |
[case testIncrementalBaseClassAttributeConflict] |
| 1744 |
class A: pass |
| 1745 |
class B: pass |
| 1746 |
|
| 1747 |
class X: |
| 1748 |
attr: A |
| 1749 |
class Y: |
| 1750 |
attr: B |
| 1751 |
class Z(X, Y): pass |
| 1752 |
[stale] |
| 1753 |
[out] |
| 1754 |
main:8: error: Definition of "attr" in base class "X" is incompatible with definition in base class "Y" |
| 1755 |
[out2] |
| 1756 |
main:8: error: Definition of "attr" in base class "X" is incompatible with definition in base class "Y" |
| 1757 |
|
| 1758 |
[case testIncrementalFollowImportsSilent] |
| 1759 |
# flags: --follow-imports=silent |
| 1760 |
import a |
| 1761 |
[file a.py] |
| 1762 |
x = 0 |
| 1763 |
[file a.py.2] |
| 1764 |
x = 0 |
| 1765 |
x + '' |
| 1766 |
|
| 1767 |
[case testIncrementalFollowImportsSkip] |
| 1768 |
# flags: --follow-imports=skip |
| 1769 |
import a |
| 1770 |
reveal_type(a.x) |
| 1771 |
[file a.py] |
| 1772 |
/ |
| 1773 |
[file a.py.2] |
| 1774 |
// |
| 1775 |
[out] |
| 1776 |
main:3: note: Revealed type is "Any" |
| 1777 |
[out2] |
| 1778 |
main:3: note: Revealed type is "Any" |
| 1779 |
|
| 1780 |
[case testIncrementalFollowImportsError] |
| 1781 |
# flags: --follow-imports=error |
| 1782 |
import a |
| 1783 |
[file a.py] |
| 1784 |
/ |
| 1785 |
[file a.py.2] |
| 1786 |
// |
| 1787 |
[out1] |
| 1788 |
main:2: error: Import of "a" ignored |
| 1789 |
main:2: note: (Using --follow-imports=error, module not passed on command line) |
| 1790 |
[out2] |
| 1791 |
main:2: error: Import of "a" ignored |
| 1792 |
main:2: note: (Using --follow-imports=error, module not passed on command line) |
| 1793 |
|
| 1794 |
[case testIncrementalFollowImportsVariable] |
| 1795 |
# flags: --config-file tmp/mypy.ini |
| 1796 |
import a |
| 1797 |
reveal_type(a.x) |
| 1798 |
[file a.py] |
| 1799 |
x = 0 |
| 1800 |
[file mypy.ini] |
| 1801 |
\[mypy] |
| 1802 |
follow_imports = normal |
| 1803 |
[file mypy.ini.2] |
| 1804 |
\[mypy] |
| 1805 |
follow_imports = skip |
| 1806 |
[out1] |
| 1807 |
main:3: note: Revealed type is "builtins.int" |
| 1808 |
[out2] |
| 1809 |
main:3: note: Revealed type is "Any" |
| 1810 |
|
| 1811 |
|
| 1812 |
[case testIncrementalFollowImportsVariablePyProjectTOML] |
| 1813 |
# flags: --config-file tmp/pyproject.toml |
| 1814 |
import a |
| 1815 |
reveal_type(a.x) |
| 1816 |
|
| 1817 |
[file a.py] |
| 1818 |
x = 0 |
| 1819 |
|
| 1820 |
[file pyproject.toml] |
| 1821 |
\[tool.mypy] |
| 1822 |
follow_imports = 'normal' |
| 1823 |
|
| 1824 |
[file pyproject.toml.2] |
| 1825 |
\[tool.mypy] |
| 1826 |
follow_imports = 'skip' |
| 1827 |
|
| 1828 |
[out1] |
| 1829 |
main:3: note: Revealed type is "builtins.int" |
| 1830 |
|
| 1831 |
[out2] |
| 1832 |
main:3: note: Revealed type is "Any" |
| 1833 |
|
| 1834 |
|
| 1835 |
[case testIncrementalIgnoreErrors] |
| 1836 |
# flags: --config-file tmp/mypy.ini |
| 1837 |
import a |
| 1838 |
[file a.py] |
| 1839 |
import module_that_will_be_deleted |
| 1840 |
[file module_that_will_be_deleted.py] |
| 1841 |
|
| 1842 |
[file mypy.ini] |
| 1843 |
\[mypy] |
| 1844 |
\[mypy-a] |
| 1845 |
ignore_errors = True |
| 1846 |
[delete module_that_will_be_deleted.py.2] |
| 1847 |
[out1] |
| 1848 |
[out2] |
| 1849 |
|
| 1850 |
[case testIncrementalNamedTupleInMethod] |
| 1851 |
from ntcrash import nope |
| 1852 |
[file ntcrash.py] |
| 1853 |
from typing import NamedTuple |
| 1854 |
class C: |
| 1855 |
def f(self) -> None: |
| 1856 |
A = NamedTuple('A', [('x', int), ('y', int)]) |
| 1857 |
[builtins fixtures/tuple.pyi] |
| 1858 |
[out1] |
| 1859 |
main:1: error: Module "ntcrash" has no attribute "nope" |
| 1860 |
[out2] |
| 1861 |
main:1: error: Module "ntcrash" has no attribute "nope" |
| 1862 |
|
| 1863 |
[case testIncrementalNamedTupleInMethod2] |
| 1864 |
from ntcrash import nope |
| 1865 |
[file ntcrash.py] |
| 1866 |
from typing import NamedTuple |
| 1867 |
class C: |
| 1868 |
class D: |
| 1869 |
def f(self) -> None: |
| 1870 |
A = NamedTuple('A', [('x', int), ('y', int)]) |
| 1871 |
[builtins fixtures/tuple.pyi] |
| 1872 |
[out1] |
| 1873 |
main:1: error: Module "ntcrash" has no attribute "nope" |
| 1874 |
[out2] |
| 1875 |
main:1: error: Module "ntcrash" has no attribute "nope" |
| 1876 |
|
| 1877 |
[case testIncrementalNamedTupleInMethod3] |
| 1878 |
from ntcrash import nope |
| 1879 |
[file ntcrash.py] |
| 1880 |
from typing import NamedTuple |
| 1881 |
class C: |
| 1882 |
def a(self): |
| 1883 |
class D: |
| 1884 |
def f(self) -> None: |
| 1885 |
A = NamedTuple('A', [('x', int), ('y', int)]) |
| 1886 |
[builtins fixtures/tuple.pyi] |
| 1887 |
[out1] |
| 1888 |
main:1: error: Module "ntcrash" has no attribute "nope" |
| 1889 |
[out2] |
| 1890 |
main:1: error: Module "ntcrash" has no attribute "nope" |
| 1891 |
|
| 1892 |
[case testIncrementalTypedDictInMethod] |
| 1893 |
from tdcrash import nope |
| 1894 |
[file tdcrash.py] |
| 1895 |
from typing import TypedDict |
| 1896 |
class C: |
| 1897 |
def f(self) -> None: |
| 1898 |
A = TypedDict('A', {'x': int, 'y': int}) |
| 1899 |
[builtins fixtures/dict.pyi] |
| 1900 |
[typing fixtures/typing-typeddict.pyi] |
| 1901 |
[out1] |
| 1902 |
main:1: error: Module "tdcrash" has no attribute "nope" |
| 1903 |
[out2] |
| 1904 |
main:1: error: Module "tdcrash" has no attribute "nope" |
| 1905 |
|
| 1906 |
[case testIncrementalTypedDictInMethod2] |
| 1907 |
from tdcrash import nope |
| 1908 |
[file tdcrash.py] |
| 1909 |
from typing import TypedDict |
| 1910 |
class C: |
| 1911 |
class D: |
| 1912 |
def f(self) -> None: |
| 1913 |
A = TypedDict('A', {'x': int, 'y': int}) |
| 1914 |
[builtins fixtures/dict.pyi] |
| 1915 |
[typing fixtures/typing-typeddict.pyi] |
| 1916 |
[out1] |
| 1917 |
main:1: error: Module "tdcrash" has no attribute "nope" |
| 1918 |
[out2] |
| 1919 |
main:1: error: Module "tdcrash" has no attribute "nope" |
| 1920 |
|
| 1921 |
[case testIncrementalTypedDictInMethod3] |
| 1922 |
from tdcrash import nope |
| 1923 |
[file tdcrash.py] |
| 1924 |
from typing import TypedDict |
| 1925 |
class C: |
| 1926 |
def a(self): |
| 1927 |
class D: |
| 1928 |
def f(self) -> None: |
| 1929 |
A = TypedDict('A', {'x': int, 'y': int}) |
| 1930 |
[builtins fixtures/dict.pyi] |
| 1931 |
[typing fixtures/typing-typeddict.pyi] |
| 1932 |
[out1] |
| 1933 |
main:1: error: Module "tdcrash" has no attribute "nope" |
| 1934 |
[out2] |
| 1935 |
main:1: error: Module "tdcrash" has no attribute "nope" |
| 1936 |
|
| 1937 |
[case testIncrementalNewTypeInMethod] |
| 1938 |
from ntcrash import nope |
| 1939 |
[file ntcrash.py] |
| 1940 |
from typing import NewType, NamedTuple, TypedDict |
| 1941 |
class C: |
| 1942 |
def f(self) -> None: |
| 1943 |
X = NewType('X', int) |
| 1944 |
A = TypedDict('A', {'x': X, 'y': int}) |
| 1945 |
B = NamedTuple('B', [('x', X)]) |
| 1946 |
|
| 1947 |
def f() -> None: |
| 1948 |
X = NewType('X', int) |
| 1949 |
A = TypedDict('A', {'x': X, 'y': int}) |
| 1950 |
B = NamedTuple('B', [('x', X)]) |
| 1951 |
|
| 1952 |
[builtins fixtures/dict.pyi] |
| 1953 |
[typing fixtures/typing-typeddict.pyi] |
| 1954 |
[out1] |
| 1955 |
main:1: error: Module "ntcrash" has no attribute "nope" |
| 1956 |
[out2] |
| 1957 |
main:1: error: Module "ntcrash" has no attribute "nope" |
| 1958 |
|
| 1959 |
[case testIncrementalInnerClassAttrInMethod] |
| 1960 |
import crash |
| 1961 |
nonexisting |
| 1962 |
[file crash.py] |
| 1963 |
class C: |
| 1964 |
def f(self) -> None: |
| 1965 |
class A: |
| 1966 |
pass |
| 1967 |
self.a = A() |
| 1968 |
[out1] |
| 1969 |
main:2: error: Name "nonexisting" is not defined |
| 1970 |
[out2] |
| 1971 |
main:2: error: Name "nonexisting" is not defined |
| 1972 |
|
| 1973 |
[case testIncrementalInnerClassAttrInMethodReveal] |
| 1974 |
import crash |
| 1975 |
reveal_type(crash.C().a) |
| 1976 |
reveal_type(crash.D().a) |
| 1977 |
[file crash.py] |
| 1978 |
from typing import TypeVar, Generic |
| 1979 |
T = TypeVar('T') |
| 1980 |
class C: |
| 1981 |
def f(self) -> None: |
| 1982 |
class A: |
| 1983 |
pass |
| 1984 |
self.a = A() |
| 1985 |
reveal_type(C().a) |
| 1986 |
class D: |
| 1987 |
def f(self) -> None: |
| 1988 |
class A: |
| 1989 |
def g(self) -> None: |
| 1990 |
class B(Generic[T]): |
| 1991 |
pass |
| 1992 |
self.b = B[int]() |
| 1993 |
self.a = A().b |
| 1994 |
reveal_type(D().a) |
| 1995 |
[out1] |
| 1996 |
tmp/crash.py:8: note: Revealed type is "crash.A@5" |
| 1997 |
tmp/crash.py:17: note: Revealed type is "crash.B@13[builtins.int]" |
| 1998 |
main:2: note: Revealed type is "crash.A@5" |
| 1999 |
main:3: note: Revealed type is "crash.B@13[builtins.int]" |
| 2000 |
[out2] |
| 2001 |
tmp/crash.py:8: note: Revealed type is "crash.A@5" |
| 2002 |
tmp/crash.py:17: note: Revealed type is "crash.B@13[builtins.int]" |
| 2003 |
main:2: note: Revealed type is "crash.A@5" |
| 2004 |
main:3: note: Revealed type is "crash.B@13[builtins.int]" |
| 2005 |
|
| 2006 |
[case testGenericMethodRestoreMetaLevel] |
| 2007 |
from typing import Dict |
| 2008 |
|
| 2009 |
d = {} # type: Dict[str, int] |
| 2010 |
g = d.get # This should not crash: see https://github.com/python/mypy/issues/2804 |
| 2011 |
[builtins fixtures/dict.pyi] |
| 2012 |
|
| 2013 |
[case testGenericMethodRestoreMetaLevel2] |
| 2014 |
from typing import TypeVar |
| 2015 |
|
| 2016 |
T = TypeVar('T') |
| 2017 |
|
| 2018 |
class D: |
| 2019 |
def m(self, x: T) -> T: |
| 2020 |
return x |
| 2021 |
|
| 2022 |
g = D().m # This should not crash: see https://github.com/python/mypy/issues/2804 |
| 2023 |
[builtins fixtures/dict.pyi] |
| 2024 |
|
| 2025 |
[case testGenericMethodRestoreMetaLevel3] |
| 2026 |
from typing import TypeVar |
| 2027 |
T = TypeVar('T') |
| 2028 |
|
| 2029 |
class C: |
| 2030 |
def m(self, x: T) -> T: |
| 2031 |
return x |
| 2032 |
|
| 2033 |
class D(C): |
| 2034 |
def __init__(self) -> None: |
| 2035 |
self.d = super().m # This should not crash: see https://github.com/python/mypy/issues/2804 |
| 2036 |
[builtins fixtures/dict.pyi] |
| 2037 |
|
| 2038 |
[case testIncrementalPerFileFlags] |
| 2039 |
# flags: --config-file tmp/mypy.ini |
| 2040 |
import a |
| 2041 |
[file a.py] |
| 2042 |
pass |
| 2043 |
[file mypy.ini] |
| 2044 |
\[mypy] |
| 2045 |
warn_no_return = False |
| 2046 |
\[mypy-a] |
| 2047 |
warn_no_return = True |
| 2048 |
[rechecked] |
| 2049 |
|
| 2050 |
[case testIncrementalClassVar] |
| 2051 |
from typing import ClassVar |
| 2052 |
class A: |
| 2053 |
x: ClassVar |
| 2054 |
A().x = 0 |
| 2055 |
[out1] |
| 2056 |
main:4: error: Cannot assign to class variable "x" via instance |
| 2057 |
[out2] |
| 2058 |
main:4: error: Cannot assign to class variable "x" via instance |
| 2059 |
|
| 2060 |
[case testIncrementalClassVarGone] |
| 2061 |
import m |
| 2062 |
m.A().x = 0 |
| 2063 |
[file m.py] |
| 2064 |
from typing import ClassVar |
| 2065 |
class A: |
| 2066 |
x: ClassVar[int] |
| 2067 |
[file m.py.2] |
| 2068 |
class A: |
| 2069 |
x: int |
| 2070 |
[out1] |
| 2071 |
main:2: error: Cannot assign to class variable "x" via instance |
| 2072 |
|
| 2073 |
[case testCachingClassVar] |
| 2074 |
import b |
| 2075 |
[file a.py] |
| 2076 |
from typing import ClassVar |
| 2077 |
class A: |
| 2078 |
x: ClassVar[int] |
| 2079 |
[file b.py] |
| 2080 |
import a |
| 2081 |
[file b.py.2] |
| 2082 |
import a |
| 2083 |
a.A().x = 0 |
| 2084 |
[out2] |
| 2085 |
tmp/b.py:2: error: Cannot assign to class variable "x" via instance |
| 2086 |
|
| 2087 |
[case testSerializeTypedDict] |
| 2088 |
import b |
| 2089 |
reveal_type(b.x) |
| 2090 |
y: b.A |
| 2091 |
reveal_type(y) |
| 2092 |
[file b.py] |
| 2093 |
from typing import TypedDict |
| 2094 |
A = TypedDict('A', {'x': int, 'y': str}) |
| 2095 |
x: A |
| 2096 |
[builtins fixtures/dict.pyi] |
| 2097 |
[typing fixtures/typing-typeddict.pyi] |
| 2098 |
[out1] |
| 2099 |
main:2: note: Revealed type is "TypedDict('b.A', {'x': builtins.int, 'y': builtins.str})" |
| 2100 |
main:4: note: Revealed type is "TypedDict('b.A', {'x': builtins.int, 'y': builtins.str})" |
| 2101 |
[out2] |
| 2102 |
main:2: note: Revealed type is "TypedDict('b.A', {'x': builtins.int, 'y': builtins.str})" |
| 2103 |
main:4: note: Revealed type is "TypedDict('b.A', {'x': builtins.int, 'y': builtins.str})" |
| 2104 |
|
| 2105 |
[case testSerializeMetaclass] |
| 2106 |
import b |
| 2107 |
reveal_type(b.A.f()) |
| 2108 |
m: b.M = b.A |
| 2109 |
reveal_type(b.a.f()) |
| 2110 |
[file b.py] |
| 2111 |
from typing import Type |
| 2112 |
|
| 2113 |
class M(type): |
| 2114 |
def f(cls) -> int: return 0 |
| 2115 |
class A(metaclass=M): pass |
| 2116 |
a: Type[A] |
| 2117 |
[out] |
| 2118 |
main:2: note: Revealed type is "builtins.int" |
| 2119 |
main:4: note: Revealed type is "builtins.int" |
| 2120 |
[out2] |
| 2121 |
main:2: note: Revealed type is "builtins.int" |
| 2122 |
main:4: note: Revealed type is "builtins.int" |
| 2123 |
|
| 2124 |
[case testSerializeMetaclassInImportCycle1] |
| 2125 |
import b |
| 2126 |
import c |
| 2127 |
reveal_type(b.A.f()) |
| 2128 |
m: c.M = b.A |
| 2129 |
reveal_type(b.a.f()) |
| 2130 |
[file b.py] |
| 2131 |
from typing import Type |
| 2132 |
from c import M |
| 2133 |
class A(metaclass=M): pass |
| 2134 |
a: Type[A] |
| 2135 |
[file c.py] |
| 2136 |
class M(type): |
| 2137 |
def f(cls) -> int: return 0 |
| 2138 |
[out] |
| 2139 |
main:3: note: Revealed type is "builtins.int" |
| 2140 |
main:5: note: Revealed type is "builtins.int" |
| 2141 |
[out2] |
| 2142 |
main:3: note: Revealed type is "builtins.int" |
| 2143 |
main:5: note: Revealed type is "builtins.int" |
| 2144 |
|
| 2145 |
[case testSerializeMetaclassInImportCycle2] |
| 2146 |
import b |
| 2147 |
import c |
| 2148 |
reveal_type(c.A.f()) |
| 2149 |
m: b.M = c.A |
| 2150 |
reveal_type(c.a.f()) |
| 2151 |
[file b.py] |
| 2152 |
from c import a |
| 2153 |
class M(type): |
| 2154 |
def f(cls) -> int: return 0 |
| 2155 |
[file c.py] |
| 2156 |
from typing import Type |
| 2157 |
import b |
| 2158 |
class A(metaclass=b.M): pass |
| 2159 |
a: Type[A] |
| 2160 |
[out] |
| 2161 |
main:3: note: Revealed type is "builtins.int" |
| 2162 |
main:5: note: Revealed type is "builtins.int" |
| 2163 |
[out2] |
| 2164 |
main:3: note: Revealed type is "builtins.int" |
| 2165 |
main:5: note: Revealed type is "builtins.int" |
| 2166 |
|
| 2167 |
[case testDeleteFile] |
| 2168 |
import n |
| 2169 |
[file n.py] |
| 2170 |
import m |
| 2171 |
[file m.py] |
| 2172 |
x = 1 |
| 2173 |
[delete m.py.2] |
| 2174 |
[rechecked n] |
| 2175 |
[stale n] |
| 2176 |
[out2] |
| 2177 |
tmp/n.py:1: error: Cannot find implementation or library stub for module named "m" |
| 2178 |
tmp/n.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports |
| 2179 |
|
| 2180 |
[case testDeleteFileWithinCycle] |
| 2181 |
import a |
| 2182 |
[file a.py] |
| 2183 |
import b |
| 2184 |
[file b.py] |
| 2185 |
import c |
| 2186 |
[file c.py] |
| 2187 |
import a |
| 2188 |
[file a.py.2] |
| 2189 |
import c |
| 2190 |
[delete b.py.2] |
| 2191 |
[rechecked a, c] |
| 2192 |
[stale a] |
| 2193 |
[out2] |
| 2194 |
|
| 2195 |
[case testThreePassesBasic] |
| 2196 |
import m |
| 2197 |
[file m.py] |
| 2198 |
def foo(): |
| 2199 |
pass |
| 2200 |
[file m.py.2] |
| 2201 |
def foo() -> None: |
| 2202 |
pass |
| 2203 |
[file m.py.3] |
| 2204 |
def foo(): |
| 2205 |
pass |
| 2206 |
[rechecked m] |
| 2207 |
[stale m] |
| 2208 |
[rechecked2 m] |
| 2209 |
[stale2 m] |
| 2210 |
[out3] |
| 2211 |
|
| 2212 |
[case testThreePassesErrorInThirdPass] |
| 2213 |
import m |
| 2214 |
[file m.py] |
| 2215 |
def foo(): |
| 2216 |
pass |
| 2217 |
[file m.py.2] |
| 2218 |
def foo() -> None: |
| 2219 |
pass |
| 2220 |
[file m.py.3] |
| 2221 |
def foo() -> int: |
| 2222 |
return '' |
| 2223 |
[rechecked m] |
| 2224 |
[stale m] |
| 2225 |
[rechecked2 m] |
| 2226 |
[stale2 m] |
| 2227 |
[out3] |
| 2228 |
tmp/m.py:2: error: Incompatible return value type (got "str", expected "int") |
| 2229 |
|
| 2230 |
[case testThreePassesThirdPassFixesError] |
| 2231 |
import n |
| 2232 |
[file n.py] |
| 2233 |
import m |
| 2234 |
x = m.foo(1) |
| 2235 |
[file m.py] |
| 2236 |
def foo(x): |
| 2237 |
pass |
| 2238 |
[file m.py.2] |
| 2239 |
def foo() -> str: |
| 2240 |
pass |
| 2241 |
[file m.py.3] |
| 2242 |
def foo(x) -> int: |
| 2243 |
pass |
| 2244 |
[rechecked m, n] |
| 2245 |
[stale m, n] |
| 2246 |
[rechecked2 m, n] |
| 2247 |
[stale2 m, n] |
| 2248 |
[out2] |
| 2249 |
tmp/n.py:2: error: Too many arguments for "foo" |
| 2250 |
[out3] |
| 2251 |
|
| 2252 |
[case testCacheDeletedAfterErrorsFound] |
| 2253 |
import a |
| 2254 |
[file a.py] |
| 2255 |
from b import x |
| 2256 |
[file b.py] |
| 2257 |
from c import x |
| 2258 |
[file c.py] |
| 2259 |
x = 1 |
| 2260 |
[file c.py.2] |
| 2261 |
1 + 1 |
| 2262 |
[file a.py.3] |
| 2263 |
from b import x |
| 2264 |
1 + 1 |
| 2265 |
[out] |
| 2266 |
[out2] |
| 2267 |
tmp/b.py:1: error: Module "c" has no attribute "x" |
| 2268 |
[out3] |
| 2269 |
tmp/b.py:1: error: Module "c" has no attribute "x" |
| 2270 |
|
| 2271 |
[case testCacheDeletedAfterErrorsFound2] |
| 2272 |
|
| 2273 |
import a |
| 2274 |
[file a.py] |
| 2275 |
from b import x |
| 2276 |
[file b.py] |
| 2277 |
from c import C |
| 2278 |
x: C |
| 2279 |
[file c.py] |
| 2280 |
class C: pass |
| 2281 |
[file c.py.2] |
| 2282 |
def C(): pass |
| 2283 |
[file a.py.3] |
| 2284 |
from b import x |
| 2285 |
1 + 1 |
| 2286 |
[out] |
| 2287 |
[out2] |
| 2288 |
tmp/b.py:2: error: Function "c.C" is not valid as a type |
| 2289 |
tmp/b.py:2: note: Perhaps you need "Callable[...]" or a callback protocol? |
| 2290 |
[out3] |
| 2291 |
tmp/b.py:2: error: Function "c.C" is not valid as a type |
| 2292 |
tmp/b.py:2: note: Perhaps you need "Callable[...]" or a callback protocol? |
| 2293 |
|
| 2294 |
[case testCacheDeletedAfterErrorsFound3] |
| 2295 |
import a |
| 2296 |
[file a.py] |
| 2297 |
import b |
| 2298 |
b.f() |
| 2299 |
[file b.py] |
| 2300 |
def f() -> None: pass |
| 2301 |
[file b.py.2] |
| 2302 |
def f(x) -> None: pass |
| 2303 |
[out] |
| 2304 |
[out2] |
| 2305 |
tmp/a.py:2: error: Missing positional argument "x" in call to "f" |
| 2306 |
[out3] |
| 2307 |
tmp/a.py:2: error: Missing positional argument "x" in call to "f" |
| 2308 |
|
| 2309 |
[case testCacheDeletedAfterErrorsFound4] |
| 2310 |
import a |
| 2311 |
[file a.py] |
| 2312 |
from b import x |
| 2313 |
[file b.py] |
| 2314 |
from c import x |
| 2315 |
[file c.py] |
| 2316 |
from d import x |
| 2317 |
[file d.py] |
| 2318 |
x = 1 |
| 2319 |
[file d.py.2] |
| 2320 |
1 + 1 |
| 2321 |
[file a.py.3] |
| 2322 |
from b import x |
| 2323 |
1 + 1 |
| 2324 |
[out] |
| 2325 |
[out2] |
| 2326 |
tmp/c.py:1: error: Module "d" has no attribute "x" |
| 2327 |
[out3] |
| 2328 |
tmp/c.py:1: error: Module "d" has no attribute "x" |
| 2329 |
|
| 2330 |
[case testNoCrashOnDeletedWithCacheOnCmdline] |
| 2331 |
# cmd: mypy -m nonexistent |
| 2332 |
# cmd2: mypy -m nonexistent |
| 2333 |
[file nonexistent.py] |
| 2334 |
[delete nonexistent.py.2] |
| 2335 |
[out] |
| 2336 |
[out2] |
| 2337 |
mypy: error: Cannot read file 'tmp/nonexistent.py': No such file or directory |
| 2338 |
|
| 2339 |
[case testSerializeAbstractPropertyIncremental] |
| 2340 |
from abc import abstractmethod |
| 2341 |
import typing |
| 2342 |
class A: |
| 2343 |
@property |
| 2344 |
def f(self) -> int: |
| 2345 |
return 1 |
| 2346 |
@f.setter # type: ignore |
| 2347 |
@abstractmethod |
| 2348 |
def f(self, x: int) -> None: |
| 2349 |
pass |
| 2350 |
a = A() |
| 2351 |
[builtins fixtures/property.pyi] |
| 2352 |
|
| 2353 |
[case testSerializeAbstractPropertyDisallowUntypedIncremental] |
| 2354 |
# flags: --disallow-untyped-defs |
| 2355 |
from abc import abstractmethod |
| 2356 |
import typing |
| 2357 |
class A: |
| 2358 |
@property |
| 2359 |
def f(self) -> int: |
| 2360 |
return 1 |
| 2361 |
@f.setter # type: ignore |
| 2362 |
@abstractmethod |
| 2363 |
def f(self, x: int) -> None: |
| 2364 |
pass |
| 2365 |
a = A() |
| 2366 |
[builtins fixtures/property.pyi] |
| 2367 |
|
| 2368 |
[case testClassNamesResolutionCrashAccess] |
| 2369 |
import mod |
| 2370 |
|
| 2371 |
[file mod.py] |
| 2372 |
class C: |
| 2373 |
def __init__(self) -> None: |
| 2374 |
self.int = '' |
| 2375 |
|
| 2376 |
def f(self, f: int) -> None: |
| 2377 |
pass |
| 2378 |
|
| 2379 |
[file mod.py.2] |
| 2380 |
class C: |
| 2381 |
def __init__(self) -> None: |
| 2382 |
self.int = '' |
| 2383 |
|
| 2384 |
def f(self, f: int) -> None: |
| 2385 |
f.x |
| 2386 |
|
| 2387 |
[out] |
| 2388 |
[out2] |
| 2389 |
tmp/mod.py:6: error: "int" has no attribute "x" |
| 2390 |
|
| 2391 |
[case testClassNamesResolutionCrashReadCache] |
| 2392 |
import mod |
| 2393 |
|
| 2394 |
[file mod.py] |
| 2395 |
import submod |
| 2396 |
|
| 2397 |
[file mod.py.2] |
| 2398 |
from submod import C |
| 2399 |
|
| 2400 |
c = C() |
| 2401 |
reveal_type(c.int) |
| 2402 |
reveal_type(c.y) |
| 2403 |
|
| 2404 |
[file submod.py] |
| 2405 |
from typing import List |
| 2406 |
|
| 2407 |
class C: |
| 2408 |
def __init__(self) -> None: |
| 2409 |
self.int = [] # type: List[int] |
| 2410 |
|
| 2411 |
def f(self, f: int) -> None: |
| 2412 |
self.y = f |
| 2413 |
|
| 2414 |
[builtins fixtures/list.pyi] |
| 2415 |
[out] |
| 2416 |
[out2] |
| 2417 |
tmp/mod.py:4: note: Revealed type is "builtins.list[builtins.int]" |
| 2418 |
tmp/mod.py:5: note: Revealed type is "builtins.int" |
| 2419 |
|
| 2420 |
[case testClassNamesResolutionCrashReveal] |
| 2421 |
import mod |
| 2422 |
|
| 2423 |
[file mod.py] |
| 2424 |
class Foo(object): |
| 2425 |
|
| 2426 |
def __init__(self) -> None: |
| 2427 |
self.bytes = b"foo" |
| 2428 |
|
| 2429 |
def bar(self, f: bytes): |
| 2430 |
pass |
| 2431 |
|
| 2432 |
foo = Foo() |
| 2433 |
foo.bar(b"test") |
| 2434 |
|
| 2435 |
[file mod.py.2] |
| 2436 |
class Foo(object): |
| 2437 |
|
| 2438 |
def __init__(self) -> None: |
| 2439 |
self.bytes = b"foo" |
| 2440 |
|
| 2441 |
def bar(self, f: bytes): |
| 2442 |
reveal_type(f) |
| 2443 |
|
| 2444 |
foo = Foo() |
| 2445 |
foo.bar(b"test") |
| 2446 |
[out] |
| 2447 |
[out2] |
| 2448 |
tmp/mod.py:7: note: Revealed type is "builtins.bytes" |
| 2449 |
|
| 2450 |
[case testIncrementalWithSilentImports] |
| 2451 |
# cmd: mypy -m a |
| 2452 |
# cmd2: mypy -m b |
| 2453 |
# flags: --follow-imports=silent |
| 2454 |
[file a.py] |
| 2455 |
import b |
| 2456 |
|
| 2457 |
b.foo(1, 2) |
| 2458 |
|
| 2459 |
[file b.py] |
| 2460 |
def foo(a: int, b: int) -> str: |
| 2461 |
return a + b |
| 2462 |
|
| 2463 |
[out1] |
| 2464 |
[out2] |
| 2465 |
tmp/b.py:2: error: Incompatible return value type (got "int", expected "str") |
| 2466 |
|
| 2467 |
[case testIncrementalWithSilentImportsReverse] |
| 2468 |
-- Same commands as previous test, just in reverse order. |
| 2469 |
-- expected output is also in reverse order |
| 2470 |
# cmd: mypy -m b |
| 2471 |
# cmd2: mypy -m a |
| 2472 |
# flags: --follow-imports=silent |
| 2473 |
[file a.py] |
| 2474 |
import b |
| 2475 |
|
| 2476 |
b.foo(1, 2) |
| 2477 |
|
| 2478 |
[file b.py] |
| 2479 |
def foo(a: int, b: int) -> str: |
| 2480 |
return a + b |
| 2481 |
|
| 2482 |
[out] |
| 2483 |
tmp/b.py:2: error: Incompatible return value type (got "int", expected "str") |
| 2484 |
[out2] |
| 2485 |
|
| 2486 |
[case testForwardNamedTupleToUnionWithOtherNamedTUple] |
| 2487 |
from typing import NamedTuple, Union |
| 2488 |
|
| 2489 |
class Person(NamedTuple): |
| 2490 |
name: Union[str, "Pair"] |
| 2491 |
|
| 2492 |
class Pair(NamedTuple): |
| 2493 |
first: str |
| 2494 |
last: str |
| 2495 |
|
| 2496 |
Person(name=Pair(first="John", last="Doe")) |
| 2497 |
[builtins fixtures/tuple.pyi] |
| 2498 |
[out] |
| 2499 |
|
| 2500 |
[case testNoCrashForwardRefToBrokenDoubleNewTypeIncremental] |
| 2501 |
from typing import Any, List, NewType |
| 2502 |
|
| 2503 |
Foo = NewType('NotFoo', int) # type: ignore |
| 2504 |
Foos = NewType('Foos', List[Foo]) # type: ignore |
| 2505 |
|
| 2506 |
def frob(foos: List[Foos]) -> None: |
| 2507 |
pass |
| 2508 |
[builtins fixtures/list.pyi] |
| 2509 |
[out] |
| 2510 |
|
| 2511 |
[case testNoCrashForwardRefOverloadIncremental] |
| 2512 |
from typing import overload, List |
| 2513 |
|
| 2514 |
@overload |
| 2515 |
def f(x: int) -> int: ... |
| 2516 |
@overload |
| 2517 |
def f(x: F) -> F: ... |
| 2518 |
def f(x): |
| 2519 |
pass |
| 2520 |
|
| 2521 |
F = List[int] |
| 2522 |
[builtins fixtures/list.pyi] |
| 2523 |
[out] |
| 2524 |
|
| 2525 |
[case testNoCrashForwardRefOverloadIncrementalClass] |
| 2526 |
from typing import overload, Tuple, NamedTuple |
| 2527 |
|
| 2528 |
x: C |
| 2529 |
class C: |
| 2530 |
@overload |
| 2531 |
def f(self, x: str) -> N: pass |
| 2532 |
@overload |
| 2533 |
def f(self, x: int) -> int: pass |
| 2534 |
def f(self, x): |
| 2535 |
pass |
| 2536 |
|
| 2537 |
class N(NamedTuple): |
| 2538 |
x: A |
| 2539 |
A = Tuple[int] |
| 2540 |
[builtins fixtures/tuple.pyi] |
| 2541 |
[out] |
| 2542 |
|
| 2543 |
[case testNewTypeFromForwardNamedTupleIncremental] |
| 2544 |
from typing import NewType, NamedTuple, Tuple |
| 2545 |
|
| 2546 |
NT = NewType('NT', 'N') |
| 2547 |
class N(NamedTuple): |
| 2548 |
x: int |
| 2549 |
|
| 2550 |
x: NT = N(1) # type: ignore |
| 2551 |
x = NT(N(1)) |
| 2552 |
[builtins fixtures/tuple.pyi] |
| 2553 |
[out] |
| 2554 |
|
| 2555 |
[case testNewTypeFromForwardTypedDictIncremental] |
| 2556 |
from typing import NewType, Tuple, TypedDict, Dict |
| 2557 |
|
| 2558 |
NT = NewType('NT', N) # type: ignore |
| 2559 |
class N(TypedDict): |
| 2560 |
x: A |
| 2561 |
A = Dict[str, int] |
| 2562 |
[builtins fixtures/dict.pyi] |
| 2563 |
[typing fixtures/typing-typeddict.pyi] |
| 2564 |
[out] |
| 2565 |
|
| 2566 |
-- Some crazy self-referential named tuples, types dicts, and aliases |
| 2567 |
-- to be sure that everything can be _serialized_ (i.e. ForwardRefs are removed). |
| 2568 |
-- For this reason errors are silenced (tests with # type: ignore have equivalents in other files) |
| 2569 |
|
| 2570 |
[case testForwardTypeAliasInBase1] |
| 2571 |
from typing import List |
| 2572 |
class C(List['A']): |
| 2573 |
pass |
| 2574 |
|
| 2575 |
A = List[int] |
| 2576 |
x: int = C()[0][0] |
| 2577 |
[builtins fixtures/list.pyi] |
| 2578 |
[out] |
| 2579 |
|
| 2580 |
[case testForwardTypeAliasInBase2] |
| 2581 |
|
| 2582 |
from typing import List, Generic, TypeVar, NamedTuple |
| 2583 |
T = TypeVar('T') |
| 2584 |
|
| 2585 |
class C(A, B): # type: ignore |
| 2586 |
pass |
| 2587 |
class G(Generic[T]): pass |
| 2588 |
A = G[C] # type: ignore |
| 2589 |
class B(NamedTuple): |
| 2590 |
x: int |
| 2591 |
|
| 2592 |
C(1).x |
| 2593 |
C(1)[0] |
| 2594 |
[builtins fixtures/list.pyi] |
| 2595 |
[out] |
| 2596 |
|
| 2597 |
[case testSerializeRecursiveAlias] |
| 2598 |
from typing import Callable, Union |
| 2599 |
|
| 2600 |
Node = Union[str, int, Callable[[], "Node"]] |
| 2601 |
n: Node |
| 2602 |
[out] |
| 2603 |
|
| 2604 |
[case testSerializeRecursiveAliases1] |
| 2605 |
|
| 2606 |
from typing import Type, Callable, Union |
| 2607 |
|
| 2608 |
A = Union[A, int] # type: ignore |
| 2609 |
B = Callable[[B], int] # type: ignore |
| 2610 |
C = Type[C] # type: ignore |
| 2611 |
[out] |
| 2612 |
|
| 2613 |
[case testSerializeRecursiveAliases2] |
| 2614 |
|
| 2615 |
from typing import Type, Callable, Union |
| 2616 |
|
| 2617 |
A = Union[B, int] # type: ignore |
| 2618 |
B = Callable[[C], int] # type: ignore |
| 2619 |
C = Type[A] # type: ignore |
| 2620 |
[out] |
| 2621 |
|
| 2622 |
[case testSerializeRecursiveAliases3] |
| 2623 |
|
| 2624 |
from typing import Type, Callable, Union, NamedTuple |
| 2625 |
|
| 2626 |
A = Union[B, int] # type: ignore |
| 2627 |
B = Callable[[C], int] # type: ignore |
| 2628 |
class C(NamedTuple): # type: ignore |
| 2629 |
x: A |
| 2630 |
[builtins fixtures/tuple.pyi] |
| 2631 |
[out] |
| 2632 |
|
| 2633 |
[case testGenericTypeAliasesForwardAnyIncremental1] |
| 2634 |
from typing import TypeVar, Generic |
| 2635 |
T = TypeVar('T') |
| 2636 |
S = TypeVar('S') |
| 2637 |
IntNode = Node[int, S] # type: ignore[used-before-def] |
| 2638 |
AnyNode = Node[S, T] # type: ignore[used-before-def] |
| 2639 |
|
| 2640 |
class Node(Generic[T, S]): |
| 2641 |
def __init__(self, x: T, y: S) -> None: |
| 2642 |
self.x = x |
| 2643 |
self.y = y |
| 2644 |
|
| 2645 |
def output() -> IntNode[str]: |
| 2646 |
return Node(1, 'x') |
| 2647 |
x = output() # type: IntNode |
| 2648 |
|
| 2649 |
y: IntNode |
| 2650 |
y.x = 1 |
| 2651 |
y.y = 1 |
| 2652 |
y.y = 'x' |
| 2653 |
|
| 2654 |
z = Node(1, 'x') # type: AnyNode |
| 2655 |
[out] |
| 2656 |
|
| 2657 |
[case testGenericTypeAliasesForwardAnyIncremental2] |
| 2658 |
from typing import TypeVar, Generic |
| 2659 |
T = TypeVar('T') |
| 2660 |
S = TypeVar('S') |
| 2661 |
|
| 2662 |
class Node(Generic[T, S]): |
| 2663 |
def __init__(self, x: T, y: S) -> None: |
| 2664 |
self.x = x |
| 2665 |
self.y = y |
| 2666 |
|
| 2667 |
def output() -> IntNode[str]: |
| 2668 |
return Node(1, 'x') |
| 2669 |
x = output() # type: IntNode |
| 2670 |
|
| 2671 |
y: IntNode |
| 2672 |
y.x = 1 |
| 2673 |
y.y = 1 |
| 2674 |
y.y = 'x' |
| 2675 |
|
| 2676 |
z = Node(1, 'x') # type: AnyNode |
| 2677 |
IntNode = Node[int, S] |
| 2678 |
AnyNode = Node[S, T] |
| 2679 |
[out] |
| 2680 |
|
| 2681 |
[case testNamedTupleForwardAsUpperBoundSerialization] |
| 2682 |
from typing import NamedTuple, TypeVar, Generic |
| 2683 |
T = TypeVar('T', bound='M') |
| 2684 |
class G(Generic[T]): |
| 2685 |
x: T |
| 2686 |
|
| 2687 |
yg: G[M] |
| 2688 |
z: int = G[M]().x.x # type: ignore[used-before-def] |
| 2689 |
z = G[M]().x[0] # type: ignore[used-before-def] |
| 2690 |
M = NamedTuple('M', [('x', int)]) |
| 2691 |
[builtins fixtures/tuple.pyi] |
| 2692 |
[out] |
| 2693 |
|
| 2694 |
[case testSelfRefNTIncremental1] |
| 2695 |
|
| 2696 |
from typing import Tuple, NamedTuple |
| 2697 |
|
| 2698 |
Node = NamedTuple('Node', [ |
| 2699 |
('name', str), |
| 2700 |
('children', Tuple['Node', ...]), # type: ignore |
| 2701 |
]) |
| 2702 |
n: Node |
| 2703 |
[builtins fixtures/tuple.pyi] |
| 2704 |
|
| 2705 |
[case testSelfRefNTIncremental2] |
| 2706 |
|
| 2707 |
from typing import Tuple, NamedTuple |
| 2708 |
|
| 2709 |
A = NamedTuple('A', [ |
| 2710 |
('x', str), |
| 2711 |
('y', Tuple['B', ...]), # type: ignore |
| 2712 |
]) |
| 2713 |
class B(NamedTuple): |
| 2714 |
x: A |
| 2715 |
y: int |
| 2716 |
|
| 2717 |
n: A |
| 2718 |
[builtins fixtures/tuple.pyi] |
| 2719 |
|
| 2720 |
[case testSelfRefNTIncremental3] |
| 2721 |
|
| 2722 |
from typing import NamedTuple, Tuple |
| 2723 |
|
| 2724 |
class B(NamedTuple): |
| 2725 |
x: Tuple[A, int] # type: ignore |
| 2726 |
y: int |
| 2727 |
A = NamedTuple('A', [ |
| 2728 |
('x', str), |
| 2729 |
('y', 'B'), |
| 2730 |
]) |
| 2731 |
n: B |
| 2732 |
m: A |
| 2733 |
lst = [m, n] |
| 2734 |
[builtins fixtures/tuple.pyi] |
| 2735 |
|
| 2736 |
[case testSelfRefNTIncremental4] |
| 2737 |
|
| 2738 |
from typing import NamedTuple |
| 2739 |
|
| 2740 |
class B(NamedTuple): |
| 2741 |
x: A # type: ignore |
| 2742 |
y: int |
| 2743 |
class A(NamedTuple): |
| 2744 |
x: str |
| 2745 |
y: B |
| 2746 |
|
| 2747 |
n: A |
| 2748 |
[builtins fixtures/tuple.pyi] |
| 2749 |
|
| 2750 |
[case testSelfRefNTIncremental5] |
| 2751 |
|
| 2752 |
from typing import NamedTuple |
| 2753 |
|
| 2754 |
B = NamedTuple('B', [ |
| 2755 |
('x', A), # type: ignore |
| 2756 |
('y', int), |
| 2757 |
]) |
| 2758 |
A = NamedTuple('A', [ |
| 2759 |
('x', str), |
| 2760 |
('y', 'B'), |
| 2761 |
]) |
| 2762 |
n: A |
| 2763 |
def f(m: B) -> None: pass |
| 2764 |
[builtins fixtures/tuple.pyi] |
| 2765 |
|
| 2766 |
[case testCrashWithPartialGlobalAndCycle] |
| 2767 |
import bar |
| 2768 |
|
| 2769 |
[file foo.py] |
| 2770 |
import bar |
| 2771 |
my_global_dict = {} # type: ignore |
| 2772 |
def external_func_0() -> None: |
| 2773 |
global my_global_dict |
| 2774 |
bar.external_list |
| 2775 |
my_global_dict[12] = 0 |
| 2776 |
|
| 2777 |
[file bar.py] |
| 2778 |
import foo |
| 2779 |
|
| 2780 |
external_list = [0] |
| 2781 |
|
| 2782 |
[builtins fixtures/dict.pyi] |
| 2783 |
|
| 2784 |
[case testIncrementalCrashOnTypeWithFunction] |
| 2785 |
import a |
| 2786 |
[file a.py] |
| 2787 |
import b |
| 2788 |
[file a.py.2] |
| 2789 |
from b import x |
| 2790 |
|
| 2791 |
[file b.py] |
| 2792 |
from typing import TypeVar, Type |
| 2793 |
T = TypeVar('T') |
| 2794 |
|
| 2795 |
def tp(arg: T) -> Type[T]: |
| 2796 |
pass |
| 2797 |
def func(x: int) -> int: |
| 2798 |
pass |
| 2799 |
|
| 2800 |
x = tp(func) |
| 2801 |
[out] |
| 2802 |
[out2] |
| 2803 |
|
| 2804 |
[case testReprocessModuleEvenIfInterfaceHashDoesNotChange] |
| 2805 |
import a |
| 2806 |
import d |
| 2807 |
|
| 2808 |
[file a.py] |
| 2809 |
import b |
| 2810 |
x: b.c.A |
| 2811 |
x = b.c.A() |
| 2812 |
|
| 2813 |
[file b.py] |
| 2814 |
import c |
| 2815 |
|
| 2816 |
[file c.py] |
| 2817 |
class A: |
| 2818 |
x = 1 |
| 2819 |
|
| 2820 |
[file d.py] |
| 2821 |
import a |
| 2822 |
def f() -> None: pass |
| 2823 |
|
| 2824 |
[file a.py.2] |
| 2825 |
import b |
| 2826 |
x: b.c.A |
| 2827 |
|
| 2828 |
[file c.py.3] |
| 2829 |
class A: |
| 2830 |
x = 2 |
| 2831 |
|
| 2832 |
[file d.py.4] |
| 2833 |
import a |
| 2834 |
def f() -> None: |
| 2835 |
from c import A |
| 2836 |
a.x = [A(), a.x][0] |
| 2837 |
|
| 2838 |
[builtins fixtures/list.pyi] |
| 2839 |
[stale] |
| 2840 |
[rechecked a] |
| 2841 |
[stale2] |
| 2842 |
[rechecked2 c] |
| 2843 |
[stale3] |
| 2844 |
[rechecked3 d] |
| 2845 |
[out1] |
| 2846 |
[out2] |
| 2847 |
[out3] |
| 2848 |
[out4] |
| 2849 |
|
| 2850 |
[case testTreeShadowingViaParentPackage] |
| 2851 |
import m.semanal |
| 2852 |
|
| 2853 |
[file m/__init__.py] |
| 2854 |
pass |
| 2855 |
|
| 2856 |
[file m/nodes.py] |
| 2857 |
if False: |
| 2858 |
import m.types |
| 2859 |
import m.semanal |
| 2860 |
class Node: |
| 2861 |
line: int |
| 2862 |
class FuncBase(Node): |
| 2863 |
type: m.types.Type |
| 2864 |
class OverloadedFuncDef(FuncBase): pass |
| 2865 |
|
| 2866 |
[file m/types.py] |
| 2867 |
from m.nodes import Node |
| 2868 |
class Type(Node): pass |
| 2869 |
class Overloaded(Type): pass |
| 2870 |
|
| 2871 |
[file m/semanal.py] |
| 2872 |
from m.nodes import OverloadedFuncDef |
| 2873 |
from m.types import Overloaded |
| 2874 |
|
| 2875 |
class C: |
| 2876 |
def func(self, defn: OverloadedFuncDef): |
| 2877 |
defn.type = Overloaded() |
| 2878 |
defn.type.line = 0 |
| 2879 |
|
| 2880 |
[file m/nodes.py.2] |
| 2881 |
if False: |
| 2882 |
import m.types |
| 2883 |
import m.semanal |
| 2884 |
class Node: |
| 2885 |
line: int |
| 2886 |
class FuncBase(Node): |
| 2887 |
type: m.types.Type |
| 2888 |
class OverloadedFuncDef(FuncBase): pass |
| 2889 |
extra = 1 |
| 2890 |
|
| 2891 |
[file m/types.py.2] |
| 2892 |
from m.nodes import Node |
| 2893 |
class Type(Node): pass |
| 2894 |
class Overloaded(Type): pass |
| 2895 |
extra = 1 |
| 2896 |
[builtins fixtures/list.pyi] |
| 2897 |
|
| 2898 |
[file m/semanal.py.2] |
| 2899 |
from m.nodes import OverloadedFuncDef |
| 2900 |
from m.types import Overloaded |
| 2901 |
|
| 2902 |
class C: |
| 2903 |
def func(self, defn: OverloadedFuncDef): |
| 2904 |
defn.type = Overloaded() |
| 2905 |
defn.type.line = 0 |
| 2906 |
|
| 2907 |
extra = 1 |
| 2908 |
|
| 2909 |
[out1] |
| 2910 |
[out2] |
| 2911 |
|
| 2912 |
[case testErrorsAffectDependentsOnly] |
| 2913 |
# cmd: mypy -m m.a m.b m.c |
| 2914 |
[file m/__init__.py] |
| 2915 |
[file m/a.py] |
| 2916 |
1 + '' # Deliberate error |
| 2917 |
[file m/b.py] |
| 2918 |
import m.a # Depends on module with error |
| 2919 |
[file m/c.py] |
| 2920 |
import m # No error here |
| 2921 |
[rechecked] |
| 2922 |
[out1] |
| 2923 |
tmp/m/a.py:1: error: Unsupported operand types for + ("int" and "str") |
| 2924 |
[out2] |
| 2925 |
tmp/m/a.py:1: error: Unsupported operand types for + ("int" and "str") |
| 2926 |
|
| 2927 |
[case testDisallowAnyExprIncremental] |
| 2928 |
# cmd: mypy -m main |
| 2929 |
# flags: --disallow-any-expr |
| 2930 |
|
| 2931 |
[file ns.py] |
| 2932 |
class Namespace: |
| 2933 |
def __init__(self): |
| 2934 |
self.user = 0 |
| 2935 |
|
| 2936 |
[file main.py] |
| 2937 |
import ns |
| 2938 |
user = ns.Namespace().user |
| 2939 |
|
| 2940 |
[out1] |
| 2941 |
tmp/main.py:2: error: Expression has type "Any" |
| 2942 |
|
| 2943 |
[out2] |
| 2944 |
tmp/main.py:2: error: Expression has type "Any" |
| 2945 |
|
| 2946 |
[case testIncrementalStrictOptional] |
| 2947 |
import a |
| 2948 |
1 + a.foo() |
| 2949 |
[file a.py] |
| 2950 |
def foo() -> int: return 0 |
| 2951 |
[file a.py.2] |
| 2952 |
from typing import Optional |
| 2953 |
def foo() -> Optional[int]: return 0 |
| 2954 |
[out1] |
| 2955 |
[out2] |
| 2956 |
main:2: error: Unsupported operand types for + ("int" and "None") |
| 2957 |
main:2: note: Right operand is of type "int | None" |
| 2958 |
|
| 2959 |
[case testAttrsIncrementalSubclassingCached] |
| 2960 |
from a import A |
| 2961 |
import attrs |
| 2962 |
@attrs.define |
| 2963 |
class B(A): |
| 2964 |
e: str = 'e' |
| 2965 |
a = B(5, [5], 'foo') |
| 2966 |
a.a = 6 |
| 2967 |
a._b = [2] |
| 2968 |
a.c = 'yo' |
| 2969 |
a._d = 22 |
| 2970 |
a.e = 'hi' |
| 2971 |
|
| 2972 |
[file a.py] |
| 2973 |
import attrs |
| 2974 |
from typing import List, ClassVar |
| 2975 |
@attrs.define |
| 2976 |
class A: |
| 2977 |
a: int |
| 2978 |
_b: List[int] |
| 2979 |
c: str = '18' |
| 2980 |
_d: int = attrs.field(validator=None, default=18) |
| 2981 |
E = 7 |
| 2982 |
F: ClassVar[int] = 22 |
| 2983 |
|
| 2984 |
[builtins fixtures/list.pyi] |
| 2985 |
[out1] |
| 2986 |
[out2] |
| 2987 |
|
| 2988 |
[case testAttrsIncrementalSubclassingCachedConverter] |
| 2989 |
from a import A |
| 2990 |
import attrs |
| 2991 |
@attrs.define |
| 2992 |
class B(A): |
| 2993 |
pass |
| 2994 |
reveal_type(B) |
| 2995 |
|
| 2996 |
[file a.py] |
| 2997 |
def converter(s:int) -> str: |
| 2998 |
return 'hello' |
| 2999 |
|
| 3000 |
import attrs |
| 3001 |
@attrs.define |
| 3002 |
class A: |
| 3003 |
x: str = attrs.field(converter=converter) |
| 3004 |
|
| 3005 |
[builtins fixtures/list.pyi] |
| 3006 |
[out1] |
| 3007 |
main:6: note: Revealed type is "def (x: builtins.int) -> __main__.B" |
| 3008 |
|
| 3009 |
[out2] |
| 3010 |
main:6: note: Revealed type is "def (x: builtins.int) -> __main__.B" |
| 3011 |
|
| 3012 |
[case testAttrsIncrementalSubclassingCachedType] |
| 3013 |
from a import A |
| 3014 |
import attrs |
| 3015 |
@attrs.define |
| 3016 |
class B(A): |
| 3017 |
pass |
| 3018 |
reveal_type(B) |
| 3019 |
|
| 3020 |
[file a.py] |
| 3021 |
import attrs |
| 3022 |
@attrs.define |
| 3023 |
class A: |
| 3024 |
x: int |
| 3025 |
|
| 3026 |
[builtins fixtures/list.pyi] |
| 3027 |
[out1] |
| 3028 |
main:6: note: Revealed type is "def (x: builtins.int) -> __main__.B" |
| 3029 |
[out2] |
| 3030 |
main:6: note: Revealed type is "def (x: builtins.int) -> __main__.B" |
| 3031 |
|
| 3032 |
[case testAttrsIncrementalArguments] |
| 3033 |
from a import Frozen, NoInit, NoCmp |
| 3034 |
f = Frozen(5) |
| 3035 |
f.x = 6 |
| 3036 |
|
| 3037 |
g = NoInit() |
| 3038 |
|
| 3039 |
Frozen(1) < Frozen(2) |
| 3040 |
Frozen(1) <= Frozen(2) |
| 3041 |
Frozen(1) > Frozen(2) |
| 3042 |
Frozen(1) >= Frozen(2) |
| 3043 |
|
| 3044 |
NoCmp(1) < NoCmp(2) |
| 3045 |
NoCmp(1) <= NoCmp(2) |
| 3046 |
NoCmp(1) > NoCmp(2) |
| 3047 |
NoCmp(1) >= NoCmp(2) |
| 3048 |
|
| 3049 |
[file a.py] |
| 3050 |
import attrs |
| 3051 |
@attrs.frozen |
| 3052 |
class Frozen: |
| 3053 |
x: int |
| 3054 |
@attrs.define(init=False) |
| 3055 |
class NoInit: |
| 3056 |
x: int |
| 3057 |
@attrs.define(eq=False) |
| 3058 |
class NoCmp: |
| 3059 |
x: int |
| 3060 |
|
| 3061 |
[builtins fixtures/plugin_attrs.pyi] |
| 3062 |
[rechecked] |
| 3063 |
[stale] |
| 3064 |
[out1] |
| 3065 |
main:3: error: Property "x" defined in "Frozen" is read-only |
| 3066 |
main:12: error: Unsupported left operand type for < ("NoCmp") |
| 3067 |
main:13: error: Unsupported left operand type for <= ("NoCmp") |
| 3068 |
main:14: error: Unsupported left operand type for > ("NoCmp") |
| 3069 |
main:15: error: Unsupported left operand type for >= ("NoCmp") |
| 3070 |
|
| 3071 |
[out2] |
| 3072 |
main:3: error: Property "x" defined in "Frozen" is read-only |
| 3073 |
main:12: error: Unsupported left operand type for < ("NoCmp") |
| 3074 |
main:13: error: Unsupported left operand type for <= ("NoCmp") |
| 3075 |
main:14: error: Unsupported left operand type for > ("NoCmp") |
| 3076 |
main:15: error: Unsupported left operand type for >= ("NoCmp") |
| 3077 |
|
| 3078 |
[case testAttrsIncrementalDunder] |
| 3079 |
from a import A |
| 3080 |
reveal_type(A) # N: Revealed type is "def (a: builtins.int) -> a.A" |
| 3081 |
reveal_type(A.__lt__) # N: Revealed type is "def [_AT] (self: _AT`3, other: _AT`3) -> builtins.bool" |
| 3082 |
reveal_type(A.__le__) # N: Revealed type is "def [_AT] (self: _AT`4, other: _AT`4) -> builtins.bool" |
| 3083 |
reveal_type(A.__gt__) # N: Revealed type is "def [_AT] (self: _AT`5, other: _AT`5) -> builtins.bool" |
| 3084 |
reveal_type(A.__ge__) # N: Revealed type is "def [_AT] (self: _AT`6, other: _AT`6) -> builtins.bool" |
| 3085 |
|
| 3086 |
A(1) < A(2) |
| 3087 |
A(1) <= A(2) |
| 3088 |
A(1) > A(2) |
| 3089 |
A(1) >= A(2) |
| 3090 |
A(1) == A(2) |
| 3091 |
A(1) != A(2) |
| 3092 |
|
| 3093 |
A(1) < 1 # E: Unsupported operand types for < ("A" and "int") |
| 3094 |
A(1) <= 1 # E: Unsupported operand types for <= ("A" and "int") |
| 3095 |
A(1) > 1 # E: Unsupported operand types for > ("A" and "int") |
| 3096 |
A(1) >= 1 # E: Unsupported operand types for >= ("A" and "int") |
| 3097 |
A(1) == 1 |
| 3098 |
A(1) != 1 |
| 3099 |
|
| 3100 |
1 < A(1) # E: Unsupported operand types for > ("A" and "int") |
| 3101 |
1 <= A(1) # E: Unsupported operand types for >= ("A" and "int") |
| 3102 |
1 > A(1) # E: Unsupported operand types for < ("A" and "int") |
| 3103 |
1 >= A(1) # E: Unsupported operand types for <= ("A" and "int") |
| 3104 |
1 == A(1) |
| 3105 |
1 != A(1) |
| 3106 |
|
| 3107 |
[file a.py] |
| 3108 |
from attr import attrib, attrs |
| 3109 |
@attrs(auto_attribs=True) |
| 3110 |
class A: |
| 3111 |
a: int |
| 3112 |
|
| 3113 |
[builtins fixtures/plugin_attrs.pyi] |
| 3114 |
[rechecked] |
| 3115 |
[stale] |
| 3116 |
[out2] |
| 3117 |
main:2: note: Revealed type is "def (a: builtins.int) -> a.A" |
| 3118 |
main:3: note: Revealed type is "def [_AT] (self: _AT`3, other: _AT`3) -> builtins.bool" |
| 3119 |
main:4: note: Revealed type is "def [_AT] (self: _AT`4, other: _AT`4) -> builtins.bool" |
| 3120 |
main:5: note: Revealed type is "def [_AT] (self: _AT`5, other: _AT`5) -> builtins.bool" |
| 3121 |
main:6: note: Revealed type is "def [_AT] (self: _AT`6, other: _AT`6) -> builtins.bool" |
| 3122 |
main:15: error: Unsupported operand types for < ("A" and "int") |
| 3123 |
main:16: error: Unsupported operand types for <= ("A" and "int") |
| 3124 |
main:17: error: Unsupported operand types for > ("A" and "int") |
| 3125 |
main:18: error: Unsupported operand types for >= ("A" and "int") |
| 3126 |
main:22: error: Unsupported operand types for > ("A" and "int") |
| 3127 |
main:23: error: Unsupported operand types for >= ("A" and "int") |
| 3128 |
main:24: error: Unsupported operand types for < ("A" and "int") |
| 3129 |
main:25: error: Unsupported operand types for <= ("A" and "int") |
| 3130 |
|
| 3131 |
[case testAttrsIncrementalSubclassModified] |
| 3132 |
from b import B |
| 3133 |
B(5, 'foo') |
| 3134 |
|
| 3135 |
[file a.py] |
| 3136 |
import attrs |
| 3137 |
@attrs.define |
| 3138 |
class A: |
| 3139 |
x: int |
| 3140 |
|
| 3141 |
[file b.py] |
| 3142 |
import attrs |
| 3143 |
from a import A |
| 3144 |
@attrs.define |
| 3145 |
class B(A): |
| 3146 |
y: str |
| 3147 |
|
| 3148 |
[file b.py.2] |
| 3149 |
import attrs |
| 3150 |
from a import A |
| 3151 |
@attrs.define |
| 3152 |
class B(A): |
| 3153 |
y: int |
| 3154 |
|
| 3155 |
[builtins fixtures/list.pyi] |
| 3156 |
[out1] |
| 3157 |
[out2] |
| 3158 |
main:2: error: Argument 2 to "B" has incompatible type "str"; expected "int" |
| 3159 |
[rechecked b] |
| 3160 |
|
| 3161 |
[case testAttrsIncrementalSubclassModifiedErrorFirst] |
| 3162 |
from b import B |
| 3163 |
B(5, 'foo') |
| 3164 |
[file a.py] |
| 3165 |
import attrs |
| 3166 |
@attrs.define |
| 3167 |
class A: |
| 3168 |
x: int |
| 3169 |
|
| 3170 |
[file b.py] |
| 3171 |
import attrs |
| 3172 |
from a import A |
| 3173 |
@attrs.define |
| 3174 |
class B(A): |
| 3175 |
y: int |
| 3176 |
|
| 3177 |
[file b.py.2] |
| 3178 |
import attrs |
| 3179 |
from a import A |
| 3180 |
@attrs.define |
| 3181 |
class B(A): |
| 3182 |
y: str |
| 3183 |
|
| 3184 |
[builtins fixtures/list.pyi] |
| 3185 |
[out1] |
| 3186 |
main:2: error: Argument 2 to "B" has incompatible type "str"; expected "int" |
| 3187 |
|
| 3188 |
[out2] |
| 3189 |
[rechecked b] |
| 3190 |
|
| 3191 |
[case testAttrsIncrementalThreeFiles] |
| 3192 |
from c import C |
| 3193 |
C(5, 'foo', True) |
| 3194 |
|
| 3195 |
[file a.py] |
| 3196 |
import attrs |
| 3197 |
@attrs.define(slots=False) |
| 3198 |
class A: |
| 3199 |
a: int |
| 3200 |
|
| 3201 |
[file b.py] |
| 3202 |
import attrs |
| 3203 |
@attrs.define(slots=False) |
| 3204 |
class B: |
| 3205 |
b: str |
| 3206 |
|
| 3207 |
[file c.py] |
| 3208 |
from a import A |
| 3209 |
from b import B |
| 3210 |
import attrs |
| 3211 |
@attrs.define(slots=False) |
| 3212 |
class C(A, B): |
| 3213 |
c: bool |
| 3214 |
|
| 3215 |
[builtins fixtures/list.pyi] |
| 3216 |
[out1] |
| 3217 |
[out2] |
| 3218 |
|
| 3219 |
[case testAttrsIncrementalConverterInSubmodule] |
| 3220 |
from a.a import A |
| 3221 |
reveal_type(A) |
| 3222 |
[file a/__init__.py] |
| 3223 |
[file a/a.py] |
| 3224 |
from typing import Optional |
| 3225 |
def converter(s:Optional[int]) -> int: |
| 3226 |
... |
| 3227 |
|
| 3228 |
import attrs |
| 3229 |
@attrs.define |
| 3230 |
class A: |
| 3231 |
x: int = attrs.field(converter=converter) |
| 3232 |
|
| 3233 |
[builtins fixtures/list.pyi] |
| 3234 |
[out1] |
| 3235 |
main:2: note: Revealed type is "def (x: builtins.int | None) -> a.a.A" |
| 3236 |
[out2] |
| 3237 |
main:2: note: Revealed type is "def (x: builtins.int | None) -> a.a.A" |
| 3238 |
|
| 3239 |
[case testAttrsIncrementalConverterManyStyles] |
| 3240 |
import a |
| 3241 |
[file a.py] |
| 3242 |
from base import Base |
| 3243 |
Base(1, 'str', True) |
| 3244 |
Base(None, None, None) |
| 3245 |
|
| 3246 |
from subclass import A, B |
| 3247 |
A(1, 'str', True) |
| 3248 |
A(None, None, None) |
| 3249 |
B(1, 'str', True, 1, 'str', True) |
| 3250 |
B(None, None, None, None, None, None) |
| 3251 |
|
| 3252 |
from submodule.base import SubBase |
| 3253 |
SubBase(1, 'str', True) |
| 3254 |
SubBase(None, None, None) |
| 3255 |
|
| 3256 |
from submodule.subclass import AA, BB |
| 3257 |
AA(1, 'str', True) |
| 3258 |
AA(None, None, None) |
| 3259 |
BB(1, 'str', True, 1, 'str', True) |
| 3260 |
BB(None, None, None, None, None, None) |
| 3261 |
|
| 3262 |
from submodule.subsubclass import SubAA, SubBB |
| 3263 |
SubAA(1, 'str', True) |
| 3264 |
SubAA(None, None, None) |
| 3265 |
SubBB(1, 'str', True, 1, 'str', True) |
| 3266 |
SubBB(None, None, None, None, None, None) |
| 3267 |
|
| 3268 |
[file a.py.2] |
| 3269 |
# Now with errors. |
| 3270 |
from base import Base |
| 3271 |
Base(1, 1, True) |
| 3272 |
|
| 3273 |
from subclass import A, B |
| 3274 |
A(1, 1, True) |
| 3275 |
B(1, 'str', True, 1, 1, True) |
| 3276 |
|
| 3277 |
from submodule.base import SubBase |
| 3278 |
SubBase(1, 1, True) |
| 3279 |
|
| 3280 |
from submodule.subclass import AA, BB |
| 3281 |
AA(1, 1, True) |
| 3282 |
BB(1, 'str', True, 1, 1, True) |
| 3283 |
|
| 3284 |
from submodule.subsubclass import SubAA, SubBB |
| 3285 |
SubAA(1, 1, True) |
| 3286 |
SubBB(1, 'str', True, 1, 1, True) |
| 3287 |
|
| 3288 |
[file foo.py] |
| 3289 |
from typing import Optional |
| 3290 |
def maybe_int(x: Optional[int]) -> int: |
| 3291 |
... |
| 3292 |
[file bar.py] |
| 3293 |
from typing import Optional |
| 3294 |
def maybe_bool(x: Optional[bool]) -> bool: |
| 3295 |
... |
| 3296 |
[file base.py] |
| 3297 |
from typing import Optional |
| 3298 |
import attrs |
| 3299 |
import bar |
| 3300 |
from foo import maybe_int |
| 3301 |
def maybe_str(x: Optional[str]) -> str: |
| 3302 |
... |
| 3303 |
@attrs.define |
| 3304 |
class Base: |
| 3305 |
x: int = attrs.field(converter=maybe_int) |
| 3306 |
y: str = attrs.field(converter=maybe_str) |
| 3307 |
z: bool = attrs.field(converter=bar.maybe_bool) |
| 3308 |
[file subclass.py] |
| 3309 |
from typing import Optional |
| 3310 |
import attrs |
| 3311 |
from base import Base |
| 3312 |
@attrs.define |
| 3313 |
class A(Base): pass |
| 3314 |
|
| 3315 |
import bar |
| 3316 |
from foo import maybe_int |
| 3317 |
def maybe_str(x: Optional[str]) -> str: |
| 3318 |
... |
| 3319 |
@attrs.define |
| 3320 |
class B(Base): |
| 3321 |
xx: int = attrs.field(converter=maybe_int) |
| 3322 |
yy: str = attrs.field(converter=maybe_str) |
| 3323 |
zz: bool = attrs.field(converter=bar.maybe_bool) |
| 3324 |
|
| 3325 |
[file submodule/__init__.py] |
| 3326 |
[file submodule/base.py] |
| 3327 |
from typing import Optional |
| 3328 |
import attrs |
| 3329 |
import bar |
| 3330 |
from foo import maybe_int |
| 3331 |
def maybe_str(x: Optional[str]) -> str: |
| 3332 |
... |
| 3333 |
@attrs.define |
| 3334 |
class SubBase: |
| 3335 |
x: int = attrs.field(converter=maybe_int) |
| 3336 |
y: str = attrs.field(converter=maybe_str) |
| 3337 |
z: bool = attrs.field(converter=bar.maybe_bool) |
| 3338 |
|
| 3339 |
[file submodule/subclass.py] |
| 3340 |
from typing import Optional |
| 3341 |
import attrs |
| 3342 |
from base import Base |
| 3343 |
@attrs.define |
| 3344 |
class AA(Base): pass |
| 3345 |
|
| 3346 |
import bar |
| 3347 |
from foo import maybe_int |
| 3348 |
def maybe_str(x: Optional[str]) -> str: |
| 3349 |
... |
| 3350 |
@attrs.define |
| 3351 |
class BB(Base): |
| 3352 |
xx: int = attrs.field(converter=maybe_int) |
| 3353 |
yy: str = attrs.field(converter=maybe_str) |
| 3354 |
zz: bool = attrs.field(converter=bar.maybe_bool) |
| 3355 |
|
| 3356 |
[file submodule/subsubclass.py] |
| 3357 |
from typing import Optional |
| 3358 |
import attrs |
| 3359 |
from .base import SubBase |
| 3360 |
@attrs.define |
| 3361 |
class SubAA(SubBase): pass |
| 3362 |
|
| 3363 |
import bar |
| 3364 |
from foo import maybe_int |
| 3365 |
def maybe_str(x: Optional[str]) -> str: |
| 3366 |
... |
| 3367 |
@attrs.define |
| 3368 |
class SubBB(SubBase): |
| 3369 |
xx: int = attrs.field(converter=maybe_int) |
| 3370 |
yy: str = attrs.field(converter=maybe_str) |
| 3371 |
zz: bool = attrs.field(converter=bar.maybe_bool) |
| 3372 |
[builtins fixtures/list.pyi] |
| 3373 |
[out1] |
| 3374 |
[out2] |
| 3375 |
tmp/a.py:3: error: Argument 2 to "Base" has incompatible type "int"; expected "str | None" |
| 3376 |
tmp/a.py:6: error: Argument 2 to "A" has incompatible type "int"; expected "str | None" |
| 3377 |
tmp/a.py:7: error: Argument 5 to "B" has incompatible type "int"; expected "str | None" |
| 3378 |
tmp/a.py:10: error: Argument 2 to "SubBase" has incompatible type "int"; expected "str | None" |
| 3379 |
tmp/a.py:13: error: Argument 2 to "AA" has incompatible type "int"; expected "str | None" |
| 3380 |
tmp/a.py:14: error: Argument 5 to "BB" has incompatible type "int"; expected "str | None" |
| 3381 |
tmp/a.py:17: error: Argument 2 to "SubAA" has incompatible type "int"; expected "str | None" |
| 3382 |
tmp/a.py:18: error: Argument 5 to "SubBB" has incompatible type "int"; expected "str | None" |
| 3383 |
|
| 3384 |
[case testAttrsIncrementalConverterInFunction] |
| 3385 |
import attrs |
| 3386 |
def foo() -> None: |
| 3387 |
def foo(x: str) -> int: |
| 3388 |
... |
| 3389 |
@attrs.define |
| 3390 |
class A: |
| 3391 |
x: int = attrs.field(converter=foo) |
| 3392 |
reveal_type(A) |
| 3393 |
[builtins fixtures/list.pyi] |
| 3394 |
[out1] |
| 3395 |
main:8: note: Revealed type is "def (x: builtins.str) -> __main__.A@6" |
| 3396 |
[out2] |
| 3397 |
main:8: note: Revealed type is "def (x: builtins.str) -> __main__.A@6" |
| 3398 |
|
| 3399 |
-- FIXME: new analyzer busted |
| 3400 |
[case testAttrsIncrementalConverterInSubmoduleForwardRef-skip] |
| 3401 |
|
| 3402 |
from a.a import A |
| 3403 |
reveal_type(A) |
| 3404 |
[file a/__init__.py] |
| 3405 |
[file a/a.py] |
| 3406 |
from typing import List |
| 3407 |
def converter(s:F) -> int: |
| 3408 |
... |
| 3409 |
|
| 3410 |
import attrs |
| 3411 |
@attrs.define |
| 3412 |
class A: |
| 3413 |
x: int = attrs.field(converter=converter) |
| 3414 |
|
| 3415 |
F = List[int] |
| 3416 |
|
| 3417 |
[builtins fixtures/list.pyi] |
| 3418 |
[out1] |
| 3419 |
main:3: note: Revealed type is "def (x: builtins.list[builtins.int]) -> a.a.A" |
| 3420 |
[out2] |
| 3421 |
main:3: note: Revealed type is "def (x: builtins.list[builtins.int]) -> a.a.A" |
| 3422 |
|
| 3423 |
-- FIXME: new analyzer busted |
| 3424 |
[case testAttrsIncrementalConverterType-skip] |
| 3425 |
|
| 3426 |
from a import C |
| 3427 |
import attrs |
| 3428 |
o = C("1", "2", "3", "4") |
| 3429 |
o = C(1, 2, "3", 4) |
| 3430 |
reveal_type(C) |
| 3431 |
@attrs.define |
| 3432 |
class D(C): |
| 3433 |
x: str |
| 3434 |
reveal_type(D) |
| 3435 |
[file a.py] |
| 3436 |
from typing import overload |
| 3437 |
import attrs |
| 3438 |
@attrs.define |
| 3439 |
class A: |
| 3440 |
x: str |
| 3441 |
@overload |
| 3442 |
def parse(x: int) -> int: |
| 3443 |
... |
| 3444 |
@overload |
| 3445 |
def parse(x: str, y: str = '') -> int: |
| 3446 |
... |
| 3447 |
def parse(x, y): ... |
| 3448 |
@attrs.define |
| 3449 |
class C: |
| 3450 |
a: complex = attrs.field(converter=complex) |
| 3451 |
b: int = attrs.field(converter=int) |
| 3452 |
c: A = attrs.field(converter=A) |
| 3453 |
d: int = attrs.field(converter=parse) |
| 3454 |
[builtins fixtures/plugin_attrs.pyi] |
| 3455 |
[out1] |
| 3456 |
main:6: note: Revealed type is "def (a: Union[builtins.float, builtins.str], b: Union[builtins.str, builtins.bytes, builtins.int], c: builtins.str, d: Union[builtins.int, builtins.str]) -> a.C" |
| 3457 |
main:10: note: Revealed type is "def (a: Union[builtins.float, builtins.str], b: Union[builtins.str, builtins.bytes, builtins.int], c: builtins.str, d: Union[builtins.int, builtins.str], x: builtins.str) -> __main__.D" |
| 3458 |
[out2] |
| 3459 |
main:6: note: Revealed type is "def (a: Union[builtins.float, builtins.str], b: Union[builtins.str, builtins.bytes, builtins.int], c: builtins.str, d: Union[builtins.int, builtins.str]) -> a.C" |
| 3460 |
main:10: note: Revealed type is "def (a: Union[builtins.float, builtins.str], b: Union[builtins.str, builtins.bytes, builtins.int], c: builtins.str, d: Union[builtins.int, builtins.str], x: builtins.str) -> __main__.D" |
| 3461 |
|
| 3462 |
[case testAttrsIncrementalThreeRuns] |
| 3463 |
from a import A |
| 3464 |
A(5) |
| 3465 |
|
| 3466 |
[file a.py] |
| 3467 |
import attrs |
| 3468 |
@attrs.define |
| 3469 |
class A: |
| 3470 |
a: int |
| 3471 |
|
| 3472 |
[file a.py.2] |
| 3473 |
import attrs |
| 3474 |
@attrs.define |
| 3475 |
class A: |
| 3476 |
a: str |
| 3477 |
|
| 3478 |
[file a.py.3] |
| 3479 |
import attrs |
| 3480 |
@attrs.define |
| 3481 |
class A: |
| 3482 |
a: int = 6 |
| 3483 |
|
| 3484 |
[builtins fixtures/list.pyi] |
| 3485 |
[out1] |
| 3486 |
[out2] |
| 3487 |
main:2: error: Argument 1 to "A" has incompatible type "int"; expected "str" |
| 3488 |
[out3] |
| 3489 |
|
| 3490 |
[case testDeletedDepLineNumber] |
| 3491 |
# The import is not on line 1 and that data should be preserved |
| 3492 |
import a |
| 3493 |
[file a.py] |
| 3494 |
[delete a.py.2] |
| 3495 |
[out1] |
| 3496 |
|
| 3497 |
[out2] |
| 3498 |
main:2: error: Cannot find implementation or library stub for module named "a" |
| 3499 |
main:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports |
| 3500 |
|
| 3501 |
[case testIncrementalInheritanceAddAnnotation] |
| 3502 |
import a |
| 3503 |
[file a.py] |
| 3504 |
import b |
| 3505 |
def foo() -> None: |
| 3506 |
1 + b.Bar().get() |
| 3507 |
[file b.py] |
| 3508 |
from c import Baz |
| 3509 |
class Bar(Baz): pass |
| 3510 |
|
| 3511 |
[file c.py] |
| 3512 |
class Baz: |
| 3513 |
def get(self): |
| 3514 |
return 1 |
| 3515 |
[file c.py.2] |
| 3516 |
from typing import Optional |
| 3517 |
class Baz: |
| 3518 |
def get(self) -> Optional[int]: |
| 3519 |
return 1 |
| 3520 |
[out] |
| 3521 |
[out2] |
| 3522 |
tmp/a.py:3: error: Unsupported operand types for + ("int" and "None") |
| 3523 |
tmp/a.py:3: note: Right operand is of type "int | None" |
| 3524 |
|
| 3525 |
[case testIncrementalMetaclassUpdate] |
| 3526 |
import a |
| 3527 |
[file a.py] |
| 3528 |
from b import B |
| 3529 |
B.x |
| 3530 |
|
| 3531 |
[file b.py] |
| 3532 |
import c |
| 3533 |
class B(metaclass=c.M): pass |
| 3534 |
|
| 3535 |
[file c.py] |
| 3536 |
class M(type): |
| 3537 |
x: int |
| 3538 |
|
| 3539 |
[file c.py.2] |
| 3540 |
class M(type): |
| 3541 |
y: int |
| 3542 |
[out] |
| 3543 |
[out2] |
| 3544 |
tmp/a.py:2: error: "type[B]" has no attribute "x" |
| 3545 |
|
| 3546 |
[case testIncrementalLotsOfInheritance] |
| 3547 |
import a |
| 3548 |
[file a.py] |
| 3549 |
from b import B |
| 3550 |
from d import D |
| 3551 |
def take(d: D) -> None: pass |
| 3552 |
def foo() -> None: |
| 3553 |
take(B()) |
| 3554 |
[file b.py] |
| 3555 |
from c import C |
| 3556 |
class B(C): pass |
| 3557 |
|
| 3558 |
[file c.py] |
| 3559 |
from d import D |
| 3560 |
class C(D): pass |
| 3561 |
|
| 3562 |
[file c.py.2] |
| 3563 |
from d import D |
| 3564 |
class C: pass |
| 3565 |
|
| 3566 |
[file d.py] |
| 3567 |
class D: pass |
| 3568 |
[out] |
| 3569 |
[out2] |
| 3570 |
tmp/a.py:5: error: Argument 1 to "take" has incompatible type "B"; expected "D" |
| 3571 |
|
| 3572 |
[case testIncrementalInheritanceProperty] |
| 3573 |
import a |
| 3574 |
[file a.py] |
| 3575 |
import b |
| 3576 |
def foo() -> None: |
| 3577 |
1 + b.Bar().x |
| 3578 |
[file b.py] |
| 3579 |
from c import Baz |
| 3580 |
class Bar(Baz): pass |
| 3581 |
|
| 3582 |
[file c.py] |
| 3583 |
class Baz: |
| 3584 |
def __init__(self) -> None: |
| 3585 |
self.x = 12 # type: int |
| 3586 |
[file c.py.2] |
| 3587 |
class Baz: |
| 3588 |
def __init__(self) -> None: |
| 3589 |
self.x = 'lol' # type: str |
| 3590 |
[out] |
| 3591 |
[out2] |
| 3592 |
tmp/a.py:3: error: Unsupported operand types for + ("int" and "str") |
| 3593 |
|
| 3594 |
[case testIncrementalWithIgnoresTwice] |
| 3595 |
import a |
| 3596 |
[file a.py] |
| 3597 |
import b |
| 3598 |
import foo # type: ignore |
| 3599 |
[file b.py] |
| 3600 |
x = 1 |
| 3601 |
[file b.py.2] |
| 3602 |
x = 'hi' |
| 3603 |
[file b.py.3] |
| 3604 |
x = 1 |
| 3605 |
[builtins fixtures/module.pyi] |
| 3606 |
[out] |
| 3607 |
[out2] |
| 3608 |
[out3] |
| 3609 |
|
| 3610 |
[case testIgnoredImport2] |
| 3611 |
import x |
| 3612 |
[file y.py] |
| 3613 |
import xyz # type: ignore |
| 3614 |
B = 0 |
| 3615 |
from x import A |
| 3616 |
[file x.py] |
| 3617 |
A = 0 |
| 3618 |
from y import B |
| 3619 |
[file x.py.2] |
| 3620 |
A = 1 |
| 3621 |
from y import B |
| 3622 |
[file x.py.3] |
| 3623 |
A = 2 |
| 3624 |
from y import B |
| 3625 |
[out] |
| 3626 |
[out2] |
| 3627 |
[out3] |
| 3628 |
|
| 3629 |
[case testDeletionOfSubmoduleTriggersImportFrom2] |
| 3630 |
from p.q import f |
| 3631 |
f() |
| 3632 |
[file p/__init__.py] |
| 3633 |
[file p/q.py] |
| 3634 |
def f() -> None: pass |
| 3635 |
[delete p/q.py.2] |
| 3636 |
[file p/q.py.3] |
| 3637 |
def f(x: int) -> None: pass |
| 3638 |
[out] |
| 3639 |
[out2] |
| 3640 |
main:1: error: Cannot find implementation or library stub for module named "p.q" |
| 3641 |
main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports |
| 3642 |
[out3] |
| 3643 |
main:2: error: Missing positional argument "x" in call to "f" |
| 3644 |
|
| 3645 |
[case testDeleteIndirectDependency] |
| 3646 |
import b |
| 3647 |
b.x.foo() |
| 3648 |
[file b.py] |
| 3649 |
import c |
| 3650 |
x = c.Foo() |
| 3651 |
[file c.py] |
| 3652 |
class Foo: |
| 3653 |
def foo(self) -> None: pass |
| 3654 |
[delete c.py.2] |
| 3655 |
[file b.py.2] |
| 3656 |
class Foo: |
| 3657 |
def foo(self) -> None: pass |
| 3658 |
x = Foo() |
| 3659 |
[out] |
| 3660 |
[out2] |
| 3661 |
|
| 3662 |
[case testImportReExportInCycle] |
| 3663 |
from m import One |
| 3664 |
[file m/__init__.py] |
| 3665 |
from .one import One |
| 3666 |
from .two import Two |
| 3667 |
[file m/one.py] |
| 3668 |
class One: |
| 3669 |
pass |
| 3670 |
[file m/two.py] |
| 3671 |
import m |
| 3672 |
class Two: |
| 3673 |
pass |
| 3674 |
[file m/one.py.2] |
| 3675 |
class One: |
| 3676 |
name: str |
| 3677 |
[file m/two.py.2] |
| 3678 |
import m |
| 3679 |
reveal_type(m.One.name) |
| 3680 |
class Two: |
| 3681 |
pass |
| 3682 |
[out2] |
| 3683 |
tmp/m/two.py:2: note: Revealed type is "builtins.str" |
| 3684 |
|
| 3685 |
[case testImportUnusedIgnore1] |
| 3686 |
# flags: --warn-unused-ignores |
| 3687 |
import a |
| 3688 |
[file a.py] |
| 3689 |
import b |
| 3690 |
import foo # type: ignore |
| 3691 |
[file b.py] |
| 3692 |
x = 1 |
| 3693 |
[file b.py.2] |
| 3694 |
x = '2' |
| 3695 |
|
| 3696 |
[case testImportUnusedIgnore2] |
| 3697 |
# flags: --warn-unused-ignores |
| 3698 |
import a |
| 3699 |
[file a.py] |
| 3700 |
import b |
| 3701 |
import c # type: ignore |
| 3702 |
[file b.py] |
| 3703 |
x = 1 |
| 3704 |
[file b.py.2] |
| 3705 |
x = 'hi' |
| 3706 |
[file c.py.3] |
| 3707 |
pass |
| 3708 |
[out] |
| 3709 |
[out2] |
| 3710 |
[out3] |
| 3711 |
tmp/a.py:2: error: Unused "type: ignore" comment |
| 3712 |
|
| 3713 |
-- Test that a non cache_fine_grained run can use a fine-grained cache |
| 3714 |
[case testRegularUsesFgCache] |
| 3715 |
# flags: --config-file tmp/mypy.ini |
| 3716 |
import a |
| 3717 |
[file a.py] |
| 3718 |
x = 0 |
| 3719 |
[file mypy.ini] |
| 3720 |
\[mypy] |
| 3721 |
cache_fine_grained = True |
| 3722 |
local_partial_types = True |
| 3723 |
[file mypy.ini.2] |
| 3724 |
\[mypy] |
| 3725 |
cache_fine_grained = False |
| 3726 |
local_partial_types = True |
| 3727 |
-- Nothing should get rechecked |
| 3728 |
[rechecked] |
| 3729 |
[stale] |
| 3730 |
|
| 3731 |
[case testFgCacheNeedsFgCache] |
| 3732 |
# flags: --config-file tmp/mypy.ini |
| 3733 |
import a |
| 3734 |
[file a.py] |
| 3735 |
x = 0 |
| 3736 |
[file mypy.ini] |
| 3737 |
\[mypy] |
| 3738 |
cache_fine_grained = False |
| 3739 |
[file mypy.ini.2] |
| 3740 |
\[mypy] |
| 3741 |
cache_fine_grained = True |
| 3742 |
[rechecked _typeshed, a, builtins, types, typing] |
| 3743 |
[stale _typeshed, a, builtins, types, typing] |
| 3744 |
[builtins fixtures/tuple.pyi] |
| 3745 |
|
| 3746 |
[case testIncrementalPackageNameOverload] |
| 3747 |
# cmd: mypy -m main a |
| 3748 |
# flags: --follow-imports=skip |
| 3749 |
[file main.py] |
| 3750 |
from a import x |
| 3751 |
x.foo() |
| 3752 |
[file a/__init__.py] |
| 3753 |
pass |
| 3754 |
[file a/__init__.py.2] |
| 3755 |
x = 10 |
| 3756 |
[file a/x.py] |
| 3757 |
def foo() -> None: |
| 3758 |
pass |
| 3759 |
[out] |
| 3760 |
[out2] |
| 3761 |
tmp/main.py:2: error: "int" has no attribute "foo" |
| 3762 |
|
| 3763 |
[case testIncrementalFineGrainedCacheError1] |
| 3764 |
# flags: --cache-fine-grained --no-sqlite-cache |
| 3765 |
import a |
| 3766 |
[file a.py] |
| 3767 |
[file b.py] |
| 3768 |
x = 0 |
| 3769 |
[file a.py.2] |
| 3770 |
from b import x |
| 3771 |
1 + 'lol' |
| 3772 |
[out] |
| 3773 |
[out2] |
| 3774 |
tmp/a.py:2: error: Unsupported operand types for + ("int" and "str") |
| 3775 |
|
| 3776 |
[case testIncrementalBustedFineGrainedCache1] |
| 3777 |
# flags: --cache-fine-grained --no-sqlite-cache |
| 3778 |
import a |
| 3779 |
import b |
| 3780 |
[file a.py] |
| 3781 |
[file b.py] |
| 3782 |
-- This is a heinous hack, but we simulate having a invalid cache by clobbering |
| 3783 |
-- the proto deps file with something with mtime mismatches. |
| 3784 |
[file ../.mypy_cache/3.10/@deps.meta.json.2] |
| 3785 |
{"snapshot": {"__main__": "a7c958b001a45bd6a2a320f4e53c4c16", "a": "d41d8cd98f00b204e9800998ecf8427e", "b": "d41d8cd98f00b204e9800998ecf8427e", "builtins": "c532c89da517a4b779bcf7a964478d67"}, "deps_meta": {"@root": {"path": "@root.deps.json", "mtime": 0}, "__main__": {"path": "__main__.deps.json", "mtime": 0}, "a": {"path": "a.deps.json", "mtime": 0}, "b": {"path": "b.deps.json", "mtime": 0}, "builtins": {"path": "builtins.deps.json", "mtime": 0}}} |
| 3786 |
[file ../.mypy_cache/.gitignore] |
| 3787 |
# Another hack to not trigger a .gitignore creation failure "false positive" |
| 3788 |
[file ../.mypy_cache/CACHEDIR.TAG] |
| 3789 |
Signature: 8a477f597d28d172789f06886806bc55 |
| 3790 |
# Another another hack to not trigger a CACHEDIR.TAG creation failure "false positive" |
| 3791 |
[file b.py.2] |
| 3792 |
# uh |
| 3793 |
-- Every file should get reloaded, since the cache was invalidated |
| 3794 |
[stale _typeshed, a, b, builtins, types, typing] |
| 3795 |
[rechecked _typeshed, a, b, builtins, types, typing] |
| 3796 |
[builtins fixtures/tuple.pyi] |
| 3797 |
|
| 3798 |
[case testIncrementalBustedFineGrainedCache2] |
| 3799 |
# flags2: --cache-fine-grained |
| 3800 |
import a |
| 3801 |
import b |
| 3802 |
[file a.py] |
| 3803 |
[file b.py] |
| 3804 |
[file b.py.2] |
| 3805 |
# uh |
| 3806 |
-- Every file should get reloaded, since the settings changed |
| 3807 |
[stale _typeshed, a, b, builtins, types, typing] |
| 3808 |
[rechecked _typeshed, a, b, builtins, types, typing] |
| 3809 |
[builtins fixtures/tuple.pyi] |
| 3810 |
|
| 3811 |
[case testIncrementalBustedFineGrainedCache3] |
| 3812 |
# flags: --cache-fine-grained --no-sqlite-cache |
| 3813 |
import a |
| 3814 |
import b |
| 3815 |
[file a.py] |
| 3816 |
[file b.py] |
| 3817 |
-- This is a heinous hack, but we simulate having a invalid cache by deleting |
| 3818 |
-- the proto deps file. |
| 3819 |
[delete ../.mypy_cache/3.10/@deps.meta.json.2] |
| 3820 |
[file b.py.2] |
| 3821 |
# uh |
| 3822 |
-- Every file should get reloaded, since the cache was invalidated |
| 3823 |
[stale _typeshed, a, b, builtins, types, typing] |
| 3824 |
[rechecked _typeshed, a, b, builtins, types, typing] |
| 3825 |
[builtins fixtures/tuple.pyi] |
| 3826 |
|
| 3827 |
[case testIncrementalWorkingFineGrainedCache] |
| 3828 |
# flags: --cache-fine-grained |
| 3829 |
# flags2: --cache-fine-grained |
| 3830 |
import a |
| 3831 |
import b |
| 3832 |
[file a.py] |
| 3833 |
[file b.py] |
| 3834 |
[file b.py.2] |
| 3835 |
# uh |
| 3836 |
-- b gets rechecked because it changed, but nothing is stale |
| 3837 |
-- since the interface did not change |
| 3838 |
[stale] |
| 3839 |
[rechecked b] |
| 3840 |
|
| 3841 |
[case testIncrementalDataclassesSubclassingCached] |
| 3842 |
from a import A |
| 3843 |
from dataclasses import dataclass |
| 3844 |
|
| 3845 |
@dataclass |
| 3846 |
class B(A): |
| 3847 |
e: str = 'e' |
| 3848 |
|
| 3849 |
a = B(5, [5], 'foo') |
| 3850 |
a.a = 6 |
| 3851 |
a._b = [2] |
| 3852 |
a.c = 'yo' |
| 3853 |
a._d = 22 |
| 3854 |
a.e = 'hi' |
| 3855 |
|
| 3856 |
[file a.py] |
| 3857 |
from dataclasses import dataclass, field |
| 3858 |
from typing import ClassVar, List |
| 3859 |
|
| 3860 |
@dataclass |
| 3861 |
class A: |
| 3862 |
a: int |
| 3863 |
_b: List[int] |
| 3864 |
c: str = '18' |
| 3865 |
_d: int = field(default=False) |
| 3866 |
E = 7 |
| 3867 |
F: ClassVar[int] = 22 |
| 3868 |
|
| 3869 |
[builtins fixtures/dataclasses.pyi] |
| 3870 |
[out1] |
| 3871 |
[out2] |
| 3872 |
|
| 3873 |
[case testIncrementalDataclassesSubclassingCachedType] |
| 3874 |
import b |
| 3875 |
|
| 3876 |
[file b.py] |
| 3877 |
from a import A |
| 3878 |
from dataclasses import dataclass |
| 3879 |
|
| 3880 |
@dataclass |
| 3881 |
class B(A): |
| 3882 |
pass |
| 3883 |
|
| 3884 |
[file b.py.2] |
| 3885 |
from a import A |
| 3886 |
from dataclasses import dataclass |
| 3887 |
|
| 3888 |
@dataclass |
| 3889 |
class B(A): |
| 3890 |
pass |
| 3891 |
|
| 3892 |
reveal_type(B) |
| 3893 |
|
| 3894 |
[file a.py] |
| 3895 |
from dataclasses import dataclass |
| 3896 |
|
| 3897 |
@dataclass |
| 3898 |
class A: |
| 3899 |
x: int |
| 3900 |
|
| 3901 |
[builtins fixtures/dataclasses.pyi] |
| 3902 |
[out1] |
| 3903 |
[out2] |
| 3904 |
tmp/b.py:8: note: Revealed type is "def (x: builtins.int) -> b.B" |
| 3905 |
|
| 3906 |
[case testIncrementalDataclassesArguments] |
| 3907 |
import b |
| 3908 |
|
| 3909 |
[file b.py] |
| 3910 |
from a import Frozen, NoInit, NoCmp |
| 3911 |
|
| 3912 |
[file b.py.2] |
| 3913 |
from a import Frozen, NoInit, NoCmp |
| 3914 |
|
| 3915 |
f = Frozen(5) |
| 3916 |
f.x = 6 |
| 3917 |
|
| 3918 |
g = NoInit() |
| 3919 |
|
| 3920 |
Frozen(1) < Frozen(2) |
| 3921 |
Frozen(1) <= Frozen(2) |
| 3922 |
Frozen(1) > Frozen(2) |
| 3923 |
Frozen(1) >= Frozen(2) |
| 3924 |
|
| 3925 |
NoCmp(1) < NoCmp(2) |
| 3926 |
NoCmp(1) <= NoCmp(2) |
| 3927 |
NoCmp(1) > NoCmp(2) |
| 3928 |
NoCmp(1) >= NoCmp(2) |
| 3929 |
|
| 3930 |
[file a.py] |
| 3931 |
from dataclasses import dataclass |
| 3932 |
|
| 3933 |
@dataclass(frozen=True, order=True) |
| 3934 |
class Frozen: |
| 3935 |
x: int |
| 3936 |
|
| 3937 |
@dataclass(init=False) |
| 3938 |
class NoInit: |
| 3939 |
x: int |
| 3940 |
|
| 3941 |
@dataclass(order=False) |
| 3942 |
class NoCmp: |
| 3943 |
x: int |
| 3944 |
|
| 3945 |
[builtins fixtures/dataclasses.pyi] |
| 3946 |
[out1] |
| 3947 |
[out2] |
| 3948 |
tmp/b.py:4: error: Property "x" defined in "Frozen" is read-only |
| 3949 |
tmp/b.py:13: error: Unsupported left operand type for < ("NoCmp") |
| 3950 |
tmp/b.py:14: error: Unsupported left operand type for <= ("NoCmp") |
| 3951 |
tmp/b.py:15: error: Unsupported left operand type for > ("NoCmp") |
| 3952 |
tmp/b.py:16: error: Unsupported left operand type for >= ("NoCmp") |
| 3953 |
|
| 3954 |
[case testIncrementalDataclassesDunder] |
| 3955 |
import b |
| 3956 |
|
| 3957 |
[file b.py] |
| 3958 |
from a import A |
| 3959 |
|
| 3960 |
[file b.py.2] |
| 3961 |
from a import A |
| 3962 |
|
| 3963 |
reveal_type(A) |
| 3964 |
reveal_type(A.__eq__) |
| 3965 |
reveal_type(A.__ne__) |
| 3966 |
reveal_type(A.__lt__) |
| 3967 |
reveal_type(A.__le__) |
| 3968 |
reveal_type(A.__gt__) |
| 3969 |
reveal_type(A.__ge__) |
| 3970 |
|
| 3971 |
A(1) < A(2) |
| 3972 |
A(1) <= A(2) |
| 3973 |
A(1) > A(2) |
| 3974 |
A(1) >= A(2) |
| 3975 |
A(1) == A(2) |
| 3976 |
A(1) != A(2) |
| 3977 |
|
| 3978 |
A(1) < 1 |
| 3979 |
A(1) <= 1 |
| 3980 |
A(1) > 1 |
| 3981 |
A(1) >= 1 |
| 3982 |
A(1) == 1 |
| 3983 |
A(1) != 1 |
| 3984 |
|
| 3985 |
1 < A(1) |
| 3986 |
1 <= A(1) |
| 3987 |
1 > A(1) |
| 3988 |
1 >= A(1) |
| 3989 |
1 == A(1) |
| 3990 |
1 != A(1) |
| 3991 |
|
| 3992 |
[file a.py] |
| 3993 |
from dataclasses import dataclass |
| 3994 |
|
| 3995 |
@dataclass(order=True) |
| 3996 |
class A: |
| 3997 |
a: int |
| 3998 |
|
| 3999 |
[builtins fixtures/dataclasses.pyi] |
| 4000 |
[out1] |
| 4001 |
[out2] |
| 4002 |
tmp/b.py:3: note: Revealed type is "def (a: builtins.int) -> a.A" |
| 4003 |
tmp/b.py:4: note: Revealed type is "def (builtins.object, builtins.object) -> builtins.bool" |
| 4004 |
tmp/b.py:5: note: Revealed type is "def (builtins.object, builtins.object) -> builtins.bool" |
| 4005 |
tmp/b.py:6: note: Revealed type is "def [_DT] (self: _DT`1, other: _DT`1) -> builtins.bool" |
| 4006 |
tmp/b.py:7: note: Revealed type is "def [_DT] (self: _DT`2, other: _DT`2) -> builtins.bool" |
| 4007 |
tmp/b.py:8: note: Revealed type is "def [_DT] (self: _DT`3, other: _DT`3) -> builtins.bool" |
| 4008 |
tmp/b.py:9: note: Revealed type is "def [_DT] (self: _DT`4, other: _DT`4) -> builtins.bool" |
| 4009 |
tmp/b.py:18: error: Unsupported operand types for < ("A" and "int") |
| 4010 |
tmp/b.py:19: error: Unsupported operand types for <= ("A" and "int") |
| 4011 |
tmp/b.py:20: error: Unsupported operand types for > ("A" and "int") |
| 4012 |
tmp/b.py:21: error: Unsupported operand types for >= ("A" and "int") |
| 4013 |
tmp/b.py:25: error: Unsupported operand types for > ("A" and "int") |
| 4014 |
tmp/b.py:26: error: Unsupported operand types for >= ("A" and "int") |
| 4015 |
tmp/b.py:27: error: Unsupported operand types for < ("A" and "int") |
| 4016 |
tmp/b.py:28: error: Unsupported operand types for <= ("A" and "int") |
| 4017 |
|
| 4018 |
[case testIncrementalDataclassesSubclassModified] |
| 4019 |
from b import B |
| 4020 |
B(5, 'foo') |
| 4021 |
|
| 4022 |
[file a.py] |
| 4023 |
from dataclasses import dataclass |
| 4024 |
|
| 4025 |
@dataclass |
| 4026 |
class A: |
| 4027 |
x: int |
| 4028 |
|
| 4029 |
[file b.py] |
| 4030 |
from a import A |
| 4031 |
from dataclasses import dataclass |
| 4032 |
|
| 4033 |
@dataclass |
| 4034 |
class B(A): |
| 4035 |
y: str |
| 4036 |
|
| 4037 |
[file b.py.2] |
| 4038 |
from a import A |
| 4039 |
from dataclasses import dataclass |
| 4040 |
|
| 4041 |
@dataclass |
| 4042 |
class B(A): |
| 4043 |
y: int |
| 4044 |
|
| 4045 |
[builtins fixtures/dataclasses.pyi] |
| 4046 |
[out1] |
| 4047 |
[out2] |
| 4048 |
main:2: error: Argument 2 to "B" has incompatible type "str"; expected "int" |
| 4049 |
[rechecked b] |
| 4050 |
|
| 4051 |
[case testIncrementalDataclassesSubclassModifiedErrorFirst] |
| 4052 |
from b import B |
| 4053 |
B(5, 'foo') |
| 4054 |
|
| 4055 |
[file a.py] |
| 4056 |
from dataclasses import dataclass |
| 4057 |
|
| 4058 |
@dataclass |
| 4059 |
class A: |
| 4060 |
x: int |
| 4061 |
|
| 4062 |
[file b.py] |
| 4063 |
from a import A |
| 4064 |
from dataclasses import dataclass |
| 4065 |
|
| 4066 |
@dataclass |
| 4067 |
class B(A): |
| 4068 |
y: int |
| 4069 |
|
| 4070 |
[file b.py.2] |
| 4071 |
from a import A |
| 4072 |
from dataclasses import dataclass |
| 4073 |
|
| 4074 |
@dataclass |
| 4075 |
class B(A): |
| 4076 |
y: str |
| 4077 |
|
| 4078 |
[builtins fixtures/dataclasses.pyi] |
| 4079 |
[out1] |
| 4080 |
main:2: error: Argument 2 to "B" has incompatible type "str"; expected "int" |
| 4081 |
|
| 4082 |
[out2] |
| 4083 |
[rechecked b] |
| 4084 |
|
| 4085 |
[case testIncrementalDataclassesThreeFiles] |
| 4086 |
from c import C |
| 4087 |
C('foo', 5, True) |
| 4088 |
|
| 4089 |
[file a.py] |
| 4090 |
from dataclasses import dataclass |
| 4091 |
|
| 4092 |
@dataclass |
| 4093 |
class A: |
| 4094 |
a: int |
| 4095 |
|
| 4096 |
[file b.py] |
| 4097 |
from dataclasses import dataclass |
| 4098 |
|
| 4099 |
@dataclass |
| 4100 |
class B: |
| 4101 |
b: str |
| 4102 |
|
| 4103 |
[file b.py.2] |
| 4104 |
from dataclasses import dataclass |
| 4105 |
|
| 4106 |
@dataclass |
| 4107 |
class B: |
| 4108 |
b: str |
| 4109 |
c: str |
| 4110 |
|
| 4111 |
[file c.py] |
| 4112 |
from a import A |
| 4113 |
from b import B |
| 4114 |
from dataclasses import dataclass |
| 4115 |
|
| 4116 |
@dataclass |
| 4117 |
class C(A, B): |
| 4118 |
c: bool |
| 4119 |
|
| 4120 |
[builtins fixtures/dataclasses.pyi] |
| 4121 |
[out1] |
| 4122 |
[out2] |
| 4123 |
tmp/c.py:7: error: Incompatible types in assignment (expression has type "bool", base class "B" defined the type as "str") |
| 4124 |
main:2: error: Argument 2 to "C" has incompatible type "int"; expected "bool" |
| 4125 |
|
| 4126 |
[case testIncrementalDataclassesThreeRuns] |
| 4127 |
from a import A |
| 4128 |
A(5) |
| 4129 |
|
| 4130 |
[file a.py] |
| 4131 |
from dataclasses import dataclass |
| 4132 |
|
| 4133 |
@dataclass |
| 4134 |
class A: |
| 4135 |
a: int |
| 4136 |
|
| 4137 |
[file a.py.2] |
| 4138 |
from dataclasses import dataclass |
| 4139 |
|
| 4140 |
@dataclass |
| 4141 |
class A: |
| 4142 |
a: str |
| 4143 |
|
| 4144 |
[file a.py.3] |
| 4145 |
from dataclasses import dataclass |
| 4146 |
|
| 4147 |
@dataclass |
| 4148 |
class A: |
| 4149 |
a: int = 6 |
| 4150 |
|
| 4151 |
[builtins fixtures/dataclasses.pyi] |
| 4152 |
[out1] |
| 4153 |
[out2] |
| 4154 |
main:2: error: Argument 1 to "A" has incompatible type "int"; expected "str" |
| 4155 |
[out3] |
| 4156 |
|
| 4157 |
[case testParentPatchingMess] |
| 4158 |
# flags: --ignore-missing-imports --follow-imports=skip |
| 4159 |
# cmd: mypy -m d d.k d.k.a d.k.v t |
| 4160 |
[file d/__init__.py] |
| 4161 |
[file d/k/__init__.py] |
| 4162 |
from d.k.a import x |
| 4163 |
[file d/k/a.py] |
| 4164 |
x = 10 |
| 4165 |
[file d/k/v.py] |
| 4166 |
from d.k.e import x |
| 4167 |
|
| 4168 |
[file t.py] |
| 4169 |
from d import k |
| 4170 |
[file t.py.2] |
| 4171 |
from d import k |
| 4172 |
# dummy change |
| 4173 |
|
| 4174 |
[case testCachedBadProtocolNote] |
| 4175 |
import b |
| 4176 |
[file a.py] |
| 4177 |
from typing import TypedDict |
| 4178 |
Point = TypedDict('Point', {'x': int, 'y': int}) |
| 4179 |
[file b.py] |
| 4180 |
from typing import Iterable |
| 4181 |
from a import Point |
| 4182 |
p: Point |
| 4183 |
it: Iterable[int] = p |
| 4184 |
[file b.py.2] |
| 4185 |
from typing import Iterable |
| 4186 |
from a import Point |
| 4187 |
p: Point |
| 4188 |
it: Iterable[int] = p # change |
| 4189 |
[builtins fixtures/dict.pyi] |
| 4190 |
[typing fixtures/typing-full.pyi] |
| 4191 |
[out] |
| 4192 |
tmp/b.py:4: error: Incompatible types in assignment (expression has type "Point", variable has type "Iterable[int]") |
| 4193 |
tmp/b.py:4: note: Following member(s) of "Point" have conflicts: |
| 4194 |
tmp/b.py:4: note: Expected: |
| 4195 |
tmp/b.py:4: note: def __iter__(self) -> Iterator[int] |
| 4196 |
tmp/b.py:4: note: Got: |
| 4197 |
tmp/b.py:4: note: def __iter__(self) -> Iterator[str] |
| 4198 |
[out2] |
| 4199 |
tmp/b.py:4: error: Incompatible types in assignment (expression has type "Point", variable has type "Iterable[int]") |
| 4200 |
tmp/b.py:4: note: Following member(s) of "Point" have conflicts: |
| 4201 |
tmp/b.py:4: note: Expected: |
| 4202 |
tmp/b.py:4: note: def __iter__(self) -> Iterator[int] |
| 4203 |
tmp/b.py:4: note: Got: |
| 4204 |
tmp/b.py:4: note: def __iter__(self) -> Iterator[str] |
| 4205 |
|
| 4206 |
[case testIndirectDepsAlwaysPatched-writescache] |
| 4207 |
# flags: --no-incremental |
| 4208 |
# flags2: --incremental |
| 4209 |
from b import C |
| 4210 |
def f() -> None: |
| 4211 |
x: int = C().x |
| 4212 |
[file b.py] |
| 4213 |
from c import C |
| 4214 |
[file c.pyi] |
| 4215 |
class C: |
| 4216 |
x: int |
| 4217 |
[file c.pyi.2] |
| 4218 |
class C: |
| 4219 |
x: str |
| 4220 |
[out] |
| 4221 |
[out2] |
| 4222 |
main:5: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 4223 |
|
| 4224 |
[case testBazelFlagIgnoresFileChanges-skip] |
| 4225 |
-- This test fails on windows, when the mypy source in on a different drive than |
| 4226 |
-- the run-directory. In this case os.path.relpath(...) fails with an exception |
| 4227 |
-- Since the initial run wrote a cache file, the second run ignores the source |
| 4228 |
# flags: --bazel |
| 4229 |
from a import f |
| 4230 |
f() |
| 4231 |
[file a.py] |
| 4232 |
def f(): pass |
| 4233 |
[file a.py.2] |
| 4234 |
[out] |
| 4235 |
[out2] |
| 4236 |
|
| 4237 |
[case testModuleGetattrInitIncremental] |
| 4238 |
import c |
| 4239 |
[file c.py] |
| 4240 |
import a.b |
| 4241 |
x = a.b.f() |
| 4242 |
[file c.py.2] |
| 4243 |
import a.b |
| 4244 |
x = a.b.f() |
| 4245 |
# touch |
| 4246 |
[file a/__init__.pyi] |
| 4247 |
from typing import Any |
| 4248 |
def __getattr__(attr: str) -> Any: ... |
| 4249 |
[builtins fixtures/module.pyi] |
| 4250 |
[out] |
| 4251 |
[out2] |
| 4252 |
|
| 4253 |
[case testModuleGetattrInitIncremental2] |
| 4254 |
import c |
| 4255 |
[file c.py] |
| 4256 |
import a.b.c |
| 4257 |
[file c.py.2] |
| 4258 |
import a.b.c |
| 4259 |
# touch |
| 4260 |
[file a/__init__.pyi] |
| 4261 |
from typing import Any |
| 4262 |
def __getattr__(attr: str) -> Any: ... |
| 4263 |
[file a/b.pyi] |
| 4264 |
# empty |
| 4265 |
[builtins fixtures/module.pyi] |
| 4266 |
[out] |
| 4267 |
tmp/c.py:1: error: Cannot find implementation or library stub for module named "a.b.c" |
| 4268 |
tmp/c.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports |
| 4269 |
[out2] |
| 4270 |
tmp/c.py:1: error: Cannot find implementation or library stub for module named "a.b.c" |
| 4271 |
tmp/c.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports |
| 4272 |
|
| 4273 |
[case testModuleGetattrIncrementalSerializeVarFlag] |
| 4274 |
import main |
| 4275 |
|
| 4276 |
[file main.py] |
| 4277 |
from b import A, f |
| 4278 |
f() |
| 4279 |
|
| 4280 |
[file main.py.3] |
| 4281 |
from b import A, f # foo |
| 4282 |
f() |
| 4283 |
|
| 4284 |
[file b.py] |
| 4285 |
from c import A |
| 4286 |
def f() -> A: ... |
| 4287 |
|
| 4288 |
[file b.py.2] |
| 4289 |
from c import A # foo |
| 4290 |
def f() -> A: ... |
| 4291 |
|
| 4292 |
[file c.py] |
| 4293 |
from d import A |
| 4294 |
|
| 4295 |
[file d.pyi] |
| 4296 |
def __getattr__(n): ... |
| 4297 |
[out1] |
| 4298 |
[out2] |
| 4299 |
[out3] |
| 4300 |
|
| 4301 |
[case testAddedMissingStubs] |
| 4302 |
# flags: --ignore-missing-imports |
| 4303 |
from missing import f |
| 4304 |
f(int()) |
| 4305 |
[file missing.pyi.2] |
| 4306 |
def f(x: str) -> None: pass |
| 4307 |
[out] |
| 4308 |
[out2] |
| 4309 |
main:3: error: Argument 1 to "f" has incompatible type "int"; expected "str" |
| 4310 |
|
| 4311 |
[case testAddedMissingStubsPackage] |
| 4312 |
# flags: --ignore-missing-imports |
| 4313 |
import package.missing |
| 4314 |
package.missing.f(int()) |
| 4315 |
[file package/__init__.pyi.2] |
| 4316 |
[file package/missing.pyi.2] |
| 4317 |
def f(x: str) -> None: pass |
| 4318 |
[out] |
| 4319 |
[out2] |
| 4320 |
main:3: error: Argument 1 to "f" has incompatible type "int"; expected "str" |
| 4321 |
|
| 4322 |
[case testAddedMissingStubsPackageFrom] |
| 4323 |
# flags: --ignore-missing-imports |
| 4324 |
from package import missing |
| 4325 |
missing.f(int()) |
| 4326 |
[file package/__init__.pyi.2] |
| 4327 |
[file package/missing.pyi.2] |
| 4328 |
def f(x: str) -> None: pass |
| 4329 |
[out] |
| 4330 |
[out2] |
| 4331 |
main:3: error: Argument 1 to "f" has incompatible type "int"; expected "str" |
| 4332 |
|
| 4333 |
[case testAddedMissingStubsPackagePartial] |
| 4334 |
# flags: --ignore-missing-imports |
| 4335 |
import package.missing |
| 4336 |
package.missing.f(int()) |
| 4337 |
[file package/__init__.pyi] |
| 4338 |
[file package/missing.pyi.2] |
| 4339 |
def f(x: str) -> None: pass |
| 4340 |
[out] |
| 4341 |
[out2] |
| 4342 |
main:3: error: Argument 1 to "f" has incompatible type "int"; expected "str" |
| 4343 |
|
| 4344 |
[case testAddedMissingStubsPackagePartialGetAttr] |
| 4345 |
import package.missing |
| 4346 |
package.missing.f(int()) |
| 4347 |
[file package/__init__.pyi] |
| 4348 |
from typing import Any |
| 4349 |
def __getattr__(attr: str) -> Any: ... |
| 4350 |
[file package/missing.pyi.2] |
| 4351 |
def f(x: str) -> None: pass |
| 4352 |
[out] |
| 4353 |
[out2] |
| 4354 |
main:2: error: Argument 1 to "f" has incompatible type "int"; expected "str" |
| 4355 |
|
| 4356 |
[case testAddedMissingStubsIgnore] |
| 4357 |
from missing import f # type: ignore |
| 4358 |
f(int()) |
| 4359 |
[file missing.pyi.2] |
| 4360 |
def f(x: str) -> None: pass |
| 4361 |
[out] |
| 4362 |
[out2] |
| 4363 |
main:2: error: Argument 1 to "f" has incompatible type "int"; expected "str" |
| 4364 |
|
| 4365 |
[case testAddedMissingStubsIgnorePackage] |
| 4366 |
import package.missing # type: ignore |
| 4367 |
package.missing.f(int()) |
| 4368 |
[file package/__init__.pyi.2] |
| 4369 |
[file package/missing.pyi.2] |
| 4370 |
def f(x: str) -> None: pass |
| 4371 |
[out] |
| 4372 |
[out2] |
| 4373 |
main:2: error: Argument 1 to "f" has incompatible type "int"; expected "str" |
| 4374 |
|
| 4375 |
[case testAddedMissingStubsIgnorePackageFrom] |
| 4376 |
from package import missing # type: ignore |
| 4377 |
missing.f(int()) |
| 4378 |
[file package/__init__.pyi.2] |
| 4379 |
[file package/missing.pyi.2] |
| 4380 |
def f(x: str) -> None: pass |
| 4381 |
[out] |
| 4382 |
[out2] |
| 4383 |
main:2: error: Argument 1 to "f" has incompatible type "int"; expected "str" |
| 4384 |
|
| 4385 |
[case testAddedMissingStubsIgnorePackagePartial] |
| 4386 |
import package.missing # type: ignore |
| 4387 |
package.missing.f(int()) |
| 4388 |
[file package/__init__.pyi] |
| 4389 |
[file package/missing.pyi.2] |
| 4390 |
def f(x: str) -> None: pass |
| 4391 |
[out] |
| 4392 |
[out2] |
| 4393 |
main:2: error: Argument 1 to "f" has incompatible type "int"; expected "str" |
| 4394 |
|
| 4395 |
-- Test cases for final qualifier |
| 4396 |
|
| 4397 |
[case testFinalAddFinalVarAssign] |
| 4398 |
import mod |
| 4399 |
from a import D |
| 4400 |
from mod import x |
| 4401 |
|
| 4402 |
mod.x = 2 # This an all below are errors. |
| 4403 |
x = 2 |
| 4404 |
d: D |
| 4405 |
d.y = 2 |
| 4406 |
d.z = 2 |
| 4407 |
D.y = 2 |
| 4408 |
[file a.py] |
| 4409 |
import mod |
| 4410 |
|
| 4411 |
class D(mod.C): |
| 4412 |
pass |
| 4413 |
[file mod.py] |
| 4414 |
x = 1 |
| 4415 |
class C: |
| 4416 |
y = 1 |
| 4417 |
def __init__(self) -> None: |
| 4418 |
self.z = 1 |
| 4419 |
|
| 4420 |
[file mod.py.2] |
| 4421 |
from typing import Final |
| 4422 |
|
| 4423 |
x: Final = 1 |
| 4424 |
class C: |
| 4425 |
y: Final = 1 |
| 4426 |
def __init__(self) -> None: |
| 4427 |
self.z: Final = 1 |
| 4428 |
[out] |
| 4429 |
[out2] |
| 4430 |
main:5: error: Cannot assign to final name "x" |
| 4431 |
main:6: error: Cannot assign to final name "x" |
| 4432 |
main:8: error: Cannot assign to final attribute "y" |
| 4433 |
main:9: error: Cannot assign to final attribute "z" |
| 4434 |
main:10: error: Cannot assign to final attribute "y" |
| 4435 |
|
| 4436 |
[case testFinalAddFinalVarOverride] |
| 4437 |
from mod import C |
| 4438 |
|
| 4439 |
class D(C): |
| 4440 |
x = 2 |
| 4441 |
def __init__(self) -> None: |
| 4442 |
self.y = 2 |
| 4443 |
class E(C): |
| 4444 |
y = 2 |
| 4445 |
def __init__(self) -> None: |
| 4446 |
self.x = 2 |
| 4447 |
|
| 4448 |
[file mod.py] |
| 4449 |
class C: |
| 4450 |
x = 1 |
| 4451 |
def __init__(self) -> None: |
| 4452 |
self.y = 1 |
| 4453 |
|
| 4454 |
[file mod.py.2] |
| 4455 |
from typing import Final |
| 4456 |
|
| 4457 |
class C: |
| 4458 |
x: Final = 1 |
| 4459 |
def __init__(self) -> None: |
| 4460 |
self.y: Final = 1 |
| 4461 |
[out] |
| 4462 |
[out2] |
| 4463 |
main:4: error: Cannot assign to final name "x" |
| 4464 |
main:6: error: Cannot assign to final attribute "y" |
| 4465 |
main:8: error: Cannot assign to final name "y" |
| 4466 |
main:10: error: Cannot assign to final attribute "x" |
| 4467 |
|
| 4468 |
[case testFinalAddFinalMethodOverride] |
| 4469 |
from mod import C |
| 4470 |
|
| 4471 |
class D(C): |
| 4472 |
def meth(self) -> int: ... |
| 4473 |
|
| 4474 |
[file mod.py] |
| 4475 |
class C: |
| 4476 |
def meth(self) -> int: ... |
| 4477 |
|
| 4478 |
[file mod.py.2] |
| 4479 |
from typing import final |
| 4480 |
|
| 4481 |
class C: |
| 4482 |
@final |
| 4483 |
def meth(self) -> int: ... |
| 4484 |
[out] |
| 4485 |
[out2] |
| 4486 |
main:4: error: Cannot override final attribute "meth" (previously declared in base class "C") |
| 4487 |
|
| 4488 |
-- These tests should just not crash |
| 4489 |
[case testOverrideByBadVar] |
| 4490 |
import a |
| 4491 |
[file a.py] |
| 4492 |
import lib |
| 4493 |
x = 1 |
| 4494 |
[file a.py.2] |
| 4495 |
import lib |
| 4496 |
x = 2 |
| 4497 |
[file lib.py] |
| 4498 |
class Slow: |
| 4499 |
pass |
| 4500 |
|
| 4501 |
s: Slow |
| 4502 |
from cext import Slow # type: ignore |
| 4503 |
[out] |
| 4504 |
[out2] |
| 4505 |
|
| 4506 |
[case testOverrideByBadVarAlias] |
| 4507 |
import a |
| 4508 |
[file a.py] |
| 4509 |
import lib |
| 4510 |
x = 1 |
| 4511 |
[file a.py.2] |
| 4512 |
import lib |
| 4513 |
x = 2 |
| 4514 |
[file lib.py] |
| 4515 |
class Slow: |
| 4516 |
pass |
| 4517 |
|
| 4518 |
A = Slow |
| 4519 |
from cext import Slow # type: ignore |
| 4520 |
[out] |
| 4521 |
[out2] |
| 4522 |
|
| 4523 |
[case testOverrideByBadVarClass] |
| 4524 |
import a |
| 4525 |
[file a.py] |
| 4526 |
import lib |
| 4527 |
x = 1 |
| 4528 |
[file a.py.2] |
| 4529 |
import lib |
| 4530 |
x = 2 |
| 4531 |
[file lib.py] |
| 4532 |
class C: |
| 4533 |
class Slow: |
| 4534 |
pass |
| 4535 |
s: Slow |
| 4536 |
from cext import Slow # type: ignore |
| 4537 |
[out] |
| 4538 |
[out2] |
| 4539 |
|
| 4540 |
[case testOverrideByBadVarClassAlias] |
| 4541 |
import a |
| 4542 |
[file a.py] |
| 4543 |
import lib |
| 4544 |
x = 1 |
| 4545 |
[file a.py.2] |
| 4546 |
import lib |
| 4547 |
x = 2 |
| 4548 |
[file lib.py] |
| 4549 |
class C: |
| 4550 |
class Slow: |
| 4551 |
pass |
| 4552 |
A = Slow |
| 4553 |
from cext import Slow # type: ignore |
| 4554 |
[out] |
| 4555 |
[out2] |
| 4556 |
|
| 4557 |
[case testOverrideByBadVarExisting] |
| 4558 |
import a |
| 4559 |
[file a.py] |
| 4560 |
import lib |
| 4561 |
x = 1 |
| 4562 |
[file a.py.2] |
| 4563 |
import lib |
| 4564 |
x = 2 |
| 4565 |
[file lib.py] |
| 4566 |
class Slow: |
| 4567 |
pass |
| 4568 |
|
| 4569 |
s: Slow |
| 4570 |
from cext import Slow # type: ignore |
| 4571 |
[file cext.py] |
| 4572 |
Slow = 1 |
| 4573 |
[out] |
| 4574 |
[out2] |
| 4575 |
|
| 4576 |
[case testOverrideByBadVarAliasExisting] |
| 4577 |
import a |
| 4578 |
[file a.py] |
| 4579 |
import lib |
| 4580 |
x = 1 |
| 4581 |
[file a.py.2] |
| 4582 |
import lib |
| 4583 |
x = 2 |
| 4584 |
[file lib.py] |
| 4585 |
class Slow: |
| 4586 |
pass |
| 4587 |
|
| 4588 |
A = Slow |
| 4589 |
from cext import Slow # type: ignore |
| 4590 |
[file cext.py] |
| 4591 |
Slow = 1 |
| 4592 |
[out] |
| 4593 |
[out2] |
| 4594 |
|
| 4595 |
[case testOverrideByBadFunction] |
| 4596 |
import a |
| 4597 |
[file a.py] |
| 4598 |
import lib |
| 4599 |
x = 1 |
| 4600 |
[file a.py.2] |
| 4601 |
import lib |
| 4602 |
x = 2 |
| 4603 |
[file lib.py] |
| 4604 |
class C: |
| 4605 |
class Slow: |
| 4606 |
pass |
| 4607 |
|
| 4608 |
s: Slow |
| 4609 |
def Slow() -> None: ... # type: ignore |
| 4610 |
[out] |
| 4611 |
[out2] |
| 4612 |
|
| 4613 |
[case testOverrideByBadVarLocal] |
| 4614 |
import a |
| 4615 |
[file a.py] |
| 4616 |
import lib |
| 4617 |
x = 1 |
| 4618 |
[file a.py.2] |
| 4619 |
import lib |
| 4620 |
x = 2 |
| 4621 |
[file lib.py] |
| 4622 |
def outer() -> None: |
| 4623 |
class Slow: |
| 4624 |
pass |
| 4625 |
|
| 4626 |
s: Slow |
| 4627 |
from cext import Slow # type: ignore |
| 4628 |
[out] |
| 4629 |
[out2] |
| 4630 |
|
| 4631 |
[case testRecursiveAliasImported] |
| 4632 |
import a |
| 4633 |
|
| 4634 |
[file a.py] |
| 4635 |
import lib |
| 4636 |
x: int |
| 4637 |
|
| 4638 |
[file a.py.2] |
| 4639 |
import lib |
| 4640 |
x: lib.A |
| 4641 |
reveal_type(x) |
| 4642 |
|
| 4643 |
[file lib.pyi] |
| 4644 |
from typing import List |
| 4645 |
MYPY = False |
| 4646 |
if MYPY: # Force processing order |
| 4647 |
from other import B |
| 4648 |
A = List[B] # type: ignore |
| 4649 |
|
| 4650 |
[file other.pyi] |
| 4651 |
from typing import List |
| 4652 |
from lib import A |
| 4653 |
B = List[A] |
| 4654 |
|
| 4655 |
[builtins fixtures/list.pyi] |
| 4656 |
[out] |
| 4657 |
[out2] |
| 4658 |
tmp/a.py:3: note: Revealed type is "builtins.list[builtins.list[...]]" |
| 4659 |
|
| 4660 |
[case testRecursiveNamedTupleTypedDict] |
| 4661 |
import a |
| 4662 |
[file a.py] |
| 4663 |
import lib |
| 4664 |
x: int |
| 4665 |
[file a.py.2] |
| 4666 |
import lib |
| 4667 |
x: lib.A |
| 4668 |
reveal_type(x.x['x']) |
| 4669 |
[file lib.pyi] |
| 4670 |
from typing import NamedTuple |
| 4671 |
from other import B |
| 4672 |
A = NamedTuple('A', [('x', B)]) |
| 4673 |
[file other.pyi] |
| 4674 |
from typing import TypedDict |
| 4675 |
from lib import A |
| 4676 |
B = TypedDict('B', {'x': A}) |
| 4677 |
[builtins fixtures/dict.pyi] |
| 4678 |
[typing fixtures/typing-typeddict.pyi] |
| 4679 |
[out] |
| 4680 |
[out2] |
| 4681 |
tmp/a.py:3: note: Revealed type is "tuple[TypedDict('other.B', {'x': tuple[..., fallback=lib.A]}), fallback=lib.A]" |
| 4682 |
|
| 4683 |
[case testFollowImportSkipNotInvalidatedOnPresent] |
| 4684 |
# flags: --follow-imports=skip |
| 4685 |
# cmd: mypy -m main |
| 4686 |
[file main.py] |
| 4687 |
import other |
| 4688 |
[file other.py] |
| 4689 |
x = 1 |
| 4690 |
[file other.py.2] |
| 4691 |
x = 'hi' |
| 4692 |
[stale] |
| 4693 |
[rechecked] |
| 4694 |
|
| 4695 |
[case testFollowImportSkipNotInvalidatedOnPresentPackage] |
| 4696 |
# flags: --follow-imports=skip |
| 4697 |
# cmd: mypy -m main |
| 4698 |
[file main.py] |
| 4699 |
import other |
| 4700 |
[file other/__init__.py] |
| 4701 |
x = 1 |
| 4702 |
[file other/__init__.py.2] |
| 4703 |
x = 'hi' |
| 4704 |
[stale] |
| 4705 |
[rechecked] |
| 4706 |
|
| 4707 |
[case testFollowImportSkipNotInvalidatedOnAdded] |
| 4708 |
# flags: --follow-imports=skip --ignore-missing-imports |
| 4709 |
# cmd: mypy -m main |
| 4710 |
[file main.py] |
| 4711 |
import other |
| 4712 |
[file other.py.2] |
| 4713 |
x = 1 |
| 4714 |
[stale] |
| 4715 |
[rechecked] |
| 4716 |
|
| 4717 |
[case testFollowImportSkipInvalidatedOnAddedStub] |
| 4718 |
# flags: --follow-imports=skip --ignore-missing-imports |
| 4719 |
# cmd: mypy -m main |
| 4720 |
[file main.py] |
| 4721 |
import other |
| 4722 |
[file other.pyi.2] |
| 4723 |
x = 1 |
| 4724 |
[stale main, other] |
| 4725 |
[rechecked main, other] |
| 4726 |
|
| 4727 |
[case testFollowImportSkipNotInvalidatedOnAddedStubOnFollowForStubs] |
| 4728 |
# flags: --follow-imports=skip --ignore-missing-imports --config-file=tmp/mypy.ini |
| 4729 |
# cmd: mypy -m main |
| 4730 |
[file main.py] |
| 4731 |
import other |
| 4732 |
[file other.pyi.2] |
| 4733 |
x = 1 |
| 4734 |
[file mypy.ini] |
| 4735 |
\[mypy] |
| 4736 |
follow_imports_for_stubs = True |
| 4737 |
[stale] |
| 4738 |
[rechecked] |
| 4739 |
|
| 4740 |
[case testAddedSkippedStubsPackageFrom] |
| 4741 |
# flags: --follow-imports=skip --ignore-missing-imports |
| 4742 |
# cmd: mypy -m main |
| 4743 |
# cmd2: mypy -m main package package.missing |
| 4744 |
[file main.py] |
| 4745 |
from package import missing |
| 4746 |
missing.f(int()) |
| 4747 |
[file package/__init__.py] |
| 4748 |
[file package/missing.py] |
| 4749 |
def f(x: str) -> None: pass |
| 4750 |
[out] |
| 4751 |
[out2] |
| 4752 |
tmp/main.py:2: error: Argument 1 to "f" has incompatible type "int"; expected "str" |
| 4753 |
|
| 4754 |
[case testOverrideByIdemAlias] |
| 4755 |
# https://github.com/python/mypy/issues/6404 |
| 4756 |
|
| 4757 |
import a |
| 4758 |
[file a.py] |
| 4759 |
import lib |
| 4760 |
x = 1 |
| 4761 |
[file a.py.2] |
| 4762 |
import lib |
| 4763 |
x = 2 |
| 4764 |
[file lib.py] |
| 4765 |
C = C # type: ignore |
| 4766 |
class C: # type: ignore |
| 4767 |
pass |
| 4768 |
[out] |
| 4769 |
[out2] |
| 4770 |
|
| 4771 |
[case testOverrideByIdemAliasReversed] |
| 4772 |
import a |
| 4773 |
[file a.py] |
| 4774 |
import lib |
| 4775 |
x = 1 |
| 4776 |
[file a.py.2] |
| 4777 |
import lib |
| 4778 |
x = 2 |
| 4779 |
[file lib.py] |
| 4780 |
class C: |
| 4781 |
pass |
| 4782 |
C = C # type: ignore |
| 4783 |
x: C |
| 4784 |
[out] |
| 4785 |
[out2] |
| 4786 |
|
| 4787 |
[case testOverrideByIdemAliasGeneric] |
| 4788 |
import a |
| 4789 |
[file a.py] |
| 4790 |
import lib |
| 4791 |
x = 1 |
| 4792 |
[file a.py.2] |
| 4793 |
import lib |
| 4794 |
x = 2 |
| 4795 |
[file lib.py] |
| 4796 |
from typing import Generic, TypeVar |
| 4797 |
|
| 4798 |
T = TypeVar('T') |
| 4799 |
|
| 4800 |
class C(Generic[T]): |
| 4801 |
pass |
| 4802 |
C = C[int] # type: ignore |
| 4803 |
x: C |
| 4804 |
[out] |
| 4805 |
[out2] |
| 4806 |
|
| 4807 |
[case testOverrideByIdemAliasImported] |
| 4808 |
import a |
| 4809 |
[file a.py] |
| 4810 |
import lib |
| 4811 |
x = 1 |
| 4812 |
[file a.py.2] |
| 4813 |
import lib |
| 4814 |
x = 2 |
| 4815 |
[file lib.py] |
| 4816 |
from other import C |
| 4817 |
C = C # type: ignore |
| 4818 |
x: C |
| 4819 |
[file other.py] |
| 4820 |
class C: |
| 4821 |
pass |
| 4822 |
[out] |
| 4823 |
[out2] |
| 4824 |
|
| 4825 |
[case testOverrideByIdemAliasImportedReversed] |
| 4826 |
import a |
| 4827 |
[file a.py] |
| 4828 |
import lib |
| 4829 |
x = 1 |
| 4830 |
[file a.py.2] |
| 4831 |
import lib |
| 4832 |
x = 2 |
| 4833 |
[file lib.py] |
| 4834 |
C = C # type: ignore |
| 4835 |
from other import C |
| 4836 |
[file other.py] |
| 4837 |
class C: |
| 4838 |
pass |
| 4839 |
[out] |
| 4840 |
[out2] |
| 4841 |
|
| 4842 |
[case testConditionalExceptionAliasOverride] |
| 4843 |
import a |
| 4844 |
[file a.py] |
| 4845 |
import lib |
| 4846 |
try: |
| 4847 |
x = 1 |
| 4848 |
except lib.Exception as e: |
| 4849 |
pass |
| 4850 |
[file a.py.2] |
| 4851 |
import lib |
| 4852 |
try: |
| 4853 |
x = 2 |
| 4854 |
except lib.Exception as e: |
| 4855 |
pass |
| 4856 |
[file lib.py] |
| 4857 |
try: |
| 4858 |
Exception = Exception |
| 4859 |
except BaseException: |
| 4860 |
class Exception(BaseException): pass # type: ignore |
| 4861 |
|
| 4862 |
try: |
| 4863 |
pass |
| 4864 |
except Exception as e: |
| 4865 |
pass |
| 4866 |
[builtins fixtures/exception.pyi] |
| 4867 |
[out] |
| 4868 |
[out2] |
| 4869 |
|
| 4870 |
[case testBadEnumLoading] |
| 4871 |
import a |
| 4872 |
[file a.py] |
| 4873 |
from b import E |
| 4874 |
x: E |
| 4875 |
y = 1 |
| 4876 |
|
| 4877 |
[file a.py.2] |
| 4878 |
from b import E |
| 4879 |
x: E |
| 4880 |
y = 2 |
| 4881 |
|
| 4882 |
[file b.py] |
| 4883 |
from typing import List |
| 4884 |
from enum import Enum |
| 4885 |
|
| 4886 |
def f() -> List[str]: ... |
| 4887 |
|
| 4888 |
E = Enum('E', f()) # type: ignore |
| 4889 |
[builtins fixtures/list.pyi] |
| 4890 |
[out] |
| 4891 |
[out2] |
| 4892 |
|
| 4893 |
[case testChangedPluginsInvalidateCache] |
| 4894 |
# flags: --config-file tmp/mypy.ini |
| 4895 |
import a |
| 4896 |
[file a.py] |
| 4897 |
from b import x |
| 4898 |
y: int = x |
| 4899 |
|
| 4900 |
[file a.py.2] |
| 4901 |
from b import x |
| 4902 |
y: int = x |
| 4903 |
touch = 1 |
| 4904 |
|
| 4905 |
[file b.py] |
| 4906 |
class C: ... |
| 4907 |
def f() -> C: ... |
| 4908 |
x = f() |
| 4909 |
|
| 4910 |
[file basic_plugin.py] |
| 4911 |
from mypy.plugin import Plugin |
| 4912 |
|
| 4913 |
class MyPlugin(Plugin): |
| 4914 |
def get_function_hook(self, fullname): |
| 4915 |
if fullname.endswith('.f'): |
| 4916 |
return my_hook |
| 4917 |
assert fullname is not None |
| 4918 |
return None |
| 4919 |
|
| 4920 |
def my_hook(ctx): |
| 4921 |
return ctx.api.named_generic_type('builtins.int', []) |
| 4922 |
|
| 4923 |
def plugin(version): |
| 4924 |
return MyPlugin |
| 4925 |
|
| 4926 |
[file basic_plugin.py.2] |
| 4927 |
from mypy.plugin import Plugin |
| 4928 |
|
| 4929 |
class MyPlugin(Plugin): |
| 4930 |
def get_function_hook(self, fullname): |
| 4931 |
if fullname.endswith('.f'): |
| 4932 |
return my_hook |
| 4933 |
assert fullname is not None |
| 4934 |
return None |
| 4935 |
|
| 4936 |
def my_hook(ctx): |
| 4937 |
return ctx.api.named_generic_type('builtins.str', []) |
| 4938 |
|
| 4939 |
def plugin(version): |
| 4940 |
return MyPlugin |
| 4941 |
[file mypy.ini] |
| 4942 |
\[mypy] |
| 4943 |
plugins=basic_plugin.py |
| 4944 |
[out] |
| 4945 |
[out2] |
| 4946 |
tmp/a.py:2: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 4947 |
|
| 4948 |
[case testChangedPluginsInvalidateCache2] |
| 4949 |
# flags: --config-file tmp/mypy.ini |
| 4950 |
import a |
| 4951 |
[file a.py] |
| 4952 |
from b import x |
| 4953 |
y: int = x |
| 4954 |
|
| 4955 |
[file a.py.2] |
| 4956 |
from b import x |
| 4957 |
y: int = x |
| 4958 |
touch = 1 |
| 4959 |
|
| 4960 |
[file b.py] |
| 4961 |
class C: ... |
| 4962 |
def f() -> C: ... |
| 4963 |
x = f() |
| 4964 |
|
| 4965 |
[file basic_plugin.py] |
| 4966 |
from mypy.plugin import Plugin |
| 4967 |
from version_plugin import __version__, choice |
| 4968 |
|
| 4969 |
class MyPlugin(Plugin): |
| 4970 |
def get_function_hook(self, fullname): |
| 4971 |
if fullname.endswith('.f'): |
| 4972 |
return my_hook |
| 4973 |
assert fullname is not None |
| 4974 |
return None |
| 4975 |
|
| 4976 |
def my_hook(ctx): |
| 4977 |
if choice: |
| 4978 |
return ctx.api.named_generic_type('builtins.int', []) |
| 4979 |
else: |
| 4980 |
return ctx.api.named_generic_type('builtins.str', []) |
| 4981 |
|
| 4982 |
def plugin(version): |
| 4983 |
return MyPlugin |
| 4984 |
|
| 4985 |
[file version_plugin.py] |
| 4986 |
__version__ = 0.1 |
| 4987 |
choice = True |
| 4988 |
|
| 4989 |
[file version_plugin.py.2] |
| 4990 |
__version__ = 0.2 |
| 4991 |
choice = False |
| 4992 |
[file mypy.ini] |
| 4993 |
\[mypy] |
| 4994 |
plugins=basic_plugin.py |
| 4995 |
[out] |
| 4996 |
[out2] |
| 4997 |
tmp/a.py:2: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 4998 |
|
| 4999 |
[case testAddedPluginsInvalidateCache] |
| 5000 |
# flags: --config-file tmp/mypy.ini |
| 5001 |
import a |
| 5002 |
[file a.py] |
| 5003 |
from b import x |
| 5004 |
y: int = x |
| 5005 |
|
| 5006 |
[file a.py.2] |
| 5007 |
from b import x |
| 5008 |
y: int = x |
| 5009 |
touch = 1 |
| 5010 |
|
| 5011 |
[file b.py] |
| 5012 |
def f() -> int: ... |
| 5013 |
x = f() |
| 5014 |
|
| 5015 |
[file basic_plugin.py] |
| 5016 |
from mypy.plugin import Plugin |
| 5017 |
|
| 5018 |
class MyPlugin(Plugin): |
| 5019 |
def get_function_hook(self, fullname): |
| 5020 |
if fullname.endswith('.f'): |
| 5021 |
return my_hook |
| 5022 |
assert fullname is not None |
| 5023 |
return None |
| 5024 |
|
| 5025 |
def my_hook(ctx): |
| 5026 |
return ctx.api.named_generic_type('builtins.str', []) |
| 5027 |
|
| 5028 |
def plugin(version): |
| 5029 |
return MyPlugin |
| 5030 |
|
| 5031 |
[file mypy.ini] |
| 5032 |
\[mypy] |
| 5033 |
python_version=3.6 |
| 5034 |
[file mypy.ini.2] |
| 5035 |
\[mypy] |
| 5036 |
python_version=3.6 |
| 5037 |
plugins=basic_plugin.py |
| 5038 |
[out] |
| 5039 |
[out2] |
| 5040 |
tmp/a.py:2: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 5041 |
|
| 5042 |
[case testRemovedPluginsInvalidateCache] |
| 5043 |
# flags: --config-file tmp/mypy.ini |
| 5044 |
import a |
| 5045 |
[file a.py] |
| 5046 |
from b import x |
| 5047 |
y: str = x |
| 5048 |
|
| 5049 |
[file a.py.2] |
| 5050 |
from b import x |
| 5051 |
y: str = x |
| 5052 |
touch = 1 |
| 5053 |
|
| 5054 |
[file b.py] |
| 5055 |
def f() -> int: ... |
| 5056 |
x = f() |
| 5057 |
|
| 5058 |
[file basic_plugin.py] |
| 5059 |
from mypy.plugin import Plugin |
| 5060 |
|
| 5061 |
class MyPlugin(Plugin): |
| 5062 |
def get_function_hook(self, fullname): |
| 5063 |
if fullname.endswith('.f'): |
| 5064 |
return my_hook |
| 5065 |
assert fullname is not None |
| 5066 |
return None |
| 5067 |
|
| 5068 |
def my_hook(ctx): |
| 5069 |
return ctx.api.named_generic_type('builtins.str', []) |
| 5070 |
|
| 5071 |
def plugin(version): |
| 5072 |
return MyPlugin |
| 5073 |
|
| 5074 |
[file mypy.ini] |
| 5075 |
\[mypy] |
| 5076 |
python_version=3.6 |
| 5077 |
plugins=basic_plugin.py |
| 5078 |
[file mypy.ini.2] |
| 5079 |
\[mypy] |
| 5080 |
python_version=3.6 |
| 5081 |
[out] |
| 5082 |
[out2] |
| 5083 |
tmp/a.py:2: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 5084 |
|
| 5085 |
[case testPluginConfigData] |
| 5086 |
# flags: --config-file tmp/mypy.ini |
| 5087 |
import a |
| 5088 |
import b |
| 5089 |
[file a.py] |
| 5090 |
[file b.py] |
| 5091 |
[file test.json] |
| 5092 |
{"a": false, "b": false} |
| 5093 |
[file test.json.2] |
| 5094 |
{"a": true, "b": false} |
| 5095 |
|
| 5096 |
[file mypy.ini] |
| 5097 |
\[mypy] |
| 5098 |
plugins=<ROOT>/test-data/unit/plugins/config_data.py |
| 5099 |
|
| 5100 |
# The config change will force a to be rechecked but not b. |
| 5101 |
[rechecked a] |
| 5102 |
|
| 5103 |
[case testLiteralIncrementalTurningIntoLiteral] |
| 5104 |
import mod |
| 5105 |
reveal_type(mod.a) |
| 5106 |
[file mod.py] |
| 5107 |
from typing import Literal |
| 5108 |
a = 1 |
| 5109 |
[file mod.py.2] |
| 5110 |
from typing import Literal |
| 5111 |
a: Literal[2] = 2 |
| 5112 |
[builtins fixtures/tuple.pyi] |
| 5113 |
[out] |
| 5114 |
main:2: note: Revealed type is "builtins.int" |
| 5115 |
[out2] |
| 5116 |
main:2: note: Revealed type is "Literal[2]" |
| 5117 |
|
| 5118 |
[case testAddedSubStarImport] |
| 5119 |
# cmd: mypy -m a pack pack.mod b |
| 5120 |
# cmd2: mypy -m other |
| 5121 |
[file a.py] |
| 5122 |
from pack import * |
| 5123 |
[file pack/__init__.py] |
| 5124 |
[file pack/mod.py] |
| 5125 |
[file b.py] |
| 5126 |
import pack.mod |
| 5127 |
[file other.py] |
| 5128 |
import a |
| 5129 |
[out] |
| 5130 |
[out2] |
| 5131 |
|
| 5132 |
[case testNewAnalyzerIncrementalBrokenNamedTuple] |
| 5133 |
|
| 5134 |
import a |
| 5135 |
[file a.py] |
| 5136 |
from b import NT |
| 5137 |
x: NT |
| 5138 |
[file a.py.2] |
| 5139 |
from b import NT |
| 5140 |
x: NT |
| 5141 |
reveal_type(x) |
| 5142 |
[file b.py] |
| 5143 |
from typing import NamedTuple |
| 5144 |
NT = NamedTuple('BadName', [('x', int)]) |
| 5145 |
[builtins fixtures/tuple.pyi] |
| 5146 |
[out] |
| 5147 |
tmp/b.py:2: error: First argument to namedtuple() should be "NT", not "BadName" |
| 5148 |
[out2] |
| 5149 |
tmp/b.py:2: error: First argument to namedtuple() should be "NT", not "BadName" |
| 5150 |
tmp/a.py:3: note: Revealed type is "tuple[builtins.int, fallback=b.NT]" |
| 5151 |
|
| 5152 |
[case testNewAnalyzerIncrementalBrokenNamedTupleNested] |
| 5153 |
|
| 5154 |
import a |
| 5155 |
[file a.py] |
| 5156 |
from b import C |
| 5157 |
x: C |
| 5158 |
[file a.py.2] |
| 5159 |
from b import C |
| 5160 |
x: C |
| 5161 |
# touch |
| 5162 |
[file b.py] |
| 5163 |
class C: ... |
| 5164 |
from collections import namedtuple |
| 5165 |
def test() -> None: |
| 5166 |
NT = namedtuple('BadName', ['x', 'y']) |
| 5167 |
[builtins fixtures/list.pyi] |
| 5168 |
[out] |
| 5169 |
tmp/b.py:4: error: First argument to namedtuple() should be "NT", not "BadName" |
| 5170 |
[out2] |
| 5171 |
tmp/b.py:4: error: First argument to namedtuple() should be "NT", not "BadName" |
| 5172 |
|
| 5173 |
[case testNewAnalyzerIncrementalMethodNamedTuple] |
| 5174 |
import a |
| 5175 |
[file a.py] |
| 5176 |
from b import C |
| 5177 |
x: C |
| 5178 |
[file a.py.2] |
| 5179 |
from b import C |
| 5180 |
x: C |
| 5181 |
reveal_type(x.h) |
| 5182 |
[file b.py] |
| 5183 |
from typing import NamedTuple |
| 5184 |
class C: |
| 5185 |
def __init__(self) -> None: |
| 5186 |
self.h: Hidden |
| 5187 |
Hidden = NamedTuple('Hidden', [('x', int)]) |
| 5188 |
[builtins fixtures/tuple.pyi] |
| 5189 |
[out] |
| 5190 |
[out2] |
| 5191 |
tmp/a.py:3: note: Revealed type is "tuple[builtins.int, fallback=b.Hidden@5]" |
| 5192 |
|
| 5193 |
[case testIncrementalNodeCreatedFromGetattr] |
| 5194 |
import a |
| 5195 |
[file a.py] |
| 5196 |
from b import C |
| 5197 |
c: C |
| 5198 |
[file b.py] |
| 5199 |
from c import C |
| 5200 |
[file c.pyi] |
| 5201 |
def __getattr__(s): ... |
| 5202 |
[file a.py.2] |
| 5203 |
from b import C |
| 5204 |
c: C |
| 5205 |
reveal_type(c) |
| 5206 |
[out] |
| 5207 |
[out2] |
| 5208 |
tmp/a.py:3: note: Revealed type is "Any" |
| 5209 |
|
| 5210 |
[case testNewAnalyzerIncrementalNestedEnum] |
| 5211 |
|
| 5212 |
import a |
| 5213 |
[file a.py] |
| 5214 |
from b import C |
| 5215 |
x: C |
| 5216 |
[file a.py.2] |
| 5217 |
from b import C |
| 5218 |
x: C |
| 5219 |
# touch |
| 5220 |
[file b.py] |
| 5221 |
class C: ... |
| 5222 |
from enum import Enum |
| 5223 |
|
| 5224 |
def test() -> None: |
| 5225 |
Color = Enum('Color', 'RED BLACK') |
| 5226 |
[builtins fixtures/list.pyi] |
| 5227 |
[out] |
| 5228 |
[out2] |
| 5229 |
|
| 5230 |
[case testCannotDetermineTypeFromOtherModule] |
| 5231 |
|
| 5232 |
import aa |
| 5233 |
|
| 5234 |
[file aa.py] |
| 5235 |
import a |
| 5236 |
|
| 5237 |
[file aa.py.2] |
| 5238 |
import a # dummy |
| 5239 |
|
| 5240 |
[file a.py] |
| 5241 |
from b import Sub |
| 5242 |
|
| 5243 |
Sub().foo |
| 5244 |
Sub().foo |
| 5245 |
|
| 5246 |
[file b.py] |
| 5247 |
from typing import Any |
| 5248 |
|
| 5249 |
class desc: |
| 5250 |
def __get__(self, _: Any, __: Any = None) -> int: |
| 5251 |
return 42 |
| 5252 |
|
| 5253 |
class Base: |
| 5254 |
@property |
| 5255 |
def foo(self) -> int: ... |
| 5256 |
|
| 5257 |
class Sub(Base): |
| 5258 |
foo = desc(42) # type: ignore |
| 5259 |
|
| 5260 |
[builtins fixtures/property.pyi] |
| 5261 |
[out] |
| 5262 |
[out2] |
| 5263 |
|
| 5264 |
[case testRedefinitionClass] |
| 5265 |
import b |
| 5266 |
[file a.py] |
| 5267 |
from whatever import Foo # type: ignore |
| 5268 |
|
| 5269 |
class Foo: # type: ignore |
| 5270 |
def f(self) -> None: |
| 5271 |
pass |
| 5272 |
[file b.py] |
| 5273 |
import a |
| 5274 |
[file b.py.2] |
| 5275 |
import a # a change |
| 5276 |
|
| 5277 |
[case testIsInstanceAdHocIntersectionIncrementalNoChange] |
| 5278 |
import b |
| 5279 |
[file a.py] |
| 5280 |
class A: pass |
| 5281 |
class B: pass |
| 5282 |
|
| 5283 |
class Foo: |
| 5284 |
def __init__(self) -> None: |
| 5285 |
x: A |
| 5286 |
assert isinstance(x, B) |
| 5287 |
self.x = x |
| 5288 |
[file b.py] |
| 5289 |
from a import Foo |
| 5290 |
[file b.py.2] |
| 5291 |
from a import Foo |
| 5292 |
reveal_type(Foo().x) |
| 5293 |
[builtins fixtures/isinstance.pyi] |
| 5294 |
[out] |
| 5295 |
[out2] |
| 5296 |
tmp/b.py:2: note: Revealed type is "a.<subclass of "a.A" and "a.B">" |
| 5297 |
|
| 5298 |
[case testIsInstanceAdHocIntersectionIncrementalNoChangeSameName] |
| 5299 |
import b |
| 5300 |
[file c.py] |
| 5301 |
class B: pass |
| 5302 |
[file a.py] |
| 5303 |
import c |
| 5304 |
class B: pass |
| 5305 |
|
| 5306 |
class Foo: |
| 5307 |
def __init__(self) -> None: |
| 5308 |
x: c.B |
| 5309 |
assert isinstance(x, B) |
| 5310 |
self.x = x |
| 5311 |
[file b.py] |
| 5312 |
from a import Foo |
| 5313 |
[file b.py.2] |
| 5314 |
from a import Foo |
| 5315 |
reveal_type(Foo().x) |
| 5316 |
[builtins fixtures/isinstance.pyi] |
| 5317 |
[out] |
| 5318 |
[out2] |
| 5319 |
tmp/b.py:2: note: Revealed type is "a.<subclass of "c.B" and "a.B">" |
| 5320 |
|
| 5321 |
|
| 5322 |
[case testIsInstanceAdHocIntersectionIncrementalNoChangeTuple] |
| 5323 |
import b |
| 5324 |
[file a.py] |
| 5325 |
from typing import Tuple |
| 5326 |
class B: pass |
| 5327 |
|
| 5328 |
class Foo: |
| 5329 |
def __init__(self) -> None: |
| 5330 |
x: Tuple[int, ...] |
| 5331 |
assert isinstance(x, B) |
| 5332 |
self.x = x |
| 5333 |
[file b.py] |
| 5334 |
from a import Foo |
| 5335 |
[file b.py.2] |
| 5336 |
from a import Foo |
| 5337 |
reveal_type(Foo().x) |
| 5338 |
[builtins fixtures/isinstance.pyi] |
| 5339 |
[out] |
| 5340 |
[out2] |
| 5341 |
tmp/b.py:2: note: Revealed type is "a.<subclass of "tuple[builtins.int, ...]" and "a.B">" |
| 5342 |
|
| 5343 |
[case testIsInstanceAdHocIntersectionIncrementalIsInstanceChange] |
| 5344 |
import c |
| 5345 |
[file a.py] |
| 5346 |
class A: pass |
| 5347 |
class B: pass |
| 5348 |
class C: pass |
| 5349 |
|
| 5350 |
class Foo: |
| 5351 |
def __init__(self) -> None: |
| 5352 |
x: A |
| 5353 |
assert isinstance(x, B) |
| 5354 |
self.x = x |
| 5355 |
[file a.py.2] |
| 5356 |
class A: pass |
| 5357 |
class B: pass |
| 5358 |
class C: pass |
| 5359 |
|
| 5360 |
class Foo: |
| 5361 |
def __init__(self) -> None: |
| 5362 |
x: A |
| 5363 |
assert isinstance(x, C) |
| 5364 |
self.x = x |
| 5365 |
|
| 5366 |
[file b.py] |
| 5367 |
from a import Foo |
| 5368 |
y = Foo().x |
| 5369 |
|
| 5370 |
[file c.py] |
| 5371 |
from b import y |
| 5372 |
reveal_type(y) |
| 5373 |
[builtins fixtures/isinstance.pyi] |
| 5374 |
[out] |
| 5375 |
tmp/c.py:2: note: Revealed type is "a.<subclass of "a.A" and "a.B">" |
| 5376 |
[out2] |
| 5377 |
tmp/c.py:2: note: Revealed type is "a.<subclass of "a.A" and "a.C">" |
| 5378 |
|
| 5379 |
[case testIsInstanceAdHocIntersectionIncrementalUnderlyingObjChang] |
| 5380 |
import c |
| 5381 |
[file a.py] |
| 5382 |
class A: pass |
| 5383 |
class B: pass |
| 5384 |
class C: pass |
| 5385 |
Extra = B |
| 5386 |
[file a.py.2] |
| 5387 |
class A: pass |
| 5388 |
class B: pass |
| 5389 |
class C: pass |
| 5390 |
Extra = C |
| 5391 |
|
| 5392 |
[file b.py] |
| 5393 |
from a import A, Extra |
| 5394 |
x: A |
| 5395 |
if isinstance(x, Extra): |
| 5396 |
y = x |
| 5397 |
|
| 5398 |
[file c.py] |
| 5399 |
from b import y |
| 5400 |
reveal_type(y) |
| 5401 |
[builtins fixtures/isinstance.pyi] |
| 5402 |
[out] |
| 5403 |
tmp/c.py:2: note: Revealed type is "b.<subclass of "a.A" and "a.B">" |
| 5404 |
[out2] |
| 5405 |
tmp/c.py:2: note: Revealed type is "b.<subclass of "a.A" and "a.C">" |
| 5406 |
|
| 5407 |
[case testIsInstanceAdHocIntersectionIncrementalIntersectionToUnreachable] |
| 5408 |
import c |
| 5409 |
[file a.py] |
| 5410 |
class A: |
| 5411 |
x: int |
| 5412 |
class B: |
| 5413 |
x: int |
| 5414 |
x: A |
| 5415 |
assert isinstance(x, B) |
| 5416 |
y = x |
| 5417 |
|
| 5418 |
[file a.py.2] |
| 5419 |
class A: |
| 5420 |
x: int |
| 5421 |
class B: |
| 5422 |
x: str |
| 5423 |
x: A |
| 5424 |
assert isinstance(x, B) |
| 5425 |
y = x |
| 5426 |
|
| 5427 |
[file b.py] |
| 5428 |
from a import y |
| 5429 |
z = y |
| 5430 |
|
| 5431 |
[file c.py] |
| 5432 |
from b import z |
| 5433 |
reveal_type(z) |
| 5434 |
[builtins fixtures/isinstance.pyi] |
| 5435 |
[out] |
| 5436 |
tmp/c.py:2: note: Revealed type is "a.<subclass of "a.A" and "a.B">" |
| 5437 |
[out2] |
| 5438 |
tmp/b.py:2: error: Cannot determine type of "y" |
| 5439 |
tmp/c.py:2: note: Revealed type is "Any" |
| 5440 |
|
| 5441 |
[case testIsInstanceAdHocIntersectionIncrementalUnreachaableToIntersection] |
| 5442 |
import c |
| 5443 |
[file a.py] |
| 5444 |
class A: |
| 5445 |
x: int |
| 5446 |
class B: |
| 5447 |
x: str |
| 5448 |
x: A |
| 5449 |
assert isinstance(x, B) |
| 5450 |
y = x |
| 5451 |
|
| 5452 |
[file a.py.2] |
| 5453 |
class A: |
| 5454 |
x: int |
| 5455 |
class B: |
| 5456 |
x: int |
| 5457 |
x: A |
| 5458 |
assert isinstance(x, B) |
| 5459 |
y = x |
| 5460 |
|
| 5461 |
[file b.py] |
| 5462 |
from a import y |
| 5463 |
z = y |
| 5464 |
|
| 5465 |
[file c.py] |
| 5466 |
from b import z |
| 5467 |
reveal_type(z) |
| 5468 |
[builtins fixtures/isinstance.pyi] |
| 5469 |
[out] |
| 5470 |
tmp/b.py:2: error: Cannot determine type of "y" |
| 5471 |
tmp/c.py:2: note: Revealed type is "Any" |
| 5472 |
[out2] |
| 5473 |
tmp/c.py:2: note: Revealed type is "a.<subclass of "a.A" and "a.B">" |
| 5474 |
|
| 5475 |
[case testIsInstanceAdHocIntersectionIncrementalNestedClass] |
| 5476 |
import b |
| 5477 |
[file a.py] |
| 5478 |
class A: |
| 5479 |
class B: ... |
| 5480 |
class C: ... |
| 5481 |
class D: |
| 5482 |
def __init__(self) -> None: |
| 5483 |
x: A.B |
| 5484 |
assert isinstance(x, A.C) |
| 5485 |
self.x = x |
| 5486 |
[file b.py] |
| 5487 |
from a import A |
| 5488 |
[file b.py.2] |
| 5489 |
from a import A |
| 5490 |
reveal_type(A.D().x) |
| 5491 |
[builtins fixtures/isinstance.pyi] |
| 5492 |
[out] |
| 5493 |
[out2] |
| 5494 |
tmp/b.py:2: note: Revealed type is "a.<subclass of "a.A.B" and "a.A.C">" |
| 5495 |
|
| 5496 |
[case testIsInstanceAdHocIntersectionIncrementalUnions] |
| 5497 |
import c |
| 5498 |
[file a.py] |
| 5499 |
import b |
| 5500 |
class A: |
| 5501 |
p: b.D |
| 5502 |
class B: |
| 5503 |
p: b.D |
| 5504 |
class C: |
| 5505 |
p: b.D |
| 5506 |
c: str |
| 5507 |
x: A |
| 5508 |
assert isinstance(x, (B, C)) |
| 5509 |
y = x |
| 5510 |
[file b.py] |
| 5511 |
class D: |
| 5512 |
p: int |
| 5513 |
[file c.py] |
| 5514 |
from a import y |
| 5515 |
[file c.py.2] |
| 5516 |
from a import y, C |
| 5517 |
reveal_type(y) |
| 5518 |
reveal_type(y.p.p) |
| 5519 |
assert isinstance(y, C) |
| 5520 |
reveal_type(y.c) |
| 5521 |
[builtins fixtures/isinstance.pyi] |
| 5522 |
[out] |
| 5523 |
[out2] |
| 5524 |
tmp/c.py:2: note: Revealed type is "a.<subclass of "a.A" and "a.B"> | a.<subclass of "a.A" and "a.C">" |
| 5525 |
tmp/c.py:3: note: Revealed type is "builtins.int" |
| 5526 |
tmp/c.py:5: note: Revealed type is "builtins.str" |
| 5527 |
|
| 5528 |
[case testStubFixupIssues] |
| 5529 |
import a |
| 5530 |
[file a.py] |
| 5531 |
import p |
| 5532 |
[file a.py.2] |
| 5533 |
import p |
| 5534 |
p.N |
| 5535 |
|
| 5536 |
[file p/__init__.pyi] |
| 5537 |
from p.util import * |
| 5538 |
|
| 5539 |
[file p/util.pyi] |
| 5540 |
from p.params import N |
| 5541 |
class Test: ... |
| 5542 |
x: N |
| 5543 |
|
| 5544 |
[file p/params.pyi] |
| 5545 |
import p.util |
| 5546 |
class N(p.util.Test): |
| 5547 |
... |
| 5548 |
[out2] |
| 5549 |
tmp/a.py:2: error: "object" has no attribute "N" |
| 5550 |
|
| 5551 |
[case testIncrementalIndirectSkipWarnUnused] |
| 5552 |
# flags: --follow-imports=skip --warn-unused-ignores |
| 5553 |
# cmd: mypy -m main a b c1 |
| 5554 |
# cmd2: mypy -m main a b c2 |
| 5555 |
|
| 5556 |
[file main.py] |
| 5557 |
import a |
| 5558 |
a.foo.bar() |
| 5559 |
|
| 5560 |
[file a.py] |
| 5561 |
import b |
| 5562 |
foo = b.Foo() |
| 5563 |
|
| 5564 |
[file b.py] |
| 5565 |
from c1 import C |
| 5566 |
class Foo: |
| 5567 |
def bar(self) -> C: |
| 5568 |
return C() |
| 5569 |
|
| 5570 |
[file c1.py] |
| 5571 |
class C: pass |
| 5572 |
|
| 5573 |
[file b.py.2] |
| 5574 |
from c2 import C |
| 5575 |
class Foo: |
| 5576 |
def bar(self) -> C: |
| 5577 |
return C() |
| 5578 |
|
| 5579 |
[file c2.py] |
| 5580 |
|
| 5581 |
[delete c1.py.2] |
| 5582 |
[file c2.py.2] |
| 5583 |
class C: pass |
| 5584 |
|
| 5585 |
[case testIncrementalNestedNamedTuple] |
| 5586 |
import a |
| 5587 |
|
| 5588 |
[file a.py] |
| 5589 |
import b |
| 5590 |
|
| 5591 |
[file a.py.2] |
| 5592 |
import b # foo |
| 5593 |
|
| 5594 |
[file b.py] |
| 5595 |
from typing import NamedTuple |
| 5596 |
|
| 5597 |
def f() -> None: |
| 5598 |
class NT(NamedTuple): |
| 5599 |
x: int |
| 5600 |
|
| 5601 |
n: NT = NT(x=2) |
| 5602 |
|
| 5603 |
def g() -> None: |
| 5604 |
NT = NamedTuple('NT', [('y', str)]) |
| 5605 |
|
| 5606 |
n: NT = NT(y='x') |
| 5607 |
|
| 5608 |
[builtins fixtures/tuple.pyi] |
| 5609 |
|
| 5610 |
[case testIncrementalNestedTypeAlias] |
| 5611 |
import a |
| 5612 |
|
| 5613 |
[file a.py] |
| 5614 |
import b |
| 5615 |
|
| 5616 |
[file a.py.2] |
| 5617 |
import b |
| 5618 |
reveal_type(b.C().x) |
| 5619 |
reveal_type(b.D().x) |
| 5620 |
|
| 5621 |
[file b.py] |
| 5622 |
from typing import List |
| 5623 |
|
| 5624 |
class C: |
| 5625 |
def __init__(self) -> None: |
| 5626 |
Alias = List[int] |
| 5627 |
self.x = [] # type: Alias |
| 5628 |
|
| 5629 |
class D: |
| 5630 |
def __init__(self) -> None: |
| 5631 |
Alias = List[str] |
| 5632 |
self.x = [] # type: Alias |
| 5633 |
|
| 5634 |
[builtins fixtures/list.pyi] |
| 5635 |
[out2] |
| 5636 |
tmp/a.py:2: note: Revealed type is "builtins.list[builtins.int]" |
| 5637 |
tmp/a.py:3: note: Revealed type is "builtins.list[builtins.str]" |
| 5638 |
|
| 5639 |
[case testIncrementalNamespacePackage1] |
| 5640 |
# flags: --namespace-packages |
| 5641 |
import m |
| 5642 |
[file m.py] |
| 5643 |
from foo.bar import x |
| 5644 |
x + 0 |
| 5645 |
[file foo/bar.py] |
| 5646 |
x = 0 |
| 5647 |
[rechecked] |
| 5648 |
[stale] |
| 5649 |
|
| 5650 |
[case testIncrementalNamespacePackage2] |
| 5651 |
# flags: --namespace-packages |
| 5652 |
import m |
| 5653 |
[file m.py] |
| 5654 |
from foo import bar |
| 5655 |
bar.x + 0 |
| 5656 |
[file foo/bar.py] |
| 5657 |
x = 0 |
| 5658 |
[rechecked] |
| 5659 |
[stale] |
| 5660 |
|
| 5661 |
[case testExplicitReexportImportCycleWildcard] |
| 5662 |
# flags: --no-implicit-reexport |
| 5663 |
import pkg.a |
| 5664 |
[file pkg/__init__.pyi] |
| 5665 |
|
| 5666 |
[file pkg/a.pyi] |
| 5667 |
MYPY = False |
| 5668 |
if MYPY: |
| 5669 |
from pkg.b import B |
| 5670 |
|
| 5671 |
[file pkg/b.pyi] |
| 5672 |
import pkg.a |
| 5673 |
MYPY = False |
| 5674 |
if MYPY: |
| 5675 |
from pkg.c import C |
| 5676 |
class B: |
| 5677 |
pass |
| 5678 |
|
| 5679 |
[file pkg/c.pyi] |
| 5680 |
from pkg.a import * |
| 5681 |
class C: |
| 5682 |
pass |
| 5683 |
[rechecked] |
| 5684 |
[stale] |
| 5685 |
|
| 5686 |
|
| 5687 |
[case testEnumAreStillFinalAfterCache] |
| 5688 |
import a |
| 5689 |
class Ok(a.RegularEnum): |
| 5690 |
x = 1 |
| 5691 |
class NotOk(a.FinalEnum): |
| 5692 |
x = 1 |
| 5693 |
[file a.py] |
| 5694 |
from enum import Enum |
| 5695 |
class RegularEnum(Enum): |
| 5696 |
x: int |
| 5697 |
class FinalEnum(Enum): |
| 5698 |
x = 1 |
| 5699 |
[builtins fixtures/isinstance.pyi] |
| 5700 |
[out] |
| 5701 |
main:3: error: Cannot override writable attribute "x" with a final one |
| 5702 |
main:3: error: Incompatible types in assignment (expression has type "Ok", base class "RegularEnum" defined the type as "int") |
| 5703 |
main:4: error: Cannot extend enum with existing members: "FinalEnum" |
| 5704 |
main:5: error: Cannot override final attribute "x" (previously declared in base class "FinalEnum") |
| 5705 |
[out2] |
| 5706 |
main:3: error: Cannot override writable attribute "x" with a final one |
| 5707 |
main:3: error: Incompatible types in assignment (expression has type "Ok", base class "RegularEnum" defined the type as "int") |
| 5708 |
main:4: error: Cannot extend enum with existing members: "FinalEnum" |
| 5709 |
main:5: error: Cannot override final attribute "x" (previously declared in base class "FinalEnum") |
| 5710 |
|
| 5711 |
[case testSlotsSerialization] |
| 5712 |
import a |
| 5713 |
[file a.py] |
| 5714 |
from b import C |
| 5715 |
|
| 5716 |
class D(C): |
| 5717 |
pass |
| 5718 |
[file b.py] |
| 5719 |
class C: |
| 5720 |
__slots__ = ('x',) |
| 5721 |
[file a.py.2] |
| 5722 |
from b import C |
| 5723 |
|
| 5724 |
class D(C): |
| 5725 |
__slots__ = ('y',) |
| 5726 |
|
| 5727 |
def __init__(self) -> None: |
| 5728 |
self.x = 1 |
| 5729 |
self.y = 2 |
| 5730 |
self.z = 3 |
| 5731 |
[builtins fixtures/tuple.pyi] |
| 5732 |
[out] |
| 5733 |
[out2] |
| 5734 |
tmp/a.py:9: error: Trying to assign name "z" that is not in "__slots__" of type "a.D" |
| 5735 |
|
| 5736 |
[case testMethodAliasIncremental] |
| 5737 |
import b |
| 5738 |
[file a.py] |
| 5739 |
class A: |
| 5740 |
def f(self) -> None: pass |
| 5741 |
g = f |
| 5742 |
|
| 5743 |
[file b.py] |
| 5744 |
from a import A |
| 5745 |
A().g() |
| 5746 |
[file b.py.2] |
| 5747 |
# trivial change |
| 5748 |
from a import A |
| 5749 |
A().g() |
| 5750 |
[out] |
| 5751 |
[out2] |
| 5752 |
|
| 5753 |
[case testIncrementalWithDifferentKindsOfNestedTypesWithinMethod] |
| 5754 |
|
| 5755 |
import a |
| 5756 |
|
| 5757 |
[file a.py] |
| 5758 |
import b |
| 5759 |
|
| 5760 |
[file a.py.2] |
| 5761 |
import b |
| 5762 |
b.xyz |
| 5763 |
|
| 5764 |
[file b.py] |
| 5765 |
from typing import NamedTuple, NewType, TypedDict |
| 5766 |
from typing_extensions import TypeAlias |
| 5767 |
from enum import Enum |
| 5768 |
from dataclasses import dataclass |
| 5769 |
|
| 5770 |
class C: |
| 5771 |
def f(self) -> None: |
| 5772 |
class C: |
| 5773 |
c: int |
| 5774 |
class NT1(NamedTuple): |
| 5775 |
c: int |
| 5776 |
NT2 = NamedTuple("NT2", [("c", int)]) |
| 5777 |
class NT3(NT1): |
| 5778 |
pass |
| 5779 |
class TD(TypedDict): |
| 5780 |
c: int |
| 5781 |
TD2 = TypedDict("TD2", {"c": int}) |
| 5782 |
class E(Enum): |
| 5783 |
X = 1 |
| 5784 |
@dataclass |
| 5785 |
class DC: |
| 5786 |
c: int |
| 5787 |
Alias: TypeAlias = NT1 |
| 5788 |
N = NewType("N", NT1) |
| 5789 |
|
| 5790 |
c: C = C() |
| 5791 |
nt1: NT1 = NT1(c=1) |
| 5792 |
nt2: NT2 = NT2(c=1) |
| 5793 |
nt3: NT3 = NT3(c=1) |
| 5794 |
td: TD = TD(c=1) |
| 5795 |
td2: TD2 = TD2(c=1) |
| 5796 |
e: E = E.X |
| 5797 |
dc: DC = DC(c=1) |
| 5798 |
al: Alias = Alias(c=1) |
| 5799 |
n: N = N(NT1(c=1)) |
| 5800 |
|
| 5801 |
[builtins fixtures/dict.pyi] |
| 5802 |
[typing fixtures/typing-typeddict.pyi] |
| 5803 |
[out2] |
| 5804 |
tmp/a.py:2: error: "object" has no attribute "xyz" |
| 5805 |
|
| 5806 |
[case testIncrementalInvalidNamedTupleInUnannotatedFunction] |
| 5807 |
# flags: --disable-error-code=annotation-unchecked |
| 5808 |
import a |
| 5809 |
|
| 5810 |
[file a.py] |
| 5811 |
import b |
| 5812 |
|
| 5813 |
[file a.py.2] |
| 5814 |
import b # f |
| 5815 |
|
| 5816 |
[file b.py] |
| 5817 |
from typing import NamedTuple |
| 5818 |
|
| 5819 |
def toplevel(fields): |
| 5820 |
TupleType = NamedTuple("TupleType", fields) |
| 5821 |
class InheritFromTuple(TupleType): |
| 5822 |
pass |
| 5823 |
NT2 = NamedTuple("bad", [('x', int)]) |
| 5824 |
nt2: NT2 = NT2(x=1) |
| 5825 |
|
| 5826 |
class C: |
| 5827 |
def method(self, fields): |
| 5828 |
TupleType = NamedTuple("TupleType", fields) |
| 5829 |
class InheritFromTuple(TupleType): |
| 5830 |
pass |
| 5831 |
NT2 = NamedTuple("bad", [('x', int)]) |
| 5832 |
nt2: NT2 = NT2(x=1) |
| 5833 |
|
| 5834 |
[builtins fixtures/tuple.pyi] |
| 5835 |
|
| 5836 |
[case testNamedTupleUpdateNonRecursiveToRecursiveCoarse] |
| 5837 |
import c |
| 5838 |
[file a.py] |
| 5839 |
from b import M |
| 5840 |
from typing import NamedTuple, Optional |
| 5841 |
class N(NamedTuple): |
| 5842 |
r: Optional[M] |
| 5843 |
x: int |
| 5844 |
n: N |
| 5845 |
[file b.py] |
| 5846 |
from a import N |
| 5847 |
from typing import NamedTuple |
| 5848 |
class M(NamedTuple): |
| 5849 |
r: None |
| 5850 |
x: int |
| 5851 |
[file b.py.2] |
| 5852 |
from a import N |
| 5853 |
from typing import NamedTuple, Optional |
| 5854 |
class M(NamedTuple): |
| 5855 |
r: Optional[N] |
| 5856 |
x: int |
| 5857 |
[file c.py] |
| 5858 |
import a |
| 5859 |
def f(x: a.N) -> None: |
| 5860 |
if x.r is not None: |
| 5861 |
s: int = x.r.x |
| 5862 |
[file c.py.3] |
| 5863 |
import a |
| 5864 |
def f(x: a.N) -> None: |
| 5865 |
if x.r is not None and x.r.r is not None and x.r.r.r is not None: |
| 5866 |
reveal_type(x) |
| 5867 |
s: int = x.r.r.r.r |
| 5868 |
f(a.n) |
| 5869 |
reveal_type(a.n) |
| 5870 |
[builtins fixtures/tuple.pyi] |
| 5871 |
[out] |
| 5872 |
[out2] |
| 5873 |
[out3] |
| 5874 |
tmp/c.py:4: note: Revealed type is "tuple[tuple[... | None, builtins.int, fallback=b.M] | None, builtins.int, fallback=a.N]" |
| 5875 |
tmp/c.py:5: error: Incompatible types in assignment (expression has type "N | None", variable has type "int") |
| 5876 |
tmp/c.py:7: note: Revealed type is "tuple[tuple[... | None, builtins.int, fallback=b.M] | None, builtins.int, fallback=a.N]" |
| 5877 |
|
| 5878 |
[case testTupleTypeUpdateNonRecursiveToRecursiveCoarse] |
| 5879 |
import c |
| 5880 |
[file a.py] |
| 5881 |
from b import M |
| 5882 |
from typing import Tuple, Optional |
| 5883 |
class N(Tuple[Optional[M], int]): ... |
| 5884 |
[file b.py] |
| 5885 |
from a import N |
| 5886 |
from typing import Tuple |
| 5887 |
class M(Tuple[None, int]): ... |
| 5888 |
[file b.py.2] |
| 5889 |
from a import N |
| 5890 |
from typing import Tuple, Optional |
| 5891 |
class M(Tuple[Optional[N], int]): ... |
| 5892 |
[file c.py] |
| 5893 |
import a |
| 5894 |
def f(x: a.N) -> None: |
| 5895 |
if x[0] is not None: |
| 5896 |
s: int = x[0][1] |
| 5897 |
[file c.py.3] |
| 5898 |
import a |
| 5899 |
def f(x: a.N) -> None: |
| 5900 |
if x[0] is not None and x[0][0] is not None and x[0][0][0] is not None: |
| 5901 |
reveal_type(x) |
| 5902 |
s: int = x[0][0][0][0] |
| 5903 |
[builtins fixtures/tuple.pyi] |
| 5904 |
[out] |
| 5905 |
[out2] |
| 5906 |
[out3] |
| 5907 |
tmp/c.py:4: note: Revealed type is "tuple[tuple[... | None, builtins.int, fallback=b.M] | None, builtins.int, fallback=a.N]" |
| 5908 |
tmp/c.py:5: error: Incompatible types in assignment (expression has type "N | None", variable has type "int") |
| 5909 |
|
| 5910 |
[case testTypeAliasUpdateNonRecursiveToRecursiveCoarse] |
| 5911 |
import c |
| 5912 |
[file a.py] |
| 5913 |
from b import M |
| 5914 |
from typing import Tuple, Optional |
| 5915 |
N = Tuple[Optional[M], int] |
| 5916 |
[file b.py] |
| 5917 |
from a import N |
| 5918 |
from typing import Tuple |
| 5919 |
M = Tuple[None, int] |
| 5920 |
[file b.py.2] |
| 5921 |
from a import N |
| 5922 |
from typing import Tuple, Optional |
| 5923 |
M = Tuple[Optional[N], int] |
| 5924 |
[file c.py] |
| 5925 |
import a |
| 5926 |
def f(x: a.N) -> None: |
| 5927 |
if x[0] is not None: |
| 5928 |
s: int = x[0][1] |
| 5929 |
[file c.py.3] |
| 5930 |
import a |
| 5931 |
def f(x: a.N) -> None: |
| 5932 |
if x[0] is not None and x[0][0] is not None and x[0][0][0] is not None: |
| 5933 |
reveal_type(x) |
| 5934 |
s: int = x[0][0][0][0] |
| 5935 |
[builtins fixtures/tuple.pyi] |
| 5936 |
[out] |
| 5937 |
[out2] |
| 5938 |
[out3] |
| 5939 |
tmp/c.py:4: note: Revealed type is "tuple[tuple[... | None, builtins.int] | None, builtins.int]" |
| 5940 |
tmp/c.py:5: error: Incompatible types in assignment (expression has type "N | None", variable has type "int") |
| 5941 |
|
| 5942 |
[case testTypedDictUpdateNonRecursiveToRecursiveCoarse] |
| 5943 |
import c |
| 5944 |
[file a.py] |
| 5945 |
from b import M |
| 5946 |
from typing import TypedDict, Optional |
| 5947 |
class N(TypedDict): |
| 5948 |
r: Optional[M] |
| 5949 |
x: int |
| 5950 |
n: N |
| 5951 |
[file b.py] |
| 5952 |
from a import N |
| 5953 |
from typing import TypedDict |
| 5954 |
class M(TypedDict): |
| 5955 |
r: None |
| 5956 |
x: int |
| 5957 |
[file b.py.2] |
| 5958 |
from a import N |
| 5959 |
from typing import TypedDict, Optional |
| 5960 |
class M(TypedDict): |
| 5961 |
r: Optional[N] |
| 5962 |
x: int |
| 5963 |
[file c.py] |
| 5964 |
import a |
| 5965 |
def f(x: a.N) -> None: |
| 5966 |
if x["r"] is not None: |
| 5967 |
s: int = x["r"]["x"] |
| 5968 |
[file c.py.3] |
| 5969 |
import a |
| 5970 |
def f(x: a.N) -> None: |
| 5971 |
if x["r"] is not None and x["r"]["r"] is not None and x["r"]["r"]["r"] is not None: |
| 5972 |
reveal_type(x) |
| 5973 |
s: int = x["r"]["r"]["r"]["r"] |
| 5974 |
f(a.n) |
| 5975 |
reveal_type(a.n) |
| 5976 |
[builtins fixtures/dict.pyi] |
| 5977 |
[typing fixtures/typing-typeddict.pyi] |
| 5978 |
[out] |
| 5979 |
[out2] |
| 5980 |
[out3] |
| 5981 |
tmp/c.py:4: note: Revealed type is "TypedDict('a.N', {'r': TypedDict('b.M', {'r': ... | None, 'x': builtins.int}) | None, 'x': builtins.int})" |
| 5982 |
tmp/c.py:5: error: Incompatible types in assignment (expression has type "N | None", variable has type "int") |
| 5983 |
tmp/c.py:7: note: Revealed type is "TypedDict('a.N', {'r': TypedDict('b.M', {'r': ... | None, 'x': builtins.int}) | None, 'x': builtins.int})" |
| 5984 |
|
| 5985 |
[case testIncrementalAddClassMethodPlugin] |
| 5986 |
# flags: --config-file tmp/mypy.ini |
| 5987 |
import b |
| 5988 |
|
| 5989 |
[file mypy.ini] |
| 5990 |
\[mypy] |
| 5991 |
plugins=<ROOT>/test-data/unit/plugins/add_classmethod.py |
| 5992 |
|
| 5993 |
[file a.py] |
| 5994 |
class BaseAddMethod: pass |
| 5995 |
|
| 5996 |
class MyClass(BaseAddMethod): |
| 5997 |
pass |
| 5998 |
|
| 5999 |
[file b.py] |
| 6000 |
import a |
| 6001 |
|
| 6002 |
[file b.py.2] |
| 6003 |
import a |
| 6004 |
|
| 6005 |
my_class = a.MyClass() |
| 6006 |
reveal_type(a.MyClass.foo_classmethod) |
| 6007 |
reveal_type(a.MyClass.foo_staticmethod) |
| 6008 |
reveal_type(my_class.foo_classmethod) |
| 6009 |
reveal_type(my_class.foo_staticmethod) |
| 6010 |
|
| 6011 |
[rechecked b] |
| 6012 |
[out2] |
| 6013 |
tmp/b.py:4: note: Revealed type is "def ()" |
| 6014 |
tmp/b.py:5: note: Revealed type is "def (builtins.int) -> builtins.str" |
| 6015 |
tmp/b.py:6: note: Revealed type is "def ()" |
| 6016 |
tmp/b.py:7: note: Revealed type is "def (builtins.int) -> builtins.str" |
| 6017 |
|
| 6018 |
[case testIncrementalAddOverloadedMethodPlugin] |
| 6019 |
# flags: --config-file tmp/mypy.ini |
| 6020 |
import b |
| 6021 |
|
| 6022 |
[file mypy.ini] |
| 6023 |
\[mypy] |
| 6024 |
plugins=<ROOT>/test-data/unit/plugins/add_overloaded_method.py |
| 6025 |
|
| 6026 |
[file a.py] |
| 6027 |
class AddOverloadedMethod: pass |
| 6028 |
|
| 6029 |
class MyClass(AddOverloadedMethod): |
| 6030 |
pass |
| 6031 |
|
| 6032 |
[file b.py] |
| 6033 |
import a |
| 6034 |
|
| 6035 |
[file b.py.2] |
| 6036 |
import a |
| 6037 |
|
| 6038 |
reveal_type(a.MyClass.method) |
| 6039 |
reveal_type(a.MyClass.clsmethod) |
| 6040 |
reveal_type(a.MyClass.stmethod) |
| 6041 |
|
| 6042 |
my_class = a.MyClass() |
| 6043 |
reveal_type(my_class.method) |
| 6044 |
reveal_type(my_class.clsmethod) |
| 6045 |
reveal_type(my_class.stmethod) |
| 6046 |
[rechecked b] |
| 6047 |
[out2] |
| 6048 |
tmp/b.py:3: note: Revealed type is "Overload(def (self: a.MyClass, arg: builtins.int) -> builtins.str, def (self: a.MyClass, arg: builtins.str) -> builtins.int)" |
| 6049 |
tmp/b.py:4: note: Revealed type is "Overload(def (arg: builtins.int) -> builtins.str, def (arg: builtins.str) -> builtins.int)" |
| 6050 |
tmp/b.py:5: note: Revealed type is "Overload(def (arg: builtins.int) -> builtins.str, def (arg: builtins.str) -> builtins.int)" |
| 6051 |
tmp/b.py:8: note: Revealed type is "Overload(def (arg: builtins.int) -> builtins.str, def (arg: builtins.str) -> builtins.int)" |
| 6052 |
tmp/b.py:9: note: Revealed type is "Overload(def (arg: builtins.int) -> builtins.str, def (arg: builtins.str) -> builtins.int)" |
| 6053 |
tmp/b.py:10: note: Revealed type is "Overload(def (arg: builtins.int) -> builtins.str, def (arg: builtins.str) -> builtins.int)" |
| 6054 |
|
| 6055 |
[case testGenericNamedTupleSerialization] |
| 6056 |
import b |
| 6057 |
[file a.py] |
| 6058 |
from typing import NamedTuple, Generic, TypeVar |
| 6059 |
|
| 6060 |
T = TypeVar("T") |
| 6061 |
class NT(NamedTuple, Generic[T]): |
| 6062 |
key: int |
| 6063 |
value: T |
| 6064 |
|
| 6065 |
[file b.py] |
| 6066 |
from a import NT |
| 6067 |
nt = NT(key=0, value="yes") |
| 6068 |
s: str = nt.value |
| 6069 |
[file b.py.2] |
| 6070 |
from a import NT |
| 6071 |
nt = NT(key=0, value=42) |
| 6072 |
s: str = nt.value |
| 6073 |
[builtins fixtures/tuple.pyi] |
| 6074 |
[out] |
| 6075 |
[out2] |
| 6076 |
tmp/b.py:3: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 6077 |
|
| 6078 |
[case testGenericTypedDictSerialization] |
| 6079 |
import b |
| 6080 |
[file a.py] |
| 6081 |
from typing import TypedDict, Generic, TypeVar |
| 6082 |
|
| 6083 |
T = TypeVar("T") |
| 6084 |
class TD(TypedDict, Generic[T]): |
| 6085 |
key: int |
| 6086 |
value: T |
| 6087 |
|
| 6088 |
[file b.py] |
| 6089 |
from a import TD |
| 6090 |
td = TD(key=0, value="yes") |
| 6091 |
s: str = td["value"] |
| 6092 |
[file b.py.2] |
| 6093 |
from a import TD |
| 6094 |
td = TD(key=0, value=42) |
| 6095 |
s: str = td["value"] |
| 6096 |
[builtins fixtures/dict.pyi] |
| 6097 |
[typing fixtures/typing-typeddict.pyi] |
| 6098 |
[out] |
| 6099 |
[out2] |
| 6100 |
tmp/b.py:3: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 6101 |
|
| 6102 |
[case testUnpackKwargsSerialize] |
| 6103 |
import m |
| 6104 |
[file lib.py] |
| 6105 |
from typing import TypedDict |
| 6106 |
from typing_extensions import Unpack |
| 6107 |
|
| 6108 |
class Person(TypedDict): |
| 6109 |
name: str |
| 6110 |
age: int |
| 6111 |
|
| 6112 |
def foo(**kwargs: Unpack[Person]): |
| 6113 |
... |
| 6114 |
|
| 6115 |
[file m.py] |
| 6116 |
from lib import foo |
| 6117 |
foo(name='Jennifer', age=38) |
| 6118 |
[file m.py.2] |
| 6119 |
from lib import foo |
| 6120 |
foo(name='Jennifer', age="38") |
| 6121 |
[builtins fixtures/dict.pyi] |
| 6122 |
[typing fixtures/typing-typeddict.pyi] |
| 6123 |
[out] |
| 6124 |
[out2] |
| 6125 |
tmp/m.py:2: error: Argument "age" to "foo" has incompatible type "str"; expected "int" |
| 6126 |
|
| 6127 |
[case testDisableEnableErrorCodesIncremental] |
| 6128 |
# flags: --disable-error-code truthy-bool |
| 6129 |
# flags2: --enable-error-code truthy-bool |
| 6130 |
class Foo: |
| 6131 |
pass |
| 6132 |
|
| 6133 |
foo = Foo() |
| 6134 |
if foo: |
| 6135 |
... |
| 6136 |
[out] |
| 6137 |
[out2] |
| 6138 |
main:7: error: "__main__.foo" has type "Foo" which does not implement __bool__ or __len__ so it could always be true in boolean context |
| 6139 |
|
| 6140 |
[case testModuleAsProtocolImplementationSerialize] |
| 6141 |
import m |
| 6142 |
[file m.py] |
| 6143 |
from typing import Protocol |
| 6144 |
from lib import C |
| 6145 |
|
| 6146 |
class Options(Protocol): |
| 6147 |
timeout: int |
| 6148 |
def update(self) -> bool: ... |
| 6149 |
|
| 6150 |
def setup(options: Options) -> None: ... |
| 6151 |
setup(C().config) |
| 6152 |
|
| 6153 |
[file lib.py] |
| 6154 |
import default_config |
| 6155 |
|
| 6156 |
class C: |
| 6157 |
config = default_config |
| 6158 |
|
| 6159 |
[file default_config.py] |
| 6160 |
timeout = 100 |
| 6161 |
def update() -> bool: ... |
| 6162 |
|
| 6163 |
[file default_config.py.2] |
| 6164 |
timeout = 100 |
| 6165 |
def update() -> str: ... |
| 6166 |
[builtins fixtures/module.pyi] |
| 6167 |
[out] |
| 6168 |
[out2] |
| 6169 |
tmp/m.py:9: error: Argument 1 to "setup" has incompatible type Module; expected "Options" |
| 6170 |
tmp/m.py:9: note: Following member(s) of Module "default_config" have conflicts: |
| 6171 |
tmp/m.py:9: note: Expected: |
| 6172 |
tmp/m.py:9: note: def update() -> bool |
| 6173 |
tmp/m.py:9: note: Got: |
| 6174 |
tmp/m.py:9: note: def update() -> str |
| 6175 |
|
| 6176 |
[case testAbstractBodyTurnsEmptyCoarse] |
| 6177 |
from b import Base |
| 6178 |
|
| 6179 |
class Sub(Base): |
| 6180 |
def meth(self) -> int: |
| 6181 |
return super().meth() |
| 6182 |
|
| 6183 |
[file b.py] |
| 6184 |
from abc import abstractmethod |
| 6185 |
class Base: |
| 6186 |
@abstractmethod |
| 6187 |
def meth(self) -> int: return 0 |
| 6188 |
|
| 6189 |
[file b.py.2] |
| 6190 |
from abc import abstractmethod |
| 6191 |
class Base: |
| 6192 |
@abstractmethod |
| 6193 |
def meth(self) -> int: ... |
| 6194 |
[out] |
| 6195 |
[out2] |
| 6196 |
main:5: error: Call to abstract method "meth" of "Base" with trivial body via super() is unsafe |
| 6197 |
|
| 6198 |
[case testLiteralCoarseGrainedChainedAliases] |
| 6199 |
from mod1 import Alias1 |
| 6200 |
from typing import Literal |
| 6201 |
x: Alias1 |
| 6202 |
def expect_int(x: int) -> None: pass |
| 6203 |
expect_int(x) |
| 6204 |
[file mod1.py] |
| 6205 |
from mod2 import Alias2 |
| 6206 |
Alias1 = Alias2 |
| 6207 |
[file mod2.py] |
| 6208 |
from mod3 import Alias3 |
| 6209 |
Alias2 = Alias3 |
| 6210 |
[file mod3.py] |
| 6211 |
from typing import Literal |
| 6212 |
Alias3 = int |
| 6213 |
[file mod3.py.2] |
| 6214 |
from typing import Literal |
| 6215 |
Alias3 = str |
| 6216 |
[builtins fixtures/tuple.pyi] |
| 6217 |
[out] |
| 6218 |
[out2] |
| 6219 |
main:5: error: Argument 1 to "expect_int" has incompatible type "str"; expected "int" |
| 6220 |
|
| 6221 |
[case testLiteralCoarseGrainedChainedAliases2] |
| 6222 |
from mod1 import Alias1 |
| 6223 |
from typing import Literal |
| 6224 |
x: Alias1 |
| 6225 |
def expect_3(x: Literal[3]) -> None: pass |
| 6226 |
expect_3(x) |
| 6227 |
[file mod1.py] |
| 6228 |
from mod2 import Alias2 |
| 6229 |
Alias1 = Alias2 |
| 6230 |
[file mod2.py] |
| 6231 |
from mod3 import Alias3 |
| 6232 |
Alias2 = Alias3 |
| 6233 |
[file mod3.py] |
| 6234 |
from typing import Literal |
| 6235 |
Alias3 = Literal[3] |
| 6236 |
[file mod3.py.2] |
| 6237 |
from typing import Literal |
| 6238 |
Alias3 = Literal[4] |
| 6239 |
[builtins fixtures/tuple.pyi] |
| 6240 |
[out] |
| 6241 |
[out2] |
| 6242 |
main:5: error: Argument 1 to "expect_3" has incompatible type "Literal[4]"; expected "Literal[3]" |
| 6243 |
|
| 6244 |
[case testDoubleReexportFunctionUpdated] |
| 6245 |
import m |
| 6246 |
|
| 6247 |
[file m.py] |
| 6248 |
import f |
| 6249 |
[file m.py.3] |
| 6250 |
import f |
| 6251 |
reveal_type(f.foo) |
| 6252 |
|
| 6253 |
[file f.py] |
| 6254 |
import c |
| 6255 |
def foo(arg: c.C) -> None: pass |
| 6256 |
|
| 6257 |
[file c.py] |
| 6258 |
from types import C |
| 6259 |
|
| 6260 |
[file types.py] |
| 6261 |
import pb1 |
| 6262 |
C = pb1.C |
| 6263 |
[file types.py.2] |
| 6264 |
import pb1, pb2 |
| 6265 |
C = pb2.C |
| 6266 |
|
| 6267 |
[file pb1.py] |
| 6268 |
class C: ... |
| 6269 |
[file pb2.py] |
| 6270 |
class C: ... |
| 6271 |
[out] |
| 6272 |
[out2] |
| 6273 |
[out3] |
| 6274 |
tmp/m.py:2: note: Revealed type is "def (arg: pb2.C)" |
| 6275 |
|
| 6276 |
[case testDoubleReexportGenericUpdated] |
| 6277 |
import m |
| 6278 |
|
| 6279 |
[file m.py] |
| 6280 |
import f |
| 6281 |
[file m.py.3] |
| 6282 |
import f |
| 6283 |
x: f.F |
| 6284 |
reveal_type(x[0]) |
| 6285 |
|
| 6286 |
[file f.py] |
| 6287 |
import c |
| 6288 |
class FB(list[c.C]): ... |
| 6289 |
class F(FB): ... |
| 6290 |
|
| 6291 |
[file c.py] |
| 6292 |
from types import C |
| 6293 |
|
| 6294 |
[file types.py] |
| 6295 |
import pb1 |
| 6296 |
C = pb1.C |
| 6297 |
[file types.py.2] |
| 6298 |
import pb1, pb2 |
| 6299 |
C = pb2.C |
| 6300 |
|
| 6301 |
[file pb1.py] |
| 6302 |
class C: ... |
| 6303 |
[file pb2.py] |
| 6304 |
class C: ... |
| 6305 |
[out] |
| 6306 |
[out2] |
| 6307 |
[out3] |
| 6308 |
tmp/m.py:3: note: Revealed type is "pb2.C" |
| 6309 |
|
| 6310 |
[case testNoCrashDoubleReexportFunctionEmpty] |
| 6311 |
import m |
| 6312 |
|
| 6313 |
[file m.py] |
| 6314 |
import f |
| 6315 |
[file m.py.3] |
| 6316 |
import f |
| 6317 |
# modify |
| 6318 |
|
| 6319 |
[file f.py] |
| 6320 |
import c |
| 6321 |
def foo(arg: c.C) -> None: pass |
| 6322 |
|
| 6323 |
[file c.py] |
| 6324 |
from types import C |
| 6325 |
|
| 6326 |
[file types.py] |
| 6327 |
import pb1 |
| 6328 |
C = pb1.C |
| 6329 |
[file types.py.2] |
| 6330 |
import pb1, pb2 |
| 6331 |
C = pb2.C |
| 6332 |
|
| 6333 |
[file pb1.py] |
| 6334 |
class C: ... |
| 6335 |
[file pb2.py.2] |
| 6336 |
class C: ... |
| 6337 |
[file pb1.py.2] |
| 6338 |
[out] |
| 6339 |
[out2] |
| 6340 |
[out3] |
| 6341 |
|
| 6342 |
[case testNoCrashDoubleReexportAliasEmpty] |
| 6343 |
import m |
| 6344 |
|
| 6345 |
[file m.py] |
| 6346 |
import f |
| 6347 |
[file m.py.3] |
| 6348 |
import f |
| 6349 |
# modify |
| 6350 |
|
| 6351 |
[file f.py] |
| 6352 |
import c |
| 6353 |
D = list[c.C] |
| 6354 |
|
| 6355 |
[file c.py] |
| 6356 |
from types import C |
| 6357 |
|
| 6358 |
[file types.py] |
| 6359 |
import pb1 |
| 6360 |
C = pb1.C |
| 6361 |
[file types.py.2] |
| 6362 |
import pb2 |
| 6363 |
C = pb2.C |
| 6364 |
|
| 6365 |
[file pb1.py] |
| 6366 |
class C: ... |
| 6367 |
[file pb2.py.2] |
| 6368 |
class C: ... |
| 6369 |
[file pb1.py.2] |
| 6370 |
[out] |
| 6371 |
[out2] |
| 6372 |
[out3] |
| 6373 |
|
| 6374 |
[case testNoCrashDoubleReexportBaseEmpty] |
| 6375 |
import m |
| 6376 |
|
| 6377 |
[file m.py] |
| 6378 |
import f |
| 6379 |
[file m.py.3] |
| 6380 |
import f |
| 6381 |
# modify |
| 6382 |
|
| 6383 |
[file f.py] |
| 6384 |
import c |
| 6385 |
class D(c.C): pass |
| 6386 |
|
| 6387 |
[file c.py] |
| 6388 |
from types import C |
| 6389 |
|
| 6390 |
[file types.py] |
| 6391 |
import pb1 |
| 6392 |
C = pb1.C |
| 6393 |
[file types.py.2] |
| 6394 |
import pb1, pb2 |
| 6395 |
C = pb2.C |
| 6396 |
|
| 6397 |
[file pb1.py] |
| 6398 |
class C: ... |
| 6399 |
[file pb2.py.2] |
| 6400 |
class C: ... |
| 6401 |
[file pb1.py.2] |
| 6402 |
[out] |
| 6403 |
[out2] |
| 6404 |
[out3] |
| 6405 |
|
| 6406 |
[case testNoCrashDoubleReexportBaseEmpty2] |
| 6407 |
import m |
| 6408 |
|
| 6409 |
[file m.py] |
| 6410 |
import f |
| 6411 |
[file m.py.3] |
| 6412 |
import f |
| 6413 |
# modify |
| 6414 |
|
| 6415 |
[file f.py] |
| 6416 |
import c |
| 6417 |
class D(c.C): pass |
| 6418 |
|
| 6419 |
[file c.py] |
| 6420 |
from types import C |
| 6421 |
|
| 6422 |
[file types.py] |
| 6423 |
import pb1 |
| 6424 |
C = pb1.C |
| 6425 |
[file types.py.2] |
| 6426 |
import pb2 |
| 6427 |
C = pb2.C |
| 6428 |
|
| 6429 |
[file pb1.py] |
| 6430 |
class C: ... |
| 6431 |
[file pb2.py.2] |
| 6432 |
class C: ... |
| 6433 |
[file pb1.py.2] |
| 6434 |
[out] |
| 6435 |
[out2] |
| 6436 |
[out3] |
| 6437 |
|
| 6438 |
[case testDoubleReexportMetaUpdated] |
| 6439 |
import m |
| 6440 |
class C(metaclass=m.M): ... |
| 6441 |
|
| 6442 |
[file m.py] |
| 6443 |
from types import M |
| 6444 |
|
| 6445 |
[file types.py] |
| 6446 |
class M(type): ... |
| 6447 |
[file types.py.2] |
| 6448 |
class M: ... |
| 6449 |
[out] |
| 6450 |
[out2] |
| 6451 |
main:2: error: Metaclasses not inheriting from "type" are not supported |
| 6452 |
|
| 6453 |
[case testIncrementalOkChangeWithSave2] |
| 6454 |
import mod1 |
| 6455 |
x: int = mod1.x |
| 6456 |
|
| 6457 |
[file mod1.py] |
| 6458 |
from mod2 import x |
| 6459 |
|
| 6460 |
[file mod2.py] |
| 6461 |
x = 1 |
| 6462 |
|
| 6463 |
[file mod2.py.2] |
| 6464 |
x = "no way" |
| 6465 |
[out] |
| 6466 |
[out2] |
| 6467 |
main:2: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 6468 |
|
| 6469 |
[case testNoCrashDoubleReexportMetaEmpty] |
| 6470 |
import m |
| 6471 |
|
| 6472 |
[file m.py] |
| 6473 |
import f |
| 6474 |
[file m.py.3] |
| 6475 |
import f |
| 6476 |
# modify |
| 6477 |
|
| 6478 |
[file f.py] |
| 6479 |
import c |
| 6480 |
class D(metaclass=c.C): pass |
| 6481 |
|
| 6482 |
[file c.py] |
| 6483 |
from types import C |
| 6484 |
|
| 6485 |
[file types.py] |
| 6486 |
import pb1 |
| 6487 |
C = pb1.C |
| 6488 |
[file types.py.2] |
| 6489 |
import pb1, pb2 |
| 6490 |
C = pb2.C |
| 6491 |
|
| 6492 |
[file pb1.py] |
| 6493 |
class C(type): ... |
| 6494 |
[file pb2.py.2] |
| 6495 |
class C(type): ... |
| 6496 |
[file pb1.py.2] |
| 6497 |
[out] |
| 6498 |
[out2] |
| 6499 |
[out3] |
| 6500 |
|
| 6501 |
[case testNoCrashDoubleReexportMetaEmpty2] |
| 6502 |
import m |
| 6503 |
|
| 6504 |
[file m.py] |
| 6505 |
import f |
| 6506 |
[file m.py.3] |
| 6507 |
import f |
| 6508 |
# modify |
| 6509 |
|
| 6510 |
[file f.py] |
| 6511 |
import c |
| 6512 |
class D(metaclass=c.C): pass |
| 6513 |
|
| 6514 |
[file c.py] |
| 6515 |
from types import C |
| 6516 |
|
| 6517 |
[file types.py] |
| 6518 |
import pb1 |
| 6519 |
C = pb1.C |
| 6520 |
[file types.py.2] |
| 6521 |
import pb2 |
| 6522 |
C = pb2.C |
| 6523 |
|
| 6524 |
[file pb1.py] |
| 6525 |
class C(type): ... |
| 6526 |
[file pb2.py.2] |
| 6527 |
class C(type): ... |
| 6528 |
[file pb1.py.2] |
| 6529 |
[out] |
| 6530 |
[out2] |
| 6531 |
[out3] |
| 6532 |
|
| 6533 |
[case testNoCrashDoubleReexportTypedDictEmpty] |
| 6534 |
import m |
| 6535 |
|
| 6536 |
[file m.py] |
| 6537 |
import f |
| 6538 |
[file m.py.3] |
| 6539 |
import f |
| 6540 |
# modify |
| 6541 |
|
| 6542 |
[file f.py] |
| 6543 |
from typing import TypedDict |
| 6544 |
import c |
| 6545 |
class D(TypedDict): |
| 6546 |
x: c.C |
| 6547 |
|
| 6548 |
[file c.py] |
| 6549 |
from types import C |
| 6550 |
|
| 6551 |
[file types.py] |
| 6552 |
import pb1 |
| 6553 |
C = pb1.C |
| 6554 |
[file types.py.2] |
| 6555 |
import pb1, pb2 |
| 6556 |
C = pb2.C |
| 6557 |
|
| 6558 |
[file pb1.py] |
| 6559 |
class C: ... |
| 6560 |
[file pb2.py.2] |
| 6561 |
class C: ... |
| 6562 |
[file pb1.py.2] |
| 6563 |
[builtins fixtures/dict.pyi] |
| 6564 |
[typing fixtures/typing-typeddict.pyi] |
| 6565 |
[out] |
| 6566 |
[out2] |
| 6567 |
[out3] |
| 6568 |
|
| 6569 |
[case testNoCrashDoubleReexportTupleEmpty] |
| 6570 |
import m |
| 6571 |
|
| 6572 |
[file m.py] |
| 6573 |
import f |
| 6574 |
[file m.py.3] |
| 6575 |
import f |
| 6576 |
# modify |
| 6577 |
|
| 6578 |
[file f.py] |
| 6579 |
from typing import Tuple |
| 6580 |
import c |
| 6581 |
class D(Tuple[c.C, int]): pass |
| 6582 |
|
| 6583 |
[file c.py] |
| 6584 |
from types import C |
| 6585 |
|
| 6586 |
[file types.py] |
| 6587 |
import pb1 |
| 6588 |
C = pb1.C |
| 6589 |
[file types.py.2] |
| 6590 |
import pb1, pb2 |
| 6591 |
C = pb2.C |
| 6592 |
|
| 6593 |
[file pb1.py] |
| 6594 |
class C: ... |
| 6595 |
[file pb2.py.2] |
| 6596 |
class C: ... |
| 6597 |
[file pb1.py.2] |
| 6598 |
[builtins fixtures/tuple.pyi] |
| 6599 |
[out] |
| 6600 |
[out2] |
| 6601 |
[out3] |
| 6602 |
|
| 6603 |
[case testNoCrashDoubleReexportOverloadEmpty] |
| 6604 |
import m |
| 6605 |
|
| 6606 |
[file m.py] |
| 6607 |
import f |
| 6608 |
[file m.py.3] |
| 6609 |
import f |
| 6610 |
# modify |
| 6611 |
|
| 6612 |
[file f.py] |
| 6613 |
from typing import Any, overload |
| 6614 |
import c |
| 6615 |
|
| 6616 |
@overload |
| 6617 |
def foo(arg: int) -> None: ... |
| 6618 |
@overload |
| 6619 |
def foo(arg: c.C) -> None: ... |
| 6620 |
def foo(arg: Any) -> None: |
| 6621 |
pass |
| 6622 |
|
| 6623 |
[file c.py] |
| 6624 |
from types import C |
| 6625 |
|
| 6626 |
[file types.py] |
| 6627 |
import pb1 |
| 6628 |
C = pb1.C |
| 6629 |
[file types.py.2] |
| 6630 |
import pb1, pb2 |
| 6631 |
C = pb2.C |
| 6632 |
|
| 6633 |
[file pb1.py] |
| 6634 |
class C: ... |
| 6635 |
[file pb2.py.2] |
| 6636 |
class C: ... |
| 6637 |
[file pb1.py.2] |
| 6638 |
[out] |
| 6639 |
[out2] |
| 6640 |
[out3] |
| 6641 |
|
| 6642 |
[case testNoCrashOnPartialLambdaInference] |
| 6643 |
# flags: --no-local-partial-types |
| 6644 |
import m |
| 6645 |
[file m.py] |
| 6646 |
from typing import TypeVar, Callable |
| 6647 |
|
| 6648 |
V = TypeVar("V") |
| 6649 |
def apply(val: V, func: Callable[[V], None]) -> None: |
| 6650 |
return func(val) |
| 6651 |
|
| 6652 |
xs = [] |
| 6653 |
apply(0, lambda a: xs.append(a)) |
| 6654 |
[file m.py.2] |
| 6655 |
from typing import TypeVar, Callable |
| 6656 |
|
| 6657 |
V = TypeVar("V") |
| 6658 |
def apply(val: V, func: Callable[[V], None]) -> None: |
| 6659 |
return func(val) |
| 6660 |
|
| 6661 |
xs = [] |
| 6662 |
apply(0, lambda a: xs.append(a)) |
| 6663 |
reveal_type(xs) |
| 6664 |
[builtins fixtures/list.pyi] |
| 6665 |
[out] |
| 6666 |
[out2] |
| 6667 |
tmp/m.py:9: note: Revealed type is "builtins.list[builtins.int]" |
| 6668 |
|
| 6669 |
[case testTypingSelfCoarse] |
| 6670 |
import m |
| 6671 |
[file lib.py] |
| 6672 |
from typing import Self |
| 6673 |
|
| 6674 |
class C: |
| 6675 |
def meth(self, other: Self) -> Self: ... |
| 6676 |
|
| 6677 |
[file m.py] |
| 6678 |
import lib |
| 6679 |
class D: ... |
| 6680 |
[file m.py.2] |
| 6681 |
import lib |
| 6682 |
class D(lib.C): ... |
| 6683 |
|
| 6684 |
reveal_type(D.meth) |
| 6685 |
reveal_type(D().meth) |
| 6686 |
[out] |
| 6687 |
[out2] |
| 6688 |
tmp/m.py:4: note: Revealed type is "def [Self <: lib.C] (self: Self`1, other: Self`1) -> Self`1" |
| 6689 |
tmp/m.py:5: note: Revealed type is "def (other: m.D) -> m.D" |
| 6690 |
|
| 6691 |
[case testIncrementalNestedGenericCallableCrash] |
| 6692 |
from typing import TypeVar, Callable |
| 6693 |
|
| 6694 |
T = TypeVar("T") |
| 6695 |
|
| 6696 |
class B: |
| 6697 |
def foo(self) -> Callable[[T], T]: ... |
| 6698 |
|
| 6699 |
class C(B): |
| 6700 |
def __init__(self) -> None: |
| 6701 |
self.x = self.foo() |
| 6702 |
[out] |
| 6703 |
[out2] |
| 6704 |
|
| 6705 |
[case testNoCrashIncrementalMetaAny] |
| 6706 |
import a |
| 6707 |
[file a.py] |
| 6708 |
from m import Foo |
| 6709 |
[file a.py.2] |
| 6710 |
from m import Foo |
| 6711 |
# touch |
| 6712 |
[file m.py] |
| 6713 |
from missing_module import Meta # type: ignore[import] |
| 6714 |
class Foo(metaclass=Meta): ... |
| 6715 |
|
| 6716 |
[case testIncrementalNativeInt] |
| 6717 |
import a |
| 6718 |
[file a.py] |
| 6719 |
from mypy_extensions import i64 |
| 6720 |
x: i64 = 0 |
| 6721 |
[file a.py.2] |
| 6722 |
from mypy_extensions import i64 |
| 6723 |
x: i64 = 0 |
| 6724 |
y: int = x |
| 6725 |
[builtins fixtures/tuple.pyi] |
| 6726 |
[out] |
| 6727 |
[out2] |
| 6728 |
|
| 6729 |
[case testGenericTypedDictWithError] |
| 6730 |
import b |
| 6731 |
[file a.py] |
| 6732 |
from typing import Generic, TypeVar, TypedDict |
| 6733 |
|
| 6734 |
TValue = TypeVar("TValue") |
| 6735 |
class Dict(TypedDict, Generic[TValue]): |
| 6736 |
value: TValue |
| 6737 |
|
| 6738 |
[file b.py] |
| 6739 |
from a import Dict, TValue |
| 6740 |
|
| 6741 |
def f(d: Dict[TValue]) -> TValue: |
| 6742 |
return d["value"] |
| 6743 |
def g(d: Dict[TValue]) -> TValue: |
| 6744 |
return d["x"] |
| 6745 |
|
| 6746 |
[file b.py.2] |
| 6747 |
from a import Dict, TValue |
| 6748 |
|
| 6749 |
def f(d: Dict[TValue]) -> TValue: |
| 6750 |
return d["value"] |
| 6751 |
def g(d: Dict[TValue]) -> TValue: |
| 6752 |
return d["y"] |
| 6753 |
[builtins fixtures/dict.pyi] |
| 6754 |
[typing fixtures/typing-typeddict.pyi] |
| 6755 |
[out] |
| 6756 |
tmp/b.py:6: error: TypedDict "a.Dict[TValue]" has no key "x" |
| 6757 |
[out2] |
| 6758 |
tmp/b.py:6: error: TypedDict "a.Dict[TValue]" has no key "y" |
| 6759 |
|
| 6760 |
[case testParamSpecNoCrash] |
| 6761 |
import m |
| 6762 |
[file m.py] |
| 6763 |
from typing import Callable, TypeVar |
| 6764 |
from lib import C |
| 6765 |
|
| 6766 |
T = TypeVar("T") |
| 6767 |
def test(x: Callable[..., T]) -> T: ... |
| 6768 |
test(C) # type: ignore |
| 6769 |
|
| 6770 |
[file m.py.2] |
| 6771 |
from typing import Callable, TypeVar |
| 6772 |
from lib import C |
| 6773 |
|
| 6774 |
T = TypeVar("T") |
| 6775 |
def test(x: Callable[..., T]) -> T: ... |
| 6776 |
test(C) # type: ignore |
| 6777 |
# touch |
| 6778 |
[file lib.py] |
| 6779 |
from typing import ParamSpec, Generic, Callable |
| 6780 |
|
| 6781 |
P = ParamSpec("P") |
| 6782 |
class C(Generic[P]): |
| 6783 |
def __init__(self, fn: Callable[P, int]) -> None: ... |
| 6784 |
[builtins fixtures/dict.pyi] |
| 6785 |
|
| 6786 |
[case testVariadicClassIncrementalUpdateRegularToVariadic] |
| 6787 |
from typing import Any |
| 6788 |
from lib import C |
| 6789 |
|
| 6790 |
x: C[int, str] |
| 6791 |
|
| 6792 |
[file lib.py] |
| 6793 |
from typing import Generic, TypeVar |
| 6794 |
|
| 6795 |
T = TypeVar("T") |
| 6796 |
S = TypeVar("S") |
| 6797 |
class C(Generic[T, S]): ... |
| 6798 |
|
| 6799 |
[file lib.py.2] |
| 6800 |
from typing import Generic |
| 6801 |
from typing_extensions import TypeVarTuple, Unpack |
| 6802 |
|
| 6803 |
Ts = TypeVarTuple("Ts") |
| 6804 |
class C(Generic[Unpack[Ts]]): ... |
| 6805 |
[builtins fixtures/tuple.pyi] |
| 6806 |
|
| 6807 |
[case testVariadicClassIncrementalUpdateVariadicToRegular] |
| 6808 |
from typing import Any |
| 6809 |
from lib import C |
| 6810 |
|
| 6811 |
x: C[int, str, int] |
| 6812 |
|
| 6813 |
[file lib.py] |
| 6814 |
from typing import Generic |
| 6815 |
from typing_extensions import TypeVarTuple, Unpack |
| 6816 |
|
| 6817 |
Ts = TypeVarTuple("Ts") |
| 6818 |
class C(Generic[Unpack[Ts]]): ... |
| 6819 |
[file lib.py.2] |
| 6820 |
from typing import Generic, TypeVar |
| 6821 |
|
| 6822 |
T = TypeVar("T") |
| 6823 |
S = TypeVar("S") |
| 6824 |
class C(Generic[T, S]): ... |
| 6825 |
[builtins fixtures/tuple.pyi] |
| 6826 |
[out2] |
| 6827 |
main:4: error: "C" expects 2 type arguments, but 3 given |
| 6828 |
|
| 6829 |
[case testVariadicTupleIncrementalUpdateNoCrash] |
| 6830 |
import m |
| 6831 |
[file m.py] |
| 6832 |
from typing import Any |
| 6833 |
from lib import C |
| 6834 |
|
| 6835 |
x: C[Any] |
| 6836 |
[file m.py.2] |
| 6837 |
from lib import C |
| 6838 |
|
| 6839 |
x: C[int] |
| 6840 |
[file lib.py] |
| 6841 |
from typing import Generic, Tuple, TypeVar |
| 6842 |
from typing_extensions import TypeVarTuple, Unpack |
| 6843 |
|
| 6844 |
Ts = TypeVarTuple("Ts") |
| 6845 |
class C(Tuple[Unpack[Ts]]): ... |
| 6846 |
[builtins fixtures/tuple.pyi] |
| 6847 |
|
| 6848 |
[case testNoIncrementalCrashOnInvalidTypedDict] |
| 6849 |
import m |
| 6850 |
[file m.py] |
| 6851 |
import counts |
| 6852 |
[file m.py.2] |
| 6853 |
import counts |
| 6854 |
# touch |
| 6855 |
[file counts.py] |
| 6856 |
from typing import TypedDict |
| 6857 |
Counts = TypedDict("Counts", {k: int for k in "abc"}) # type: ignore |
| 6858 |
[builtins fixtures/dict.pyi] |
| 6859 |
[typing fixtures/typing-typeddict.pyi] |
| 6860 |
|
| 6861 |
[case testNoIncrementalCrashOnInvalidTypedDictFunc] |
| 6862 |
import m |
| 6863 |
[file m.py] |
| 6864 |
import counts |
| 6865 |
[file m.py.2] |
| 6866 |
import counts |
| 6867 |
# touch |
| 6868 |
[file counts.py] |
| 6869 |
from typing import TypedDict |
| 6870 |
def test() -> None: |
| 6871 |
Counts = TypedDict("Counts", {k: int for k in "abc"}) # type: ignore |
| 6872 |
[builtins fixtures/dict.pyi] |
| 6873 |
[typing fixtures/typing-typeddict.pyi] |
| 6874 |
|
| 6875 |
[case testNoIncrementalCrashOnTypedDictMethod] |
| 6876 |
import a |
| 6877 |
[file a.py] |
| 6878 |
from b import C |
| 6879 |
x: C |
| 6880 |
[file a.py.2] |
| 6881 |
from b import C |
| 6882 |
x: C |
| 6883 |
reveal_type(x.h) |
| 6884 |
[file b.py] |
| 6885 |
from typing import TypedDict |
| 6886 |
class C: |
| 6887 |
def __init__(self) -> None: |
| 6888 |
self.h: Hidden |
| 6889 |
class Hidden(TypedDict): |
| 6890 |
x: int |
| 6891 |
[builtins fixtures/dict.pyi] |
| 6892 |
[typing fixtures/typing-typeddict.pyi] |
| 6893 |
[out] |
| 6894 |
[out2] |
| 6895 |
tmp/a.py:3: note: Revealed type is "TypedDict('b.Hidden@5', {'x': builtins.int})" |
| 6896 |
|
| 6897 |
[case testNoIncrementalCrashOnInvalidEnumMethod] |
| 6898 |
import a |
| 6899 |
[file a.py] |
| 6900 |
from lib import TheClass |
| 6901 |
[file a.py.2] |
| 6902 |
from lib import TheClass |
| 6903 |
x: TheClass |
| 6904 |
reveal_type(x.enum_type) |
| 6905 |
[file lib.py] |
| 6906 |
import enum |
| 6907 |
|
| 6908 |
class TheClass: |
| 6909 |
def __init__(self) -> None: |
| 6910 |
names = ["foo"] |
| 6911 |
pyenum = enum.Enum('Blah', { # type: ignore[misc] |
| 6912 |
x.upper(): x |
| 6913 |
for x in names |
| 6914 |
}) |
| 6915 |
self.enum_type = pyenum |
| 6916 |
[builtins fixtures/tuple.pyi] |
| 6917 |
[out] |
| 6918 |
[out2] |
| 6919 |
tmp/a.py:3: note: Revealed type is "def (value: builtins.object) -> lib.pyenum@6" |
| 6920 |
|
| 6921 |
-- Note: do not use _no_parallel unless really needed! |
| 6922 |
[case testIncrementalFunctoolsPartial_no_parallel] |
| 6923 |
import a |
| 6924 |
|
| 6925 |
[file a.py] |
| 6926 |
from typing import Callable |
| 6927 |
from partial import p1, p2 |
| 6928 |
|
| 6929 |
p1(1, "a", 3) # OK |
| 6930 |
p1(1, "a", c=3) # OK |
| 6931 |
p1(1, b="a", c=3) # OK |
| 6932 |
|
| 6933 |
reveal_type(p1) |
| 6934 |
|
| 6935 |
def takes_callable_int(f: Callable[..., int]) -> None: ... |
| 6936 |
def takes_callable_str(f: Callable[..., str]) -> None: ... |
| 6937 |
takes_callable_int(p1) |
| 6938 |
takes_callable_str(p1) |
| 6939 |
|
| 6940 |
p2("a") # OK |
| 6941 |
p2("a", 3) # OK |
| 6942 |
p2("a", c=3) # OK |
| 6943 |
p2(1, 3) |
| 6944 |
p2(1, "a", 3) |
| 6945 |
p2(a=1, b="a", c=3) |
| 6946 |
|
| 6947 |
[file a.py.2] |
| 6948 |
from typing import Callable |
| 6949 |
from partial import p3 |
| 6950 |
|
| 6951 |
p3(1) # OK |
| 6952 |
p3(1, c=3) # OK |
| 6953 |
p3(a=1) # OK |
| 6954 |
p3(1, b="a", c=3) # OK, keywords can be clobbered |
| 6955 |
p3(1, 3) |
| 6956 |
|
| 6957 |
[file partial.py] |
| 6958 |
from typing import Callable |
| 6959 |
import functools |
| 6960 |
|
| 6961 |
def foo(a: int, b: str, c: int = 5) -> int: ... |
| 6962 |
|
| 6963 |
p1 = functools.partial(foo) |
| 6964 |
p2 = functools.partial(foo, 1) |
| 6965 |
p3 = functools.partial(foo, b="a") |
| 6966 |
[builtins fixtures/dict.pyi] |
| 6967 |
[out] |
| 6968 |
tmp/a.py:8: note: Revealed type is "functools.partial[builtins.int]" |
| 6969 |
tmp/a.py:13: error: Argument 1 to "takes_callable_str" has incompatible type "partial[int]"; expected "Callable[..., str]" |
| 6970 |
tmp/a.py:13: note: "partial[int].__call__" has type "def __call__(__self, *args: Any, **kwargs: Any) -> int" |
| 6971 |
tmp/a.py:18: error: Argument 1 to "foo" has incompatible type "int"; expected "str" |
| 6972 |
tmp/a.py:19: error: Too many arguments for "foo" |
| 6973 |
tmp/a.py:19: error: Argument 1 to "foo" has incompatible type "int"; expected "str" |
| 6974 |
tmp/a.py:19: error: Argument 2 to "foo" has incompatible type "str"; expected "int" |
| 6975 |
tmp/a.py:20: error: Unexpected keyword argument "a" for "foo" |
| 6976 |
tmp/a.py:20: note: "foo" defined in "partial" |
| 6977 |
[out2] |
| 6978 |
tmp/a.py:8: error: Too many positional arguments for "foo" |
| 6979 |
tmp/a.py:8: error: Argument 2 to "foo" has incompatible type "int"; expected "str" |
| 6980 |
|
| 6981 |
[case testStartUsingTypeGuard] |
| 6982 |
import a |
| 6983 |
[file a.py] |
| 6984 |
from lib import guard |
| 6985 |
from typing import Union |
| 6986 |
from typing_extensions import assert_type |
| 6987 |
x: Union[int, str] |
| 6988 |
|
| 6989 |
[file a.py.2] |
| 6990 |
from lib import guard |
| 6991 |
from typing import Union |
| 6992 |
from typing_extensions import assert_type |
| 6993 |
x: Union[int, str] |
| 6994 |
if guard(x): |
| 6995 |
assert_type(x, int) |
| 6996 |
else: |
| 6997 |
assert_type(x, Union[int, str]) |
| 6998 |
[file lib.py] |
| 6999 |
from typing_extensions import TypeGuard |
| 7000 |
def guard(x: object) -> TypeGuard[int]: |
| 7001 |
pass |
| 7002 |
[builtins fixtures/tuple.pyi] |
| 7003 |
|
| 7004 |
[case testStartUsingTypeIs] |
| 7005 |
import a |
| 7006 |
[file a.py] |
| 7007 |
from lib import guard |
| 7008 |
from typing import Union |
| 7009 |
from typing_extensions import assert_type |
| 7010 |
x: Union[int, str] |
| 7011 |
|
| 7012 |
[file a.py.2] |
| 7013 |
from lib import guard |
| 7014 |
from typing import Union |
| 7015 |
from typing_extensions import assert_type |
| 7016 |
x: Union[int, str] |
| 7017 |
if guard(x): |
| 7018 |
assert_type(x, int) |
| 7019 |
else: |
| 7020 |
assert_type(x, str) |
| 7021 |
[file lib.py] |
| 7022 |
from typing_extensions import TypeIs |
| 7023 |
def guard(x: object) -> TypeIs[int]: |
| 7024 |
pass |
| 7025 |
[builtins fixtures/tuple.pyi] |
| 7026 |
|
| 7027 |
[case testTypeGuardToTypeIs] |
| 7028 |
import a |
| 7029 |
[file a.py] |
| 7030 |
from lib import guard |
| 7031 |
from typing import Union |
| 7032 |
from typing_extensions import assert_type |
| 7033 |
x: Union[int, str] |
| 7034 |
if guard(x): |
| 7035 |
assert_type(x, int) |
| 7036 |
else: |
| 7037 |
assert_type(x, Union[int, str]) |
| 7038 |
[file a.py.2] |
| 7039 |
from lib import guard |
| 7040 |
from typing import Union |
| 7041 |
from typing_extensions import assert_type |
| 7042 |
x: Union[int, str] |
| 7043 |
if guard(x): |
| 7044 |
assert_type(x, int) |
| 7045 |
else: |
| 7046 |
assert_type(x, str) |
| 7047 |
[file lib.py] |
| 7048 |
from typing_extensions import TypeGuard |
| 7049 |
def guard(x: object) -> TypeGuard[int]: |
| 7050 |
pass |
| 7051 |
[file lib.py.2] |
| 7052 |
from typing_extensions import TypeIs |
| 7053 |
def guard(x: object) -> TypeIs[int]: |
| 7054 |
pass |
| 7055 |
[builtins fixtures/tuple.pyi] |
| 7056 |
|
| 7057 |
[case testStartUsingPEP604Union] |
| 7058 |
import a |
| 7059 |
[file a.py] |
| 7060 |
import lib |
| 7061 |
|
| 7062 |
[file a.py.2] |
| 7063 |
from lib import IntOrStr |
| 7064 |
assert isinstance(1, IntOrStr) |
| 7065 |
|
| 7066 |
[file lib.py] |
| 7067 |
from typing_extensions import TypeAlias |
| 7068 |
|
| 7069 |
IntOrStr: TypeAlias = int | str |
| 7070 |
assert isinstance(1, IntOrStr) |
| 7071 |
[builtins fixtures/type.pyi] |
| 7072 |
|
| 7073 |
[case testPropertySetterTypeIncremental] |
| 7074 |
import b |
| 7075 |
[file a.py] |
| 7076 |
class A: |
| 7077 |
@property |
| 7078 |
def f(self) -> int: |
| 7079 |
return 1 |
| 7080 |
@f.setter |
| 7081 |
def f(self, x: str) -> None: |
| 7082 |
pass |
| 7083 |
[file b.py] |
| 7084 |
from a import A |
| 7085 |
[file b.py.2] |
| 7086 |
from a import A |
| 7087 |
a = A() |
| 7088 |
a.f = '' # OK |
| 7089 |
reveal_type(a.f) |
| 7090 |
a.f = 1 |
| 7091 |
reveal_type(a.f) |
| 7092 |
[builtins fixtures/property.pyi] |
| 7093 |
[out] |
| 7094 |
[out2] |
| 7095 |
tmp/b.py:4: note: Revealed type is "builtins.int" |
| 7096 |
tmp/b.py:5: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 7097 |
tmp/b.py:6: note: Revealed type is "builtins.int" |
| 7098 |
|
| 7099 |
[case testSerializeDeferredGenericNamedTuple] |
| 7100 |
import pkg |
| 7101 |
[file pkg/__init__.py] |
| 7102 |
from .lib import NT |
| 7103 |
[file pkg/lib.py] |
| 7104 |
from typing import Generic, NamedTuple, TypeVar |
| 7105 |
from pkg import does_not_exist # type: ignore |
| 7106 |
from pkg.missing import also_missing # type: ignore |
| 7107 |
|
| 7108 |
T = TypeVar("T", bound=does_not_exist) |
| 7109 |
class NT(NamedTuple, Generic[T]): |
| 7110 |
values: also_missing[T] |
| 7111 |
[file pkg/__init__.py.2] |
| 7112 |
# touch |
| 7113 |
from .lib import NT |
| 7114 |
[builtins fixtures/tuple.pyi] |
| 7115 |
[out] |
| 7116 |
[out2] |
| 7117 |
|
| 7118 |
[case testNewRedefineAffectsCache] |
| 7119 |
# flags: --local-partial-types --allow-redefinition |
| 7120 |
# flags2: --local-partial-types |
| 7121 |
# flags3: --local-partial-types --allow-redefinition |
| 7122 |
x = 0 |
| 7123 |
if int(): |
| 7124 |
x = "" |
| 7125 |
[out] |
| 7126 |
[out2] |
| 7127 |
main:6: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 7128 |
|
| 7129 |
[case testUntypedCallsExcludeAffectsCache] |
| 7130 |
# flags: --disallow-untyped-calls --untyped-calls-exclude=mod.Super |
| 7131 |
# flags2: --disallow-untyped-calls --untyped-calls-exclude=mod |
| 7132 |
# flags3: --disallow-untyped-calls --untyped-calls-exclude=mod.Super |
| 7133 |
import mod |
| 7134 |
[file mod.py] |
| 7135 |
class Super: |
| 7136 |
def draw(self): |
| 7137 |
... |
| 7138 |
class Class(Super): |
| 7139 |
... |
| 7140 |
Class().draw() |
| 7141 |
[out] |
| 7142 |
tmp/mod.py:6: error: Call to untyped function "draw" in typed context |
| 7143 |
[out2] |
| 7144 |
[out3] |
| 7145 |
tmp/mod.py:6: error: Call to untyped function "draw" in typed context |
| 7146 |
|
| 7147 |
[case testMethodMakeBoundIncremental] |
| 7148 |
from a import A |
| 7149 |
a = A() |
| 7150 |
a.f() |
| 7151 |
[file a.py] |
| 7152 |
class B: |
| 7153 |
def f(self, s: A) -> int: ... |
| 7154 |
|
| 7155 |
def f(s: A) -> int: ... |
| 7156 |
|
| 7157 |
class A: |
| 7158 |
f = f |
| 7159 |
[file a.py.2] |
| 7160 |
class B: |
| 7161 |
def f(self, s: A) -> int: ... |
| 7162 |
|
| 7163 |
def f(s: A) -> int: ... |
| 7164 |
|
| 7165 |
class A: |
| 7166 |
f = B().f |
| 7167 |
[out] |
| 7168 |
[out2] |
| 7169 |
main:3: error: Too few arguments |
| 7170 |
|
| 7171 |
[case testUnreachableAfterToplevelAssertImportThirdParty] |
| 7172 |
# flags: --platform unknown |
| 7173 |
import sys |
| 7174 |
assert sys.platform == 'linux' |
| 7175 |
import does_not_exist |
| 7176 |
[builtins fixtures/ops.pyi] |
| 7177 |
[out] |
| 7178 |
[out2] |
| 7179 |
|
| 7180 |
[case testIncrementalNoCrashOnParamSpecPrefixUpdateMethod] |
| 7181 |
import impl |
| 7182 |
[file impl.py] |
| 7183 |
from typing_extensions import ParamSpec |
| 7184 |
from lib import Sub |
| 7185 |
|
| 7186 |
P = ParamSpec("P") |
| 7187 |
class Impl(Sub[P]): |
| 7188 |
def test(self, *args: P.args, **kwargs: P.kwargs) -> None: |
| 7189 |
self.meth(1, *args, **kwargs) |
| 7190 |
|
| 7191 |
[file impl.py.2] |
| 7192 |
from typing_extensions import ParamSpec |
| 7193 |
from lib import Sub |
| 7194 |
|
| 7195 |
P = ParamSpec("P") |
| 7196 |
class Impl(Sub[P]): |
| 7197 |
def test(self, *args: P.args, **kwargs: P.kwargs) -> None: |
| 7198 |
self.meth("no", *args, **kwargs) |
| 7199 |
|
| 7200 |
[file lib.py] |
| 7201 |
from typing import Generic |
| 7202 |
from typing_extensions import ParamSpec, Concatenate |
| 7203 |
|
| 7204 |
P = ParamSpec("P") |
| 7205 |
class Base(Generic[P]): |
| 7206 |
def meth(self, *args: P.args, **kwargs: P.kwargs) -> None: ... |
| 7207 |
class Sub(Base[Concatenate[int, P]]): ... |
| 7208 |
[builtins fixtures/paramspec.pyi] |
| 7209 |
[out] |
| 7210 |
[out2] |
| 7211 |
tmp/impl.py:7: error: Argument 1 to "meth" of "Base" has incompatible type "str"; expected "int" |
| 7212 |
|
| 7213 |
[case testIncrementalNoCrashOnParamSpecPrefixUpdateMethodAlias] |
| 7214 |
import impl |
| 7215 |
[file impl.py] |
| 7216 |
from typing_extensions import ParamSpec |
| 7217 |
from lib import Sub |
| 7218 |
|
| 7219 |
P = ParamSpec("P") |
| 7220 |
class Impl(Sub[P]): |
| 7221 |
def test(self, *args: P.args, **kwargs: P.kwargs) -> None: |
| 7222 |
self.alias(1, *args, **kwargs) |
| 7223 |
|
| 7224 |
[file impl.py.2] |
| 7225 |
from typing_extensions import ParamSpec |
| 7226 |
from lib import Sub |
| 7227 |
|
| 7228 |
P = ParamSpec("P") |
| 7229 |
class Impl(Sub[P]): |
| 7230 |
def test(self, *args: P.args, **kwargs: P.kwargs) -> None: |
| 7231 |
self.alias("no", *args, **kwargs) |
| 7232 |
|
| 7233 |
[file lib.py] |
| 7234 |
from typing import Generic |
| 7235 |
from typing_extensions import ParamSpec, Concatenate |
| 7236 |
|
| 7237 |
P = ParamSpec("P") |
| 7238 |
class Base(Generic[P]): |
| 7239 |
def meth(self, *args: P.args, **kwargs: P.kwargs) -> None: ... |
| 7240 |
alias = meth |
| 7241 |
class Sub(Base[Concatenate[int, P]]): ... |
| 7242 |
[builtins fixtures/paramspec.pyi] |
| 7243 |
[out] |
| 7244 |
[out2] |
| 7245 |
tmp/impl.py:7: error: Argument 1 has incompatible type "str"; expected "int" |
| 7246 |
|
| 7247 |
[case testIncrementalDifferentSourcesFreshnessCorrect] |
| 7248 |
# cmd: mypy -m foo bar |
| 7249 |
# cmd2: mypy -m foo |
| 7250 |
# cmd3: mypy -m foo bar |
| 7251 |
[file foo.py] |
| 7252 |
foo = 5 |
| 7253 |
[file foo.py.2] |
| 7254 |
foo = "foo" |
| 7255 |
[file bar.py] |
| 7256 |
from foo import foo |
| 7257 |
bar: int = foo |
| 7258 |
[out] |
| 7259 |
[out2] |
| 7260 |
[out3] |
| 7261 |
tmp/bar.py:2: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 7262 |
|
| 7263 |
[case testIncrementalBlockingErrorRepeatAndUndo_no_native_parse] |
| 7264 |
import m |
| 7265 |
[file m.py] |
| 7266 |
import f |
| 7267 |
reveal_type(f.x) |
| 7268 |
[file m.py.3] |
| 7269 |
import f |
| 7270 |
reveal_type(f.x) |
| 7271 |
# touch |
| 7272 |
[file f.py] |
| 7273 |
x = 1 |
| 7274 |
[file f.py.2] |
| 7275 |
no way |
| 7276 |
[file f.py.4] |
| 7277 |
x = 1 |
| 7278 |
[out] |
| 7279 |
tmp/m.py:2: note: Revealed type is "builtins.int" |
| 7280 |
[out2] |
| 7281 |
tmp/f.py:1: error: Invalid syntax |
| 7282 |
[out3] |
| 7283 |
tmp/f.py:1: error: Invalid syntax |
| 7284 |
[out4] |
| 7285 |
tmp/m.py:2: note: Revealed type is "builtins.int" |
| 7286 |
|
| 7287 |
[case testIncrementalSameErrorOrder] |
| 7288 |
import m |
| 7289 |
[file m.py] |
| 7290 |
import n |
| 7291 |
def accept_int(x: int) -> None: pass |
| 7292 |
accept_int(n.foo) |
| 7293 |
[file n.py] |
| 7294 |
import other |
| 7295 |
foo = "hello" |
| 7296 |
reveal_type(foo) |
| 7297 |
[file other.py] |
| 7298 |
[file other.py.2] |
| 7299 |
# touch |
| 7300 |
[rechecked other] |
| 7301 |
[stale] |
| 7302 |
[out] |
| 7303 |
tmp/n.py:3: note: Revealed type is "builtins.str" |
| 7304 |
tmp/m.py:3: error: Argument 1 to "accept_int" has incompatible type "str"; expected "int" |
| 7305 |
[out2] |
| 7306 |
tmp/n.py:3: note: Revealed type is "builtins.str" |
| 7307 |
tmp/m.py:3: error: Argument 1 to "accept_int" has incompatible type "str"; expected "int" |
| 7308 |
|
| 7309 |
[case testIncrementalNoIndirectDepFromLocal] |
| 7310 |
import foo |
| 7311 |
import bar |
| 7312 |
|
| 7313 |
[file foo.py] |
| 7314 |
# Having a local named 'bar' shouldn't generate a dependency on module 'bar' |
| 7315 |
def f(bar: int) -> int: |
| 7316 |
return bar |
| 7317 |
|
| 7318 |
[file bar.py] |
| 7319 |
import foo |
| 7320 |
x = 1 |
| 7321 |
|
| 7322 |
[file bar.py.2] |
| 7323 |
import foo |
| 7324 |
x = 2 |
| 7325 |
|
| 7326 |
[out] |
| 7327 |
[rechecked bar] |
| 7328 |
[stale] |
| 7329 |
|
| 7330 |
|
| 7331 |
[case testIncrementalTypedDictGetMethodTotalFalse] |
| 7332 |
import impl |
| 7333 |
[file lib.py] |
| 7334 |
from typing import TypedDict |
| 7335 |
class Unrelated: pass |
| 7336 |
D = TypedDict('D', {'x': int, 'y': str}, total=False) |
| 7337 |
[file impl.py] |
| 7338 |
pass |
| 7339 |
[file impl.py.2] |
| 7340 |
from typing import Literal |
| 7341 |
from lib import D, Unrelated |
| 7342 |
d: D |
| 7343 |
u: Unrelated |
| 7344 |
x: Literal['x'] |
| 7345 |
y: Literal['y'] |
| 7346 |
z: Literal['z'] |
| 7347 |
x_or_y: Literal['x', 'y'] |
| 7348 |
x_or_z: Literal['x', 'z'] |
| 7349 |
x_or_y_or_z: Literal['x', 'y', 'z'] |
| 7350 |
|
| 7351 |
# test with literal expression |
| 7352 |
reveal_type(d.get('x')) |
| 7353 |
reveal_type(d.get('y')) |
| 7354 |
reveal_type(d.get('z')) |
| 7355 |
reveal_type(d.get('x', u)) |
| 7356 |
reveal_type(d.get('x', 1)) |
| 7357 |
reveal_type(d.get('y', None)) |
| 7358 |
|
| 7359 |
# test with literal type / union of literal types with implicit default |
| 7360 |
reveal_type(d.get(x)) |
| 7361 |
reveal_type(d.get(y)) |
| 7362 |
reveal_type(d.get(z)) |
| 7363 |
reveal_type(d.get(x_or_y)) |
| 7364 |
reveal_type(d.get(x_or_z)) |
| 7365 |
reveal_type(d.get(x_or_y_or_z)) |
| 7366 |
|
| 7367 |
# test with literal type / union of literal types with explicit default |
| 7368 |
reveal_type(d.get(x, u)) |
| 7369 |
reveal_type(d.get(y, u)) |
| 7370 |
reveal_type(d.get(z, u)) |
| 7371 |
reveal_type(d.get(x_or_y, u)) |
| 7372 |
reveal_type(d.get(x_or_z, u)) |
| 7373 |
reveal_type(d.get(x_or_y_or_z, u)) |
| 7374 |
[builtins fixtures/dict.pyi] |
| 7375 |
[typing fixtures/typing-typeddict.pyi] |
| 7376 |
[out] |
| 7377 |
[out2] |
| 7378 |
tmp/impl.py:13: note: Revealed type is "builtins.int | None" |
| 7379 |
tmp/impl.py:14: note: Revealed type is "builtins.str | None" |
| 7380 |
tmp/impl.py:15: note: Revealed type is "builtins.object" |
| 7381 |
tmp/impl.py:16: note: Revealed type is "builtins.int | lib.Unrelated" |
| 7382 |
tmp/impl.py:17: note: Revealed type is "builtins.int" |
| 7383 |
tmp/impl.py:18: note: Revealed type is "builtins.str | None" |
| 7384 |
tmp/impl.py:21: note: Revealed type is "builtins.int | None" |
| 7385 |
tmp/impl.py:22: note: Revealed type is "builtins.str | None" |
| 7386 |
tmp/impl.py:23: note: Revealed type is "builtins.object" |
| 7387 |
tmp/impl.py:24: note: Revealed type is "builtins.int | builtins.str | None" |
| 7388 |
tmp/impl.py:25: note: Revealed type is "builtins.object" |
| 7389 |
tmp/impl.py:26: note: Revealed type is "builtins.object" |
| 7390 |
tmp/impl.py:29: note: Revealed type is "builtins.int | lib.Unrelated" |
| 7391 |
tmp/impl.py:30: note: Revealed type is "builtins.str | lib.Unrelated" |
| 7392 |
tmp/impl.py:31: note: Revealed type is "builtins.object" |
| 7393 |
tmp/impl.py:32: note: Revealed type is "builtins.int | builtins.str | lib.Unrelated" |
| 7394 |
tmp/impl.py:33: note: Revealed type is "builtins.object" |
| 7395 |
tmp/impl.py:34: note: Revealed type is "builtins.object" |
| 7396 |
|
| 7397 |
[case testIncrementalTypedDictGetMethodTotalTrue] |
| 7398 |
import impl |
| 7399 |
[file lib.py] |
| 7400 |
from typing import TypedDict |
| 7401 |
class Unrelated: pass |
| 7402 |
D = TypedDict('D', {'x': int, 'y': str}, total=True) |
| 7403 |
[file impl.py] |
| 7404 |
pass |
| 7405 |
[file impl.py.2] |
| 7406 |
from typing import Literal |
| 7407 |
from lib import D, Unrelated |
| 7408 |
d: D |
| 7409 |
u: Unrelated |
| 7410 |
x: Literal['x'] |
| 7411 |
y: Literal['y'] |
| 7412 |
z: Literal['z'] |
| 7413 |
x_or_y: Literal['x', 'y'] |
| 7414 |
x_or_z: Literal['x', 'z'] |
| 7415 |
x_or_y_or_z: Literal['x', 'y', 'z'] |
| 7416 |
|
| 7417 |
# test with literal expression |
| 7418 |
reveal_type(d.get('x')) |
| 7419 |
reveal_type(d.get('y')) |
| 7420 |
reveal_type(d.get('z')) |
| 7421 |
reveal_type(d.get('x', u)) |
| 7422 |
reveal_type(d.get('x', 1)) |
| 7423 |
reveal_type(d.get('y', None)) |
| 7424 |
|
| 7425 |
# test with literal type / union of literal types with implicit default |
| 7426 |
reveal_type(d.get(x)) |
| 7427 |
reveal_type(d.get(y)) |
| 7428 |
reveal_type(d.get(z)) |
| 7429 |
reveal_type(d.get(x_or_y)) |
| 7430 |
reveal_type(d.get(x_or_z)) |
| 7431 |
reveal_type(d.get(x_or_y_or_z)) |
| 7432 |
|
| 7433 |
# test with literal type / union of literal types with explicit default |
| 7434 |
reveal_type(d.get(x, u)) |
| 7435 |
reveal_type(d.get(y, u)) |
| 7436 |
reveal_type(d.get(z, u)) |
| 7437 |
reveal_type(d.get(x_or_y, u)) |
| 7438 |
reveal_type(d.get(x_or_z, u)) |
| 7439 |
reveal_type(d.get(x_or_y_or_z, u)) |
| 7440 |
[builtins fixtures/dict.pyi] |
| 7441 |
[typing fixtures/typing-typeddict.pyi] |
| 7442 |
[out] |
| 7443 |
[out2] |
| 7444 |
tmp/impl.py:13: note: Revealed type is "builtins.int" |
| 7445 |
tmp/impl.py:14: note: Revealed type is "builtins.str" |
| 7446 |
tmp/impl.py:15: note: Revealed type is "builtins.object" |
| 7447 |
tmp/impl.py:16: note: Revealed type is "builtins.int" |
| 7448 |
tmp/impl.py:17: note: Revealed type is "builtins.int" |
| 7449 |
tmp/impl.py:18: note: Revealed type is "builtins.str" |
| 7450 |
tmp/impl.py:21: note: Revealed type is "builtins.int" |
| 7451 |
tmp/impl.py:22: note: Revealed type is "builtins.str" |
| 7452 |
tmp/impl.py:23: note: Revealed type is "builtins.object" |
| 7453 |
tmp/impl.py:24: note: Revealed type is "builtins.int | builtins.str" |
| 7454 |
tmp/impl.py:25: note: Revealed type is "builtins.object" |
| 7455 |
tmp/impl.py:26: note: Revealed type is "builtins.object" |
| 7456 |
tmp/impl.py:29: note: Revealed type is "builtins.int" |
| 7457 |
tmp/impl.py:30: note: Revealed type is "builtins.str" |
| 7458 |
tmp/impl.py:31: note: Revealed type is "builtins.object" |
| 7459 |
tmp/impl.py:32: note: Revealed type is "builtins.int | builtins.str" |
| 7460 |
tmp/impl.py:33: note: Revealed type is "builtins.object" |
| 7461 |
tmp/impl.py:34: note: Revealed type is "builtins.object" |
| 7462 |
|
| 7463 |
|
| 7464 |
[case testIncrementalTypedDictGetMethodTotalMixed] |
| 7465 |
import impl |
| 7466 |
[file lib.py] |
| 7467 |
from typing import TypedDict |
| 7468 |
from typing_extensions import Required, NotRequired |
| 7469 |
class Unrelated: pass |
| 7470 |
D = TypedDict('D', {'x': Required[int], 'y': NotRequired[str]}) |
| 7471 |
[file impl.py] |
| 7472 |
pass |
| 7473 |
[file impl.py.2] |
| 7474 |
from typing import Literal |
| 7475 |
from lib import D, Unrelated |
| 7476 |
d: D |
| 7477 |
u: Unrelated |
| 7478 |
x: Literal['x'] |
| 7479 |
y: Literal['y'] |
| 7480 |
z: Literal['z'] |
| 7481 |
x_or_y: Literal['x', 'y'] |
| 7482 |
x_or_z: Literal['x', 'z'] |
| 7483 |
x_or_y_or_z: Literal['x', 'y', 'z'] |
| 7484 |
|
| 7485 |
# test with literal expression |
| 7486 |
reveal_type(d.get('x')) |
| 7487 |
reveal_type(d.get('y')) |
| 7488 |
reveal_type(d.get('z')) |
| 7489 |
reveal_type(d.get('x', u)) |
| 7490 |
reveal_type(d.get('x', 1)) |
| 7491 |
reveal_type(d.get('y', None)) |
| 7492 |
|
| 7493 |
# test with literal type / union of literal types with implicit default |
| 7494 |
reveal_type(d.get(x)) |
| 7495 |
reveal_type(d.get(y)) |
| 7496 |
reveal_type(d.get(z)) |
| 7497 |
reveal_type(d.get(x_or_y)) |
| 7498 |
reveal_type(d.get(x_or_z)) |
| 7499 |
reveal_type(d.get(x_or_y_or_z)) |
| 7500 |
|
| 7501 |
# test with literal type / union of literal types with explicit default |
| 7502 |
reveal_type(d.get(x, u)) |
| 7503 |
reveal_type(d.get(y, u)) |
| 7504 |
reveal_type(d.get(z, u)) |
| 7505 |
reveal_type(d.get(x_or_y, u)) |
| 7506 |
reveal_type(d.get(x_or_z, u)) |
| 7507 |
reveal_type(d.get(x_or_y_or_z, u)) |
| 7508 |
[builtins fixtures/dict.pyi] |
| 7509 |
[typing fixtures/typing-typeddict.pyi] |
| 7510 |
[out] |
| 7511 |
[out2] |
| 7512 |
tmp/impl.py:13: note: Revealed type is "builtins.int" |
| 7513 |
tmp/impl.py:14: note: Revealed type is "builtins.str | None" |
| 7514 |
tmp/impl.py:15: note: Revealed type is "builtins.object" |
| 7515 |
tmp/impl.py:16: note: Revealed type is "builtins.int" |
| 7516 |
tmp/impl.py:17: note: Revealed type is "builtins.int" |
| 7517 |
tmp/impl.py:18: note: Revealed type is "builtins.str | None" |
| 7518 |
tmp/impl.py:21: note: Revealed type is "builtins.int" |
| 7519 |
tmp/impl.py:22: note: Revealed type is "builtins.str | None" |
| 7520 |
tmp/impl.py:23: note: Revealed type is "builtins.object" |
| 7521 |
tmp/impl.py:24: note: Revealed type is "builtins.int | builtins.str | None" |
| 7522 |
tmp/impl.py:25: note: Revealed type is "builtins.object" |
| 7523 |
tmp/impl.py:26: note: Revealed type is "builtins.object" |
| 7524 |
tmp/impl.py:29: note: Revealed type is "builtins.int" |
| 7525 |
tmp/impl.py:30: note: Revealed type is "builtins.str | lib.Unrelated" |
| 7526 |
tmp/impl.py:31: note: Revealed type is "builtins.object" |
| 7527 |
tmp/impl.py:32: note: Revealed type is "builtins.int | builtins.str | lib.Unrelated" |
| 7528 |
tmp/impl.py:33: note: Revealed type is "builtins.object" |
| 7529 |
tmp/impl.py:34: note: Revealed type is "builtins.object" |
| 7530 |
|
| 7531 |
[case testIncrementalAccessSubmoduleWithoutExplicitImport] |
| 7532 |
import b |
| 7533 |
import a |
| 7534 |
|
| 7535 |
[file a.py] |
| 7536 |
import pkg |
| 7537 |
|
| 7538 |
pkg.submod.foo() |
| 7539 |
|
| 7540 |
[file a.py.2] |
| 7541 |
import pkg |
| 7542 |
|
| 7543 |
pkg.submod.foo() |
| 7544 |
x = 1 |
| 7545 |
|
| 7546 |
[file b.py] |
| 7547 |
import c |
| 7548 |
|
| 7549 |
[file c.py] |
| 7550 |
from pkg import submod |
| 7551 |
|
| 7552 |
[file pkg/__init__.pyi] |
| 7553 |
[file pkg/submod.pyi] |
| 7554 |
def foo() -> None: pass |
| 7555 |
[out] |
| 7556 |
tmp/a.py:3: error: "object" has no attribute "submod" |
| 7557 |
[out2] |
| 7558 |
tmp/a.py:3: error: "object" has no attribute "submod" |
| 7559 |
|
| 7560 |
[case testIncrementalAccessSubmoduleWithoutExplicitImportNested] |
| 7561 |
import a |
| 7562 |
|
| 7563 |
[file a.py] |
| 7564 |
import pandas |
| 7565 |
pandas.core.dtypes |
| 7566 |
|
| 7567 |
[file a.py.2] |
| 7568 |
import pandas |
| 7569 |
pandas.core.dtypes |
| 7570 |
# touch |
| 7571 |
|
| 7572 |
[file pandas/__init__.py] |
| 7573 |
import pandas.core.api |
| 7574 |
|
| 7575 |
[file pandas/core/__init__.py] |
| 7576 |
[file pandas/core/api.py] |
| 7577 |
import pandas.core.dtypes.dtypes |
| 7578 |
|
| 7579 |
[file pandas/core/dtypes/__init__.py] |
| 7580 |
[file pandas/core/dtypes/dtypes.py] |
| 7581 |
X = 0 |
| 7582 |
[out] |
| 7583 |
[out2] |
| 7584 |
|
| 7585 |
[case testIncrementalAccessSubmoduleWithoutExplicitImportNestedFrom] |
| 7586 |
import a |
| 7587 |
|
| 7588 |
[file a.py] |
| 7589 |
import pandas |
| 7590 |
|
| 7591 |
# Although this actually works at runtime, we do not support this, since |
| 7592 |
# this would cause major slowdown for a rare edge case. This test verifies |
| 7593 |
# that we fail consistently on cold and warm runs. |
| 7594 |
pandas.core.dtypes |
| 7595 |
|
| 7596 |
[file a.py.2] |
| 7597 |
import pandas |
| 7598 |
pandas.core.dtypes |
| 7599 |
|
| 7600 |
[file pandas/__init__.py] |
| 7601 |
import pandas.core.api |
| 7602 |
|
| 7603 |
[file pandas/core/__init__.py] |
| 7604 |
[file pandas/core/api.py] |
| 7605 |
from pandas.core.dtypes.dtypes import X |
| 7606 |
|
| 7607 |
[file pandas/core/dtypes/__init__.py] |
| 7608 |
[file pandas/core/dtypes/dtypes.py] |
| 7609 |
X = 0 |
| 7610 |
[out] |
| 7611 |
tmp/a.py:6: error: "object" has no attribute "dtypes" |
| 7612 |
[out2] |
| 7613 |
tmp/a.py:2: error: "object" has no attribute "dtypes" |
| 7614 |
|
| 7615 |
[case testStarImportCycleRedefinition] |
| 7616 |
import m |
| 7617 |
|
| 7618 |
[file m.py] |
| 7619 |
import a |
| 7620 |
|
| 7621 |
[file m.py.2] |
| 7622 |
import a |
| 7623 |
reveal_type(a.C) |
| 7624 |
|
| 7625 |
[file a/__init__.py] |
| 7626 |
from a.b import * |
| 7627 |
from a.c import * |
| 7628 |
x = 1 |
| 7629 |
|
| 7630 |
[file a/b.py] |
| 7631 |
from other import C |
| 7632 |
from a.c import y |
| 7633 |
class C: ... # type: ignore |
| 7634 |
|
| 7635 |
[file a/c.py] |
| 7636 |
from other import C |
| 7637 |
from a import x |
| 7638 |
y = 1 |
| 7639 |
|
| 7640 |
[file other.py] |
| 7641 |
class C: ... |
| 7642 |
[out2] |
| 7643 |
tmp/m.py:2: note: Revealed type is "def () -> other.C" |
| 7644 |
|
| 7645 |
[case testOutputFormatterIncremental] |
| 7646 |
# flags2: --output json |
| 7647 |
def wrong() -> int: |
| 7648 |
if wrong(): |
| 7649 |
return 0 |
| 7650 |
[out] |
| 7651 |
main:2: error: Missing return statement |
| 7652 |
[out2] |
| 7653 |
{"file": "main", "line": 2, "column": 0, "end_line": 4, "end_column": 16, "message": "Missing return statement", "hint": null, "code": "return", "severity": "error"} |
| 7654 |
|
| 7655 |
[case testReExportAllInStubIncremental] |
| 7656 |
from m1 import C |
| 7657 |
from m1 import D |
| 7658 |
C() |
| 7659 |
C(1) |
| 7660 |
[file m1.pyi] |
| 7661 |
from m2 import * |
| 7662 |
[file m2.pyi] |
| 7663 |
from m3 import * |
| 7664 |
from m3 import __all__ as __all__ |
| 7665 |
class D: pass |
| 7666 |
[file m2.pyi.2] |
| 7667 |
from m3 import * |
| 7668 |
from m3 import __all__ as __all__ |
| 7669 |
class D: |
| 7670 |
x = 1 |
| 7671 |
[file m3.pyi] |
| 7672 |
from m4 import C as C |
| 7673 |
__all__ = ['C'] |
| 7674 |
[file m4.pyi] |
| 7675 |
class C: pass |
| 7676 |
[builtins fixtures/list.pyi] |
| 7677 |
[out] |
| 7678 |
main:2: error: Module "m1" has no attribute "D" |
| 7679 |
main:4: error: Too many arguments for "C" |
| 7680 |
[out2] |
| 7681 |
main:2: error: Module "m1" has no attribute "D" |
| 7682 |
main:4: error: Too many arguments for "C" |
| 7683 |
|
| 7684 |
[case testCyclicUndefinedImportWithStarIncremental] |
| 7685 |
import m |
| 7686 |
[file m.py] |
| 7687 |
import a |
| 7688 |
[file m.py.2] |
| 7689 |
import a |
| 7690 |
reveal_type(a.no_such_export) |
| 7691 |
[file a.py] |
| 7692 |
from b import no_such_export |
| 7693 |
[file b.py] |
| 7694 |
from a import * |
| 7695 |
[out] |
| 7696 |
tmp/b.py:1: error: Cannot resolve name "no_such_export" (possible cyclic definition) |
| 7697 |
[out2] |
| 7698 |
tmp/b.py:1: error: Cannot resolve name "no_such_export" (possible cyclic definition) |
| 7699 |
tmp/m.py:2: note: Revealed type is "Any" |
| 7700 |
|
| 7701 |
[case testCachedUnexpectedKeywordArgument] |
| 7702 |
import m |
| 7703 |
[file m.py] |
| 7704 |
import a |
| 7705 |
[file a.py] |
| 7706 |
import b |
| 7707 |
b.lol(uhhhh=12) # tweak |
| 7708 |
[file a.py.2] |
| 7709 |
import b |
| 7710 |
b.lol(uhhhh=12) |
| 7711 |
[file b.py] |
| 7712 |
def lol() -> None: pass |
| 7713 |
[file b.py.3] |
| 7714 |
# space |
| 7715 |
def lol() -> None: pass |
| 7716 |
[file m.py.4] |
| 7717 |
import a # touch |
| 7718 |
[out] |
| 7719 |
tmp/a.py:2: error: Unexpected keyword argument "uhhhh" for "lol" |
| 7720 |
tmp/a.py:2: note: "lol" defined in "b" |
| 7721 |
[out2] |
| 7722 |
tmp/a.py:2: error: Unexpected keyword argument "uhhhh" for "lol" |
| 7723 |
tmp/a.py:2: note: "lol" defined in "b" |
| 7724 |
[out3] |
| 7725 |
tmp/a.py:2: error: Unexpected keyword argument "uhhhh" for "lol" |
| 7726 |
tmp/a.py:2: note: "lol" defined in "b" |
| 7727 |
[out4] |
| 7728 |
tmp/a.py:2: error: Unexpected keyword argument "uhhhh" for "lol" |
| 7729 |
tmp/a.py:2: note: "lol" defined in "b" |
| 7730 |
|
| 7731 |
[case testMissingImportUnIgnoredInConfig] |
| 7732 |
# flags: --config-file tmp/mypy.ini |
| 7733 |
from foo import bar |
| 7734 |
[file mypy.ini] |
| 7735 |
\[mypy] |
| 7736 |
\[mypy-foo] |
| 7737 |
ignore_missing_imports = True |
| 7738 |
[file mypy.ini.2] |
| 7739 |
\[mypy] |
| 7740 |
\[mypy-foo] |
| 7741 |
ignore_missing_imports = False |
| 7742 |
[out] |
| 7743 |
[out2] |
| 7744 |
main:2: error: Cannot find implementation or library stub for module named "foo" |
| 7745 |
main:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports |
| 7746 |
|
| 7747 |
[case testMissingImportUnIgnoredInConfig2] |
| 7748 |
# flags: --config-file tmp/mypy.ini |
| 7749 |
from foo import bar |
| 7750 |
[file mypy.ini] |
| 7751 |
\[mypy] |
| 7752 |
\[mypy-foo] |
| 7753 |
ignore_missing_imports = False |
| 7754 |
[file mypy.ini.2] |
| 7755 |
\[mypy] |
| 7756 |
\[mypy-foo] |
| 7757 |
ignore_missing_imports = True |
| 7758 |
[out] |
| 7759 |
main:2: error: Cannot find implementation or library stub for module named "foo" |
| 7760 |
main:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports |
| 7761 |
[out2] |
| 7762 |
|
| 7763 |
[case testMissingImportUnIgnoredInConfig3] |
| 7764 |
# flags: --config-file tmp/mypy.ini |
| 7765 |
from foo import bar |
| 7766 |
[file foo.py] |
| 7767 |
bar = 1 |
| 7768 |
[file mypy.ini] |
| 7769 |
\[mypy] |
| 7770 |
\[mypy-foo] |
| 7771 |
follow_imports = skip |
| 7772 |
[file mypy.ini.2] |
| 7773 |
\[mypy] |
| 7774 |
\[mypy-foo] |
| 7775 |
follow_imports = error |
| 7776 |
[out] |
| 7777 |
[out2] |
| 7778 |
main:2: error: Import of "foo" ignored |
| 7779 |
main:2: note: (Using --follow-imports=error, module not passed on command line) |
| 7780 |
|
| 7781 |
[case testMissingImportUnIgnoredInConfig4] |
| 7782 |
# flags: --config-file tmp/mypy.ini |
| 7783 |
from foo import bar |
| 7784 |
[file foo.py] |
| 7785 |
bar = 1 |
| 7786 |
[file mypy.ini] |
| 7787 |
\[mypy] |
| 7788 |
\[mypy-foo] |
| 7789 |
follow_imports = error |
| 7790 |
[file mypy.ini.2] |
| 7791 |
\[mypy] |
| 7792 |
\[mypy-foo] |
| 7793 |
follow_imports = skip |
| 7794 |
[out] |
| 7795 |
main:2: error: Import of "foo" ignored |
| 7796 |
main:2: note: (Using --follow-imports=error, module not passed on command line) |
| 7797 |
[out2] |
| 7798 |
|
| 7799 |
[case testMissingImportUnIgnoredInConfig5] |
| 7800 |
# flags: --config-file tmp/mypy.ini --warn-unused-ignores |
| 7801 |
from foo import bar # type: ignore[import-not-found] |
| 7802 |
[file mypy.ini] |
| 7803 |
\[mypy] |
| 7804 |
\[mypy-foo] |
| 7805 |
ignore_missing_imports = True |
| 7806 |
[file mypy.ini.2] |
| 7807 |
\[mypy] |
| 7808 |
\[mypy-foo] |
| 7809 |
ignore_missing_imports = False |
| 7810 |
[out] |
| 7811 |
main:2: error: Unused "type: ignore" comment |
| 7812 |
[out2] |
| 7813 |
|
| 7814 |
[case testMissingImportUnIgnoredInConfig6] |
| 7815 |
# flags: --config-file tmp/mypy.ini --warn-unused-ignores |
| 7816 |
from foo import bar # type: ignore[import-not-found] |
| 7817 |
[file mypy.ini] |
| 7818 |
\[mypy] |
| 7819 |
\[mypy-foo] |
| 7820 |
ignore_missing_imports = False |
| 7821 |
[file mypy.ini.2] |
| 7822 |
\[mypy] |
| 7823 |
\[mypy-foo] |
| 7824 |
ignore_missing_imports = True |
| 7825 |
[out] |
| 7826 |
[out2] |
| 7827 |
main:2: error: Unused "type: ignore" comment |
| 7828 |
|
| 7829 |
[case testIndirectDependencyReorderModulesNoCrash] |
| 7830 |
import a |
| 7831 |
[file a.py] |
| 7832 |
import b |
| 7833 |
[file a.py.2] |
| 7834 |
import pkg.mod |
| 7835 |
import b |
| 7836 |
[file b.py] |
| 7837 |
import foo |
| 7838 |
import pkg |
| 7839 |
x: pkg.mod.C |
| 7840 |
[file pkg/__init__.py] |
| 7841 |
[file pkg/mod.py] |
| 7842 |
import c |
| 7843 |
class C: ... |
| 7844 |
# The chain of trivial stale modules is to force late load of pkg.mod, |
| 7845 |
# otherwise the test can pass accidentally. |
| 7846 |
[file c.py] |
| 7847 |
import d |
| 7848 |
[file c.py.2] |
| 7849 |
import d # touch |
| 7850 |
[file d.py] |
| 7851 |
import e |
| 7852 |
[file d.py.2] |
| 7853 |
import e # touch |
| 7854 |
[file e.py] |
| 7855 |
[file foo.py] |
| 7856 |
import bar |
| 7857 |
[file bar.py] |
| 7858 |
import pkg.mod |
| 7859 |
[file bar.py.2] |
| 7860 |
[out] |
| 7861 |
[out2] |
| 7862 |
tmp/b.py:3: error: Name "pkg.mod.C" is not defined |
| 7863 |
|
| 7864 |
[case testIndirectDependencyReorderModulesNoCrash2] |
| 7865 |
import m |
| 7866 |
[file m.py] |
| 7867 |
import a |
| 7868 |
[file m.py.2] |
| 7869 |
import a |
| 7870 |
import d |
| 7871 |
[file a.py] |
| 7872 |
import b |
| 7873 |
x: b.c.d.C |
| 7874 |
[file b.py] |
| 7875 |
import c |
| 7876 |
[file c.py] |
| 7877 |
import d |
| 7878 |
[file c.py.2] |
| 7879 |
[file d.py] |
| 7880 |
import n1 |
| 7881 |
class C: ... |
| 7882 |
# The chain of trivial stale modules is to force late load of d, |
| 7883 |
# otherwise the test can pass accidentally. |
| 7884 |
[file n1.py] |
| 7885 |
import n2 |
| 7886 |
[file n1.py.2] |
| 7887 |
import n2 # touch |
| 7888 |
[file n2.py] |
| 7889 |
import n3 |
| 7890 |
[file n2.py.2] |
| 7891 |
import n3 # touch |
| 7892 |
[file n3.py] |
| 7893 |
[out] |
| 7894 |
[out2] |
| 7895 |
tmp/a.py:2: error: Name "b.c.d.C" is not defined |
| 7896 |
|
| 7897 |
[case testDeletedModuleFromImport] |
| 7898 |
# flags: --ignore-missing-imports |
| 7899 |
from a import b |
| 7900 |
[file a/__init__.py] |
| 7901 |
[file a/b.py] |
| 7902 |
[delete a/b.py.2] |
| 7903 |
[out] |
| 7904 |
[out2] |
| 7905 |
main:2: error: Module "a" has no attribute "b" |
| 7906 |
|
| 7907 |
[case testDeletedModuleFromImport2] |
| 7908 |
# flags: --ignore-missing-imports |
| 7909 |
import a |
| 7910 |
import a.b |
| 7911 |
from a import b # no error here |
| 7912 |
[file a/__init__.py] |
| 7913 |
[file a/b.py] |
| 7914 |
[delete a/b.py.2] |
| 7915 |
[out] |
| 7916 |
[out2] |
| 7917 |
|
| 7918 |
[case testDeletedModuleFromImport3] |
| 7919 |
# flags: --warn-unused-ignores |
| 7920 |
from a import b # type: ignore[attr-defined] |
| 7921 |
[file a/__init__.py] |
| 7922 |
[file a/b.py] |
| 7923 |
[delete a/b.py.2] |
| 7924 |
[out] |
| 7925 |
main:2: error: Unused "type: ignore" comment |
| 7926 |
[out2] |
| 7927 |
|
| 7928 |
[case testConfigWarnUnusedSectionIncremental] |
| 7929 |
# flags: --config-file=tmp/mypy.ini |
| 7930 |
import m |
| 7931 |
[file m.py] |
| 7932 |
import a |
| 7933 |
[file m.py.2] |
| 7934 |
import a # touch |
| 7935 |
[file a.py] |
| 7936 |
import foo # type: ignore |
| 7937 |
[file mypy.ini] |
| 7938 |
\[mypy] |
| 7939 |
warn_unused_configs = true |
| 7940 |
\[mypy-bar] |
| 7941 |
\[mypy-foo] |
| 7942 |
[file mypy.ini.3] |
| 7943 |
\[mypy] |
| 7944 |
warn_unused_configs = true |
| 7945 |
\[mypy-foo] |
| 7946 |
[out] |
| 7947 |
tmp/mypy.ini: note: unused section(s): [mypy-bar] |
| 7948 |
[out2] |
| 7949 |
tmp/mypy.ini: note: unused section(s): [mypy-bar] |
| 7950 |
[out3] |
| 7951 |
|
| 7952 |
[case testConfigWarnUnusedSectionIncrementalTOML] |
| 7953 |
# flags: --config-file tmp/pyproject.toml |
| 7954 |
import m |
| 7955 |
[file m.py] |
| 7956 |
import a |
| 7957 |
[file m.py.2] |
| 7958 |
import a # touch |
| 7959 |
[file a.py] |
| 7960 |
import foo # type: ignore |
| 7961 |
[file pyproject.toml] |
| 7962 |
\[tool.mypy] |
| 7963 |
warn_unused_configs = true |
| 7964 |
\[[tool.mypy.overrides]] |
| 7965 |
module = "bar" |
| 7966 |
\[[tool.mypy.overrides]] |
| 7967 |
module = "foo" |
| 7968 |
warn_unreachable = true |
| 7969 |
[file pyproject.toml.3] |
| 7970 |
\[tool.mypy] |
| 7971 |
warn_unused_configs = true |
| 7972 |
\[[tool.mypy.overrides]] |
| 7973 |
module = "foo" |
| 7974 |
[out] |
| 7975 |
tmp/pyproject.toml: note: unused section(s): module = ['bar'] |
| 7976 |
[out2] |
| 7977 |
tmp/pyproject.toml: note: unused section(s): module = ['bar'] |
| 7978 |
[out3] |
| 7979 |
|
| 7980 |
[case testAddedMissingModuleSkip] |
| 7981 |
# flags: --follow-imports=skip |
| 7982 |
import mod |
| 7983 |
[file mod.py.2] |
| 7984 |
[out] |
| 7985 |
main:2: error: Cannot find implementation or library stub for module named "mod" |
| 7986 |
main:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports |
| 7987 |
[out2] |
| 7988 |
|
| 7989 |
[case testDeletedModuleSkip] |
| 7990 |
# flags: --follow-imports=skip |
| 7991 |
import mod |
| 7992 |
[file mod.py] |
| 7993 |
[delete mod.py.2] |
| 7994 |
[out] |
| 7995 |
[out2] |
| 7996 |
main:2: error: Cannot find implementation or library stub for module named "mod" |
| 7997 |
main:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports |
| 7998 |
|
| 7999 |
[case testIncrementalFileConfigCommentsStale] |
| 8000 |
-- When a dependency changes, the importing module becomes stale and is |
| 8001 |
-- reprocessed via process_stale_scc. As inline config comments are not cached |
| 8002 |
-- (by design), moving the order of processing the stale SCC can accidentally |
| 8003 |
-- break file config comments on subsequent runs. |
| 8004 |
# mypy: disable-error-code="import-not-found" |
| 8005 |
import nonexistent |
| 8006 |
import b |
| 8007 |
[file b.py] |
| 8008 |
x = 1 |
| 8009 |
[file b.py.2] |
| 8010 |
x = "hello" |
| 8011 |
[builtins fixtures/module.pyi] |
| 8012 |
[stale b] |
| 8013 |
[rechecked b] |
| 8014 |
|
| 8015 |
[case testNamedTupleInlineBaseClassNoNameCollision] |
| 8016 |
import m |
| 8017 |
[file m.py] |
| 8018 |
from lib import A, B |
| 8019 |
a: A |
| 8020 |
b: B |
| 8021 |
reveal_type(a) |
| 8022 |
reveal_type(b) |
| 8023 |
[file m.py.2] |
| 8024 |
from lib import A, B |
| 8025 |
a: A |
| 8026 |
b: B |
| 8027 |
reveal_type(a) # touch |
| 8028 |
reveal_type(b) |
| 8029 |
[file lib.py] |
| 8030 |
from typing import NamedTuple |
| 8031 |
class A(NamedTuple("Same", [('x', int)])): pass |
| 8032 |
class B(NamedTuple("Same", [('x', str)])): pass |
| 8033 |
[builtins fixtures/tuple.pyi] |
| 8034 |
[out] |
| 8035 |
tmp/m.py:4: note: Revealed type is "tuple[builtins.int, fallback=lib.A]" |
| 8036 |
tmp/m.py:5: note: Revealed type is "tuple[builtins.str, fallback=lib.B]" |
| 8037 |
[out2] |
| 8038 |
tmp/m.py:4: note: Revealed type is "tuple[builtins.int, fallback=lib.A]" |
| 8039 |
tmp/m.py:5: note: Revealed type is "tuple[builtins.str, fallback=lib.B]" |
| 8040 |
|
| 8041 |
[case testNamedTupleInlineBaseClassRedefined] |
| 8042 |
import m |
| 8043 |
[file m.py] |
| 8044 |
from lib import A |
| 8045 |
a: A |
| 8046 |
reveal_type(a) |
| 8047 |
[file m.py.2] |
| 8048 |
from lib import A |
| 8049 |
a: A # touch |
| 8050 |
reveal_type(a) |
| 8051 |
[file lib.py] |
| 8052 |
from typing import NamedTuple |
| 8053 |
class A(NamedTuple("N", [('x', int)])): pass |
| 8054 |
class A(NamedTuple("N", [('x', str)])): pass |
| 8055 |
[builtins fixtures/tuple.pyi] |
| 8056 |
[out] |
| 8057 |
tmp/lib.py:3: error: Name "A" already defined on line 2 |
| 8058 |
tmp/m.py:3: note: Revealed type is "tuple[builtins.int, fallback=lib.A]" |
| 8059 |
[out2] |
| 8060 |
tmp/lib.py:3: error: Name "A" already defined on line 2 |
| 8061 |
tmp/m.py:3: note: Revealed type is "tuple[builtins.int, fallback=lib.A]" |
| 8062 |
|
| 8063 |
[case testTypedDictInlineBaseClassRedefined] |
| 8064 |
import m |
| 8065 |
[file m.py] |
| 8066 |
from lib import A |
| 8067 |
a: A |
| 8068 |
reveal_type(a) |
| 8069 |
[file m.py.2] |
| 8070 |
from lib import A |
| 8071 |
a: A # touch |
| 8072 |
reveal_type(a) |
| 8073 |
[file lib.py] |
| 8074 |
from typing import TypedDict |
| 8075 |
class A(TypedDict("TD", {'x': int})): |
| 8076 |
pass |
| 8077 |
class A(TypedDict("TD", {'x': str})): |
| 8078 |
pass |
| 8079 |
[builtins fixtures/dict.pyi] |
| 8080 |
[typing fixtures/typing-typeddict.pyi] |
| 8081 |
[out] |
| 8082 |
tmp/lib.py:4: error: Name "A" already defined (possibly by an import) |
| 8083 |
tmp/m.py:3: note: Revealed type is "TypedDict('lib.A', {'x': builtins.int})" |
| 8084 |
[out2] |
| 8085 |
tmp/lib.py:4: error: Name "A" already defined (possibly by an import) |
| 8086 |
tmp/m.py:3: note: Revealed type is "TypedDict('lib.A', {'x': builtins.int})" |
| 8087 |
|
| 8088 |
[case testNewReturnTypeIncremental] |
| 8089 |
import m |
| 8090 |
[file m.py] |
| 8091 |
from lib import C |
| 8092 |
|
| 8093 |
reveal_type(C().ta) |
| 8094 |
x: int = C().ta |
| 8095 |
reveal_type(C().ta.x) |
| 8096 |
[file m.py.2] |
| 8097 |
from lib import C |
| 8098 |
|
| 8099 |
# touch |
| 8100 |
reveal_type(C().ta) |
| 8101 |
x: int = C().ta |
| 8102 |
reveal_type(C().ta.x) |
| 8103 |
[file lib.py] |
| 8104 |
class A: |
| 8105 |
x = "test" |
| 8106 |
def __new__(cls) -> int: ... # type: ignore |
| 8107 |
|
| 8108 |
class C: |
| 8109 |
def __init__(self) -> None: |
| 8110 |
self.ta = A |
| 8111 |
[out] |
| 8112 |
tmp/m.py:3: note: Revealed type is "def () -> builtins.int" |
| 8113 |
tmp/m.py:4: error: Incompatible types in assignment (expression has type "type[A]", variable has type "int") |
| 8114 |
tmp/m.py:5: note: Revealed type is "builtins.str" |
| 8115 |
[out2] |
| 8116 |
tmp/m.py:4: note: Revealed type is "def () -> builtins.int" |
| 8117 |
tmp/m.py:5: error: Incompatible types in assignment (expression has type "type[A]", variable has type "int") |
| 8118 |
tmp/m.py:6: note: Revealed type is "builtins.str" |
| 8119 |
|
| 8120 |
[case testTypeFormWorksInIncrementalMode] |
| 8121 |
import b |
| 8122 |
[file a.py] |
| 8123 |
from typing import TypeVar |
| 8124 |
from typing_extensions import TypeForm |
| 8125 |
|
| 8126 |
T = TypeVar("T") |
| 8127 |
def test(arg: TypeForm[T]) -> T: ... |
| 8128 |
|
| 8129 |
[file b.py] |
| 8130 |
from a import test |
| 8131 |
test("int") |
| 8132 |
|
| 8133 |
[file b.py.2] |
| 8134 |
from a import test |
| 8135 |
reveal_type(test("int")) |
| 8136 |
|
| 8137 |
[builtins fixtures/primitives.pyi] |
| 8138 |
[typing fixtures/typing-full.pyi] |
| 8139 |
[out] |
| 8140 |
[out2] |
| 8141 |
tmp/b.py:2: note: Revealed type is "builtins.int" |
| 8142 |
|
| 8143 |
[case testIncrementalNativeParserShadowFile] |
| 8144 |
# flags: --native-parser --shadow-file tmp/a.py tmp/a_shadow.py |
| 8145 |
import a |
| 8146 |
import b |
| 8147 |
-- a and b don't depend on each other, so they can be checked in parallel. |
| 8148 |
[file a.py] |
| 8149 |
x: int = 1 |
| 8150 |
reveal_type(x) |
| 8151 |
[file b.py] |
| 8152 |
y: int = 2 |
| 8153 |
[file a_shadow.py] |
| 8154 |
x: str = "y" |
| 8155 |
reveal_type(x) |
| 8156 |
[rechecked] |
| 8157 |
[stale] |
| 8158 |
[out1] |
| 8159 |
tmp/a.py:2: note: Revealed type is "builtins.str" |
| 8160 |
[out2] |
| 8161 |
tmp/a.py:2: note: Revealed type is "builtins.str" |
| 8162 |
|
| 8163 |
[case testIncrementalNativeParserShadowFileChanged] |
| 8164 |
# flags: --native-parser --shadow-file tmp/a.py tmp/a_shadow.py |
| 8165 |
import a |
| 8166 |
import b |
| 8167 |
-- a and b don't depend on each other, so they can be checked in parallel. |
| 8168 |
[file a.py] |
| 8169 |
x: int = 1 |
| 8170 |
reveal_type(x) |
| 8171 |
[file b.py] |
| 8172 |
y: int = 2 |
| 8173 |
[file a_shadow.py] |
| 8174 |
x: str = "y" |
| 8175 |
reveal_type(x) |
| 8176 |
[file a_shadow.py.2] |
| 8177 |
x: bytes = b"y" |
| 8178 |
reveal_type(x) |
| 8179 |
[rechecked a] |
| 8180 |
[stale a] |
| 8181 |
[out1] |
| 8182 |
tmp/a.py:2: note: Revealed type is "builtins.str" |
| 8183 |
[out2] |
| 8184 |
tmp/a.py:2: note: Revealed type is "builtins.bytes" |
| 8185 |
|
| 8186 |
[case testIncrementalNativeParserShadowFileIntroduced] |
| 8187 |
# flags: --native-parser |
| 8188 |
# flags2: --native-parser --shadow-file tmp/a.py tmp/a_shadow.py |
| 8189 |
import a |
| 8190 |
import b |
| 8191 |
-- a and b don't depend on each other, so they can be checked in parallel. |
| 8192 |
-- The first run has no shadow file; the second run introduces one for a.py. |
| 8193 |
[file a.py] |
| 8194 |
x: int = 1 |
| 8195 |
reveal_type(x) |
| 8196 |
[file b.py] |
| 8197 |
y: int = 2 |
| 8198 |
[file a_shadow.py.2] |
| 8199 |
x: str = "y" |
| 8200 |
reveal_type(x) |
| 8201 |
[rechecked a] |
| 8202 |
[stale a] |
| 8203 |
[out1] |
| 8204 |
tmp/a.py:2: note: Revealed type is "builtins.int" |
| 8205 |
[out2] |
| 8206 |
tmp/a.py:2: note: Revealed type is "builtins.str" |
| 8207 |
|
| 8208 |
[case testIncrementalFollowImportsSkipStubWithSkippedRuntimeDependency] |
| 8209 |
# flags: --follow-imports=skip |
| 8210 |
import pkg.foo |
| 8211 |
[file pkg/__init__.py] |
| 8212 |
|
| 8213 |
[file pkg/foo.pyi] |
| 8214 |
from pkg import helper |
| 8215 |
|
| 8216 |
x = 1 |
| 8217 |
[file pkg/helper.py] |
| 8218 |
y = 2 |
| 8219 |
[rechecked] |
| 8220 |
[stale] |
| 8221 |
[out2] |
| 8222 |
[out3] |