| 1 |
-- Test cases for fine-grained incremental checking |
| 2 |
-- |
| 3 |
-- Test cases may define multiple versions of a file |
| 4 |
-- (e.g. m.py, m.py.2). There is always an initial batch |
| 5 |
-- pass that processes all files present initially, followed |
| 6 |
-- by one or more fine-grained incremental passes that use |
| 7 |
-- alternative versions of files, if available. If a file |
| 8 |
-- just has a single .py version, it is used for all passes. |
| 9 |
|
| 10 |
-- TODO: what if version for some passes but not all |
| 11 |
|
| 12 |
-- Output is laid out like this: |
| 13 |
-- |
| 14 |
-- [out] |
| 15 |
-- <optional output from batch pass> |
| 16 |
-- == |
| 17 |
-- <optional output from first incremental pass> |
| 18 |
-- |
| 19 |
-- |
| 20 |
-- Modules that are expected to be detected as changed by dmypy_server |
| 21 |
-- can be checked with [stale ...] |
| 22 |
-- Generally this should mean added, deleted, or changed files, though there |
| 23 |
-- are important edge cases related to the cache: deleted files won't be detected |
| 24 |
-- as changed in the initial run with the cache while modules that depended on them |
| 25 |
-- should be. |
| 26 |
-- |
| 27 |
-- Modules that require a full-module reprocessing by update can be checked with |
| 28 |
-- [rechecked ...]. This should include any files detected as having changed as well |
| 29 |
-- as any files that contain targets that need to be reprocessed but which haven't |
| 30 |
-- been loaded yet. If there is no [rechecked...] directive, it inherits the value of |
| 31 |
-- [stale ...]. |
| 32 |
-- |
| 33 |
-- Specifications for later runs can be given with [stale2 ...], [stale3 ...], etc. |
| 34 |
-- |
| 35 |
-- Test runner can parse options from mypy.ini file. Updating this file in between |
| 36 |
-- incremental runs is not yet supported. |
| 37 |
-- |
| 38 |
-- Each test case run without caching and with caching (if the initial run passes), |
| 39 |
-- unless it has one a -only_when_cache or -only_when_nocache arguments. We sometimes |
| 40 |
-- skip caching test cases to speed up tests, if the caching variant is not useful. |
| 41 |
-- The caching test case variants get an implicit _cached suffix. |
| 42 |
|
| 43 |
[case testReprocessFunction] |
| 44 |
import m |
| 45 |
def g() -> int: |
| 46 |
return m.f() |
| 47 |
[file m.py] |
| 48 |
def f() -> int: |
| 49 |
pass |
| 50 |
[file m.py.2] |
| 51 |
def f() -> str: |
| 52 |
pass |
| 53 |
[out] |
| 54 |
== |
| 55 |
main:3: error: Incompatible return value type (got "str", expected "int") |
| 56 |
|
| 57 |
[case testReprocessTopLevel] |
| 58 |
import m |
| 59 |
m.f(1) |
| 60 |
def g() -> None: pass |
| 61 |
[file m.py] |
| 62 |
def f(x: int) -> None: pass |
| 63 |
[file m.py.2] |
| 64 |
def f(x: str) -> None: pass |
| 65 |
[out] |
| 66 |
== |
| 67 |
main:2: error: Argument 1 to "f" has incompatible type "int"; expected "str" |
| 68 |
|
| 69 |
[case testReprocessMethod] |
| 70 |
import m |
| 71 |
class B: |
| 72 |
def f(self, a: m.A) -> None: |
| 73 |
a.g() # E |
| 74 |
[file m.py] |
| 75 |
class A: |
| 76 |
def g(self) -> None: pass |
| 77 |
[file m.py.2] |
| 78 |
class A: |
| 79 |
def g(self, a: A) -> None: pass |
| 80 |
[out] |
| 81 |
== |
| 82 |
main:4: error: Missing positional argument "a" in call to "g" of "A" |
| 83 |
|
| 84 |
[case testReprocessMethodShowSource] |
| 85 |
# flags: --pretty --show-error-codes |
| 86 |
import m |
| 87 |
class B: |
| 88 |
def f(self, a: m.A) -> None: |
| 89 |
a.g() # E |
| 90 |
[file m.py] |
| 91 |
class A: |
| 92 |
def g(self) -> None: pass |
| 93 |
[file m.py.2] |
| 94 |
class A: |
| 95 |
def g(self, a: A) -> None: pass |
| 96 |
[out] |
| 97 |
== |
| 98 |
main:5: error: Missing positional argument "a" in call to "g" of "A" [call-arg] |
| 99 |
a.g() # E |
| 100 |
^~~~~ |
| 101 |
|
| 102 |
[case testFunctionMissingModuleAttribute] |
| 103 |
import m |
| 104 |
def h() -> None: |
| 105 |
m.f(1) |
| 106 |
[file m.py] |
| 107 |
def f(x: int) -> None: pass |
| 108 |
[file m.py.2] |
| 109 |
def g(x: str) -> None: pass |
| 110 |
[builtins fixtures/fine_grained.pyi] |
| 111 |
[out] |
| 112 |
== |
| 113 |
main:3: error: Module has no attribute "f" |
| 114 |
|
| 115 |
[case testTopLevelMissingModuleAttribute] |
| 116 |
import m |
| 117 |
m.f(1) |
| 118 |
def g() -> None: pass |
| 119 |
[file m.py] |
| 120 |
def f(x: int) -> None: pass |
| 121 |
[file m.py.2] |
| 122 |
def g(x: int) -> None: pass |
| 123 |
[builtins fixtures/fine_grained.pyi] |
| 124 |
[out] |
| 125 |
== |
| 126 |
main:2: error: Module has no attribute "f" |
| 127 |
|
| 128 |
[case testClassChangedIntoFunction] |
| 129 |
|
| 130 |
import m |
| 131 |
def f(a: m.A) -> None: |
| 132 |
pass |
| 133 |
[file m.py] |
| 134 |
class A: pass |
| 135 |
[file m.py.2] |
| 136 |
def A() -> None: pass |
| 137 |
[out] |
| 138 |
== |
| 139 |
main:3: error: Function "m.A" is not valid as a type |
| 140 |
main:3: note: Perhaps you need "Callable[...]" or a callback protocol? |
| 141 |
|
| 142 |
[case testClassChangedIntoFunction2] |
| 143 |
|
| 144 |
import m |
| 145 |
class B: |
| 146 |
def f(self, a: m.A) -> None: pass |
| 147 |
[file m.py] |
| 148 |
class A: pass |
| 149 |
[file m.py.2] |
| 150 |
def A() -> None: pass |
| 151 |
[file n.py.3] |
| 152 |
[out] |
| 153 |
== |
| 154 |
main:4: error: Function "m.A" is not valid as a type |
| 155 |
main:4: note: Perhaps you need "Callable[...]" or a callback protocol? |
| 156 |
== |
| 157 |
main:4: error: Function "m.A" is not valid as a type |
| 158 |
main:4: note: Perhaps you need "Callable[...]" or a callback protocol? |
| 159 |
|
| 160 |
[case testAttributeTypeChanged] |
| 161 |
import m |
| 162 |
def f(a: m.A) -> int: |
| 163 |
return a.x |
| 164 |
[file m.py] |
| 165 |
class A: |
| 166 |
def f(self) -> None: |
| 167 |
self.x = 1 |
| 168 |
[file m.py.2] |
| 169 |
class A: |
| 170 |
def f(self) -> None: |
| 171 |
self.x = 'x' |
| 172 |
[out] |
| 173 |
== |
| 174 |
main:3: error: Incompatible return value type (got "str", expected "int") |
| 175 |
|
| 176 |
[case testAttributeRemoved] |
| 177 |
import m |
| 178 |
def f(a: m.A) -> int: |
| 179 |
return a.x |
| 180 |
[file m.py] |
| 181 |
class A: |
| 182 |
def f(self) -> None: |
| 183 |
self.x = 1 |
| 184 |
[file m.py.2] |
| 185 |
class A: |
| 186 |
def f(self) -> None: pass |
| 187 |
[out] |
| 188 |
== |
| 189 |
main:3: error: "A" has no attribute "x" |
| 190 |
|
| 191 |
[case testVariableTypeBecomesInvalid] |
| 192 |
import m |
| 193 |
def f() -> None: |
| 194 |
a: m.A |
| 195 |
[file m.py] |
| 196 |
class A: pass |
| 197 |
[file m.py.2] |
| 198 |
[out] |
| 199 |
== |
| 200 |
main:3: error: Name "m.A" is not defined |
| 201 |
|
| 202 |
[case testTwoIncrementalSteps] |
| 203 |
import m |
| 204 |
import n |
| 205 |
[file m.py] |
| 206 |
def f() -> None: pass |
| 207 |
[file n.py] |
| 208 |
import m |
| 209 |
def g() -> None: |
| 210 |
m.f() # E |
| 211 |
[file m.py.2] |
| 212 |
import n |
| 213 |
def f(x: int) -> None: |
| 214 |
n.g() # E |
| 215 |
[file n.py.3] |
| 216 |
import m |
| 217 |
def g(a: str) -> None: |
| 218 |
m.f('') # E |
| 219 |
[out] |
| 220 |
== |
| 221 |
n.py:3: error: Missing positional argument "x" in call to "f" |
| 222 |
== |
| 223 |
n.py:3: error: Argument 1 to "f" has incompatible type "str"; expected "int" |
| 224 |
m.py:3: error: Missing positional argument "a" in call to "g" |
| 225 |
|
| 226 |
[case testTwoRounds] |
| 227 |
import m |
| 228 |
def h(a: m.A) -> int: |
| 229 |
return a.x |
| 230 |
[file m.py] |
| 231 |
import n |
| 232 |
class A: |
| 233 |
def g(self, b: n.B) -> None: |
| 234 |
self.x = b.f() |
| 235 |
[file n.py] |
| 236 |
class B: |
| 237 |
def f(self) -> int: pass |
| 238 |
[file n.py.2] |
| 239 |
class B: |
| 240 |
def f(self) -> str: pass |
| 241 |
[out] |
| 242 |
== |
| 243 |
main:3: error: Incompatible return value type (got "str", expected "int") |
| 244 |
|
| 245 |
[case testFixTypeError] |
| 246 |
import m |
| 247 |
def f(a: m.A) -> None: |
| 248 |
a.f(a) |
| 249 |
[file m.py] |
| 250 |
class A: |
| 251 |
def f(self, a: 'A') -> None: pass |
| 252 |
[file m.py.2] |
| 253 |
class A: |
| 254 |
def f(self) -> None: pass |
| 255 |
[file m.py.3] |
| 256 |
class A: |
| 257 |
def f(self, a: 'A') -> None: pass |
| 258 |
[out] |
| 259 |
== |
| 260 |
main:3: error: Too many arguments for "f" of "A" |
| 261 |
== |
| 262 |
|
| 263 |
[case testFixTypeError2] |
| 264 |
import m |
| 265 |
def f(a: m.A) -> None: |
| 266 |
a.f() |
| 267 |
[file m.py] |
| 268 |
class A: |
| 269 |
def f(self) -> None: pass |
| 270 |
[file m.py.2] |
| 271 |
class A: |
| 272 |
def g(self) -> None: pass |
| 273 |
[file m.py.3] |
| 274 |
class A: |
| 275 |
def f(self) -> None: pass |
| 276 |
[out] |
| 277 |
== |
| 278 |
main:3: error: "A" has no attribute "f" |
| 279 |
== |
| 280 |
|
| 281 |
[case testFixSemanticAnalysisError] |
| 282 |
import m |
| 283 |
def f() -> None: |
| 284 |
m.A() |
| 285 |
[file m.py] |
| 286 |
class A: pass |
| 287 |
[file m.py.2] |
| 288 |
class B: pass |
| 289 |
[file m.py.3] |
| 290 |
class A: pass |
| 291 |
[builtins fixtures/fine_grained.pyi] |
| 292 |
[out] |
| 293 |
== |
| 294 |
main:3: error: Module has no attribute "A" |
| 295 |
== |
| 296 |
|
| 297 |
[case testContinueToReportTypeCheckError] |
| 298 |
import m |
| 299 |
def f(a: m.A) -> None: |
| 300 |
a.f() |
| 301 |
def g(a: m.A) -> None: |
| 302 |
a.g() |
| 303 |
[file m.py] |
| 304 |
class A: |
| 305 |
def f(self) -> None: pass |
| 306 |
def g(self) -> None: pass |
| 307 |
[file m.py.2] |
| 308 |
class A: pass |
| 309 |
[file m.py.3] |
| 310 |
class A: |
| 311 |
def f(self) -> None: pass |
| 312 |
[out] |
| 313 |
== |
| 314 |
main:3: error: "A" has no attribute "f" |
| 315 |
main:5: error: "A" has no attribute "g" |
| 316 |
== |
| 317 |
main:5: error: "A" has no attribute "g" |
| 318 |
|
| 319 |
[case testContinueToReportSemanticAnalysisError] |
| 320 |
import m |
| 321 |
def f() -> None: |
| 322 |
m.A() |
| 323 |
def g() -> None: |
| 324 |
m.B() |
| 325 |
[file m.py] |
| 326 |
class A: pass |
| 327 |
class B: pass |
| 328 |
[file m.py.2] |
| 329 |
[file m.py.3] |
| 330 |
class A: pass |
| 331 |
[builtins fixtures/fine_grained.pyi] |
| 332 |
[out] |
| 333 |
== |
| 334 |
main:3: error: Module has no attribute "A" |
| 335 |
main:5: error: Module has no attribute "B" |
| 336 |
== |
| 337 |
main:5: error: Module has no attribute "B" |
| 338 |
|
| 339 |
[case testContinueToReportErrorAtTopLevel-only_when_nocache] |
| 340 |
-- Different cache/no-cache tests because: |
| 341 |
-- Error message ordering differs |
| 342 |
import n |
| 343 |
import m |
| 344 |
m.A().f() |
| 345 |
[file n.py] |
| 346 |
import m |
| 347 |
m.A().g() |
| 348 |
[file m.py] |
| 349 |
class A: |
| 350 |
def f(self) -> None: pass |
| 351 |
def g(self) -> None: pass |
| 352 |
[file m.py.2] |
| 353 |
class A: pass |
| 354 |
[file m.py.3] |
| 355 |
class A: |
| 356 |
def f(self) -> None: pass |
| 357 |
[out] |
| 358 |
== |
| 359 |
main:3: error: "A" has no attribute "f" |
| 360 |
n.py:2: error: "A" has no attribute "g" |
| 361 |
== |
| 362 |
n.py:2: error: "A" has no attribute "g" |
| 363 |
|
| 364 |
[case testContinueToReportErrorAtTopLevel2-only_when_cache] |
| 365 |
-- Different cache/no-cache tests because: |
| 366 |
-- Error message ordering differs |
| 367 |
import n |
| 368 |
import m |
| 369 |
m.A().f() |
| 370 |
[file n.py] |
| 371 |
import m |
| 372 |
m.A().g() |
| 373 |
[file m.py] |
| 374 |
class A: |
| 375 |
def f(self) -> None: pass |
| 376 |
def g(self) -> None: pass |
| 377 |
[file m.py.2] |
| 378 |
class A: pass |
| 379 |
[file m.py.3] |
| 380 |
class A: |
| 381 |
def f(self) -> None: pass |
| 382 |
[out] |
| 383 |
== |
| 384 |
n.py:2: error: "A" has no attribute "g" |
| 385 |
main:3: error: "A" has no attribute "f" |
| 386 |
== |
| 387 |
n.py:2: error: "A" has no attribute "g" |
| 388 |
|
| 389 |
[case testContinueToReportErrorInMethod] |
| 390 |
import m |
| 391 |
class C: |
| 392 |
def f(self, a: m.A) -> None: |
| 393 |
a.f() |
| 394 |
def g(self, a: m.A) -> None: |
| 395 |
a.g() |
| 396 |
[file m.py] |
| 397 |
class A: |
| 398 |
def f(self) -> None: pass |
| 399 |
def g(self) -> None: pass |
| 400 |
[file m.py.2] |
| 401 |
class A: pass |
| 402 |
[file m.py.3] |
| 403 |
class A: |
| 404 |
def f(self) -> None: pass |
| 405 |
[out] |
| 406 |
== |
| 407 |
main:4: error: "A" has no attribute "f" |
| 408 |
main:6: error: "A" has no attribute "g" |
| 409 |
== |
| 410 |
main:6: error: "A" has no attribute "g" |
| 411 |
|
| 412 |
[case testInitialBatchGeneratedError] |
| 413 |
import m |
| 414 |
def g() -> None: |
| 415 |
m.f() |
| 416 |
def h() -> None: |
| 417 |
m.g() |
| 418 |
[file m.py] |
| 419 |
def f(x: object) -> None: pass |
| 420 |
[file m.py.2] |
| 421 |
def f() -> None: pass |
| 422 |
[file m.py.3] |
| 423 |
def f() -> None: pass |
| 424 |
def g() -> None: pass |
| 425 |
[builtins fixtures/fine_grained.pyi] |
| 426 |
[out] |
| 427 |
main:3: error: Missing positional argument "x" in call to "f" |
| 428 |
main:5: error: Module has no attribute "g" |
| 429 |
== |
| 430 |
main:5: error: Module has no attribute "g" |
| 431 |
== |
| 432 |
|
| 433 |
[case testKeepReportingErrorIfNoChanges] |
| 434 |
import m |
| 435 |
def h() -> None: |
| 436 |
m.g() |
| 437 |
[file m.py] |
| 438 |
[file m.py.2] |
| 439 |
[builtins fixtures/fine_grained.pyi] |
| 440 |
[out] |
| 441 |
main:3: error: Module has no attribute "g" |
| 442 |
== |
| 443 |
main:3: error: Module has no attribute "g" |
| 444 |
|
| 445 |
[case testFixErrorAndReintroduce] |
| 446 |
import m |
| 447 |
def h() -> None: |
| 448 |
m.g() |
| 449 |
[file m.py] |
| 450 |
[file m.py.2] |
| 451 |
def g() -> None: pass |
| 452 |
[file m.py.3] |
| 453 |
[builtins fixtures/fine_grained.pyi] |
| 454 |
[out] |
| 455 |
main:3: error: Module has no attribute "g" |
| 456 |
== |
| 457 |
== |
| 458 |
main:3: error: Module has no attribute "g" |
| 459 |
|
| 460 |
[case testIgnoreWorksAfterUpdate] |
| 461 |
import a |
| 462 |
[file a.py] |
| 463 |
import b |
| 464 |
int() + str() # type: ignore |
| 465 |
[file b.py] |
| 466 |
x = 1 |
| 467 |
[file b.py.2] |
| 468 |
x = 2 |
| 469 |
[file b.py.3] |
| 470 |
x = 3 |
| 471 |
[delete b.py.4] |
| 472 |
[out] |
| 473 |
== |
| 474 |
== |
| 475 |
== |
| 476 |
a.py:1: error: Cannot find implementation or library stub for module named "b" |
| 477 |
a.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports |
| 478 |
|
| 479 |
[case testIgnoreWorksWithMissingImports] |
| 480 |
import a |
| 481 |
[file a.py] |
| 482 |
import b |
| 483 |
import xyz # type: ignore |
| 484 |
xyz.whatever |
| 485 |
[file b.py] |
| 486 |
x = 1 |
| 487 |
[file b.py.2] |
| 488 |
x = 2 |
| 489 |
[file b.py.3] |
| 490 |
x = 3 |
| 491 |
[file xyz.py.4] |
| 492 |
[out] |
| 493 |
== |
| 494 |
== |
| 495 |
== |
| 496 |
a.py:3: error: "object" has no attribute "whatever" |
| 497 |
|
| 498 |
[case testAddedIgnoreWithMissingImports] |
| 499 |
import a |
| 500 |
[file a.py] |
| 501 |
from b import x |
| 502 |
y: int = x |
| 503 |
[file b.py] |
| 504 |
from xyz import x |
| 505 |
[file b.py.2] |
| 506 |
from xyz import x # type: ignore |
| 507 |
[file xyz.py.3] |
| 508 |
x = str() |
| 509 |
[out] |
| 510 |
b.py:1: error: Cannot find implementation or library stub for module named "xyz" |
| 511 |
b.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports |
| 512 |
== |
| 513 |
== |
| 514 |
a.py:2: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 515 |
|
| 516 |
[case testRemovedIgnoreWithMissingImport] |
| 517 |
import a |
| 518 |
[file a.py] |
| 519 |
from b import x |
| 520 |
y: int = x |
| 521 |
[file b.py] |
| 522 |
from xyz import x # type: ignore |
| 523 |
[file b.py.2] |
| 524 |
from xyz import x |
| 525 |
[file xyz.py.3] |
| 526 |
x = str() |
| 527 |
[out] |
| 528 |
== |
| 529 |
b.py:1: error: Cannot find implementation or library stub for module named "xyz" |
| 530 |
b.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports |
| 531 |
== |
| 532 |
a.py:2: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 533 |
|
| 534 |
[case testRemovedModuleUnderIgnore] |
| 535 |
import a |
| 536 |
[file a.py] |
| 537 |
import c |
| 538 |
from b import x # type: ignore |
| 539 |
y: int = x |
| 540 |
[file b.py] |
| 541 |
x = str() |
| 542 |
[file c.py] |
| 543 |
x = 1 |
| 544 |
[delete b.py.2] |
| 545 |
[file c.py.3] |
| 546 |
x = 3 |
| 547 |
[out] |
| 548 |
a.py:3: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 549 |
== |
| 550 |
== |
| 551 |
|
| 552 |
[case AddedModuleUnderIgnore] |
| 553 |
import a |
| 554 |
[file a.py] |
| 555 |
import c |
| 556 |
from b import x # type: ignore |
| 557 |
y: int = x |
| 558 |
[file c.py] |
| 559 |
x = 1 |
| 560 |
[file c.py.2] |
| 561 |
x = 2 |
| 562 |
[file b.py.3] |
| 563 |
# empty |
| 564 |
[out] |
| 565 |
== |
| 566 |
== |
| 567 |
|
| 568 |
[case testIgnoreInBetween] |
| 569 |
import a |
| 570 |
[file a.py] |
| 571 |
import b |
| 572 |
x: int = b.x |
| 573 |
[file b.py] |
| 574 |
import c |
| 575 |
x = c.C.x # type: ignore |
| 576 |
[file c.py] |
| 577 |
class C: |
| 578 |
pass |
| 579 |
[file c.py.2] |
| 580 |
class C: |
| 581 |
x: int |
| 582 |
[file c.py.3] |
| 583 |
# empty |
| 584 |
[file c.py.4] |
| 585 |
class C: |
| 586 |
x: str |
| 587 |
[out] |
| 588 |
== |
| 589 |
== |
| 590 |
== |
| 591 |
a.py:2: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 592 |
|
| 593 |
[case testIgnoredAttrReprocessedModule] |
| 594 |
import a |
| 595 |
[file a.py] |
| 596 |
import b |
| 597 |
x = b.x # type: ignore |
| 598 |
y: int = x |
| 599 |
[file b.py] |
| 600 |
import c |
| 601 |
[file b.py.2] |
| 602 |
import c |
| 603 |
x = c.x |
| 604 |
[file c.py] |
| 605 |
x: str |
| 606 |
[out] |
| 607 |
== |
| 608 |
a.py:3: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 609 |
|
| 610 |
[case testIgnoredAttrReprocessedBase] |
| 611 |
import a |
| 612 |
[file a.py] |
| 613 |
import b |
| 614 |
def fun() -> None: |
| 615 |
x = b.C.x # type: ignore |
| 616 |
y: int = x |
| 617 |
[file b.py] |
| 618 |
import c |
| 619 |
class C: |
| 620 |
pass |
| 621 |
[file b.py.2] |
| 622 |
import c |
| 623 |
class C(c.B): |
| 624 |
pass |
| 625 |
[file c.py] |
| 626 |
class B: |
| 627 |
x: str |
| 628 |
[out] |
| 629 |
== |
| 630 |
a.py:4: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 631 |
|
| 632 |
[case testIgnoredAttrReprocessedMeta] |
| 633 |
import a |
| 634 |
[file a.py] |
| 635 |
import b |
| 636 |
def fun() -> None: |
| 637 |
x = b.C.x # type: ignore |
| 638 |
y: int = x |
| 639 |
[file b.py] |
| 640 |
import c |
| 641 |
class C: |
| 642 |
pass |
| 643 |
[file b.py.2] |
| 644 |
import c |
| 645 |
class C(metaclass=c.M): |
| 646 |
pass |
| 647 |
[file c.py] |
| 648 |
class M(type): |
| 649 |
x: str |
| 650 |
[out] |
| 651 |
== |
| 652 |
a.py:4: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 653 |
|
| 654 |
[case testDataclassUpdate1] |
| 655 |
[file a.py] |
| 656 |
from dataclasses import dataclass |
| 657 |
|
| 658 |
@dataclass |
| 659 |
class A: |
| 660 |
x: int |
| 661 |
|
| 662 |
[file b.py] |
| 663 |
from dataclasses import dataclass |
| 664 |
|
| 665 |
from a import A |
| 666 |
@dataclass |
| 667 |
class B(A): |
| 668 |
y: int |
| 669 |
|
| 670 |
B(1, 2) |
| 671 |
|
| 672 |
[file a.py.2] |
| 673 |
from dataclasses import dataclass |
| 674 |
|
| 675 |
@dataclass |
| 676 |
class A: |
| 677 |
x: str |
| 678 |
|
| 679 |
[file a.py.3] |
| 680 |
from dataclasses import dataclass |
| 681 |
|
| 682 |
@dataclass |
| 683 |
class A: |
| 684 |
x: int |
| 685 |
|
| 686 |
[out] |
| 687 |
== |
| 688 |
b.py:8: error: Argument 1 to "B" has incompatible type "int"; expected "str" |
| 689 |
== |
| 690 |
[builtins fixtures/dataclasses.pyi] |
| 691 |
|
| 692 |
[case testDataclassUpdate2] |
| 693 |
[file c.py] |
| 694 |
Foo = int |
| 695 |
|
| 696 |
[file c.py.2] |
| 697 |
Foo = str |
| 698 |
|
| 699 |
[file a.py] |
| 700 |
from dataclasses import dataclass |
| 701 |
from c import Foo |
| 702 |
|
| 703 |
@dataclass |
| 704 |
class A: |
| 705 |
x: Foo |
| 706 |
|
| 707 |
[file b.py] |
| 708 |
from dataclasses import dataclass |
| 709 |
|
| 710 |
from a import A |
| 711 |
@dataclass |
| 712 |
class B(A): |
| 713 |
y: int |
| 714 |
|
| 715 |
B(1, 2) |
| 716 |
|
| 717 |
[out] |
| 718 |
== |
| 719 |
b.py:8: error: Argument 1 to "B" has incompatible type "int"; expected "str" |
| 720 |
[builtins fixtures/dataclasses.pyi] |
| 721 |
|
| 722 |
[case testDataclassUpdate3] |
| 723 |
from b import B |
| 724 |
B(1, 2) |
| 725 |
[file b.py] |
| 726 |
from a import A |
| 727 |
from dataclasses import dataclass |
| 728 |
@dataclass |
| 729 |
class B(A): |
| 730 |
b: int |
| 731 |
[file a.py] |
| 732 |
from dataclasses import dataclass |
| 733 |
@dataclass |
| 734 |
class A: |
| 735 |
a: int |
| 736 |
|
| 737 |
[file a.py.2] |
| 738 |
from dataclasses import dataclass |
| 739 |
@dataclass |
| 740 |
class A: |
| 741 |
a: int |
| 742 |
other: int |
| 743 |
[builtins fixtures/dataclasses.pyi] |
| 744 |
[out] |
| 745 |
== |
| 746 |
main:2: error: Missing positional argument "b" in call to "B" |
| 747 |
|
| 748 |
[case testDataclassUpdate4] |
| 749 |
from b import B |
| 750 |
B(1, 2) |
| 751 |
[file b.py] |
| 752 |
from a import A |
| 753 |
from dataclasses import dataclass |
| 754 |
@dataclass(frozen=True) |
| 755 |
class B(A): |
| 756 |
b: int |
| 757 |
[file a.py] |
| 758 |
from dataclasses import dataclass |
| 759 |
@dataclass(frozen=True) |
| 760 |
class A: |
| 761 |
a: int |
| 762 |
|
| 763 |
[file a.py.2] |
| 764 |
from dataclasses import dataclass |
| 765 |
@dataclass(frozen=True) |
| 766 |
class A: |
| 767 |
a: int |
| 768 |
other: int |
| 769 |
[builtins fixtures/dataclasses.pyi] |
| 770 |
[out] |
| 771 |
== |
| 772 |
main:2: error: Missing positional argument "b" in call to "B" |
| 773 |
|
| 774 |
[case testDataclassUpdate5] |
| 775 |
from b import B |
| 776 |
B(1, 2) |
| 777 |
[file b.py] |
| 778 |
from a import A |
| 779 |
from dataclasses import dataclass |
| 780 |
@dataclass |
| 781 |
class B(A): |
| 782 |
b: int |
| 783 |
[file a.py] |
| 784 |
from dataclasses import dataclass |
| 785 |
@dataclass(init=False) |
| 786 |
class A: |
| 787 |
a: int |
| 788 |
|
| 789 |
[file a.py.2] |
| 790 |
from dataclasses import dataclass |
| 791 |
@dataclass(init=False) |
| 792 |
class A: |
| 793 |
a: int |
| 794 |
other: int |
| 795 |
|
| 796 |
[file a.py.3] |
| 797 |
from dataclasses import dataclass |
| 798 |
@dataclass(init=False) |
| 799 |
class A: |
| 800 |
a: int |
| 801 |
|
| 802 |
[builtins fixtures/dataclasses.pyi] |
| 803 |
[out] |
| 804 |
== |
| 805 |
main:2: error: Missing positional argument "b" in call to "B" |
| 806 |
== |
| 807 |
|
| 808 |
[case testDataclassUpdate6] |
| 809 |
from b import B |
| 810 |
B(1, 2) < B(1, 2) |
| 811 |
[file b.py] |
| 812 |
from a import A |
| 813 |
from dataclasses import dataclass |
| 814 |
@dataclass |
| 815 |
class B(A): |
| 816 |
b: int |
| 817 |
[file a.py] |
| 818 |
from dataclasses import dataclass |
| 819 |
@dataclass(order=True) |
| 820 |
class A: |
| 821 |
a: int |
| 822 |
|
| 823 |
[file a.py.2] |
| 824 |
from dataclasses import dataclass |
| 825 |
@dataclass |
| 826 |
class A: |
| 827 |
a: int |
| 828 |
[builtins fixtures/dataclasses.pyi] |
| 829 |
[out] |
| 830 |
== |
| 831 |
main:2: error: Unsupported left operand type for < ("B") |
| 832 |
|
| 833 |
[case testDataclassUpdate8] |
| 834 |
from c import C |
| 835 |
C(1, 2, 3) |
| 836 |
[file c.py] |
| 837 |
from b import B |
| 838 |
from dataclasses import dataclass |
| 839 |
@dataclass |
| 840 |
class C(B): |
| 841 |
c: int |
| 842 |
[file b.py] |
| 843 |
from a import A |
| 844 |
from dataclasses import dataclass |
| 845 |
@dataclass |
| 846 |
class B(A): |
| 847 |
b: int |
| 848 |
[file a.py] |
| 849 |
from dataclasses import dataclass |
| 850 |
@dataclass |
| 851 |
class A: |
| 852 |
a: int |
| 853 |
|
| 854 |
[file a.py.2] |
| 855 |
from dataclasses import dataclass |
| 856 |
@dataclass |
| 857 |
class A: |
| 858 |
a: int |
| 859 |
other: int |
| 860 |
[builtins fixtures/dataclasses.pyi] |
| 861 |
[out] |
| 862 |
== |
| 863 |
main:2: error: Missing positional argument "c" in call to "C" |
| 864 |
|
| 865 |
[case testDataclassUpdate9] |
| 866 |
from c import C |
| 867 |
C(1, 2, 3) |
| 868 |
[file c.py] |
| 869 |
from b import B |
| 870 |
from dataclasses import dataclass |
| 871 |
@dataclass |
| 872 |
class C(B): |
| 873 |
c: int |
| 874 |
[file b.py] |
| 875 |
from a import A |
| 876 |
from dataclasses import dataclass |
| 877 |
@dataclass |
| 878 |
class B(A): |
| 879 |
b: int |
| 880 |
[file a.py] |
| 881 |
from dataclasses import dataclass |
| 882 |
@dataclass(init=False) |
| 883 |
class A: |
| 884 |
a: int |
| 885 |
|
| 886 |
[file a.py.2] |
| 887 |
from dataclasses import dataclass |
| 888 |
@dataclass(init=False) |
| 889 |
class A: |
| 890 |
a: int |
| 891 |
other: int |
| 892 |
|
| 893 |
[file a.py.3] |
| 894 |
from dataclasses import dataclass |
| 895 |
@dataclass(init=False) |
| 896 |
class A: |
| 897 |
a: int |
| 898 |
|
| 899 |
[builtins fixtures/dataclasses.pyi] |
| 900 |
[out] |
| 901 |
== |
| 902 |
main:2: error: Missing positional argument "c" in call to "C" |
| 903 |
== |
| 904 |
|
| 905 |
[case testAttrsUpdate1] |
| 906 |
[file a.py] |
| 907 |
import attr |
| 908 |
@attr.s |
| 909 |
class A: |
| 910 |
a = attr.ib() # type: int |
| 911 |
|
| 912 |
[file b.py] |
| 913 |
from a import A |
| 914 |
import attr |
| 915 |
@attr.s |
| 916 |
class B(A): |
| 917 |
b = attr.ib() # type: int |
| 918 |
|
| 919 |
B(1, 2) |
| 920 |
|
| 921 |
[file a.py.2] |
| 922 |
import attr |
| 923 |
@attr.s |
| 924 |
class A: |
| 925 |
a = attr.ib() # type: int |
| 926 |
other = attr.ib() # type: int |
| 927 |
[builtins fixtures/list.pyi] |
| 928 |
[out] |
| 929 |
== |
| 930 |
b.py:7: error: Missing positional argument "b" in call to "B" |
| 931 |
|
| 932 |
[case testAttrsUpdate2] |
| 933 |
from b import B |
| 934 |
B(1, 2) |
| 935 |
[file b.py] |
| 936 |
from a import A |
| 937 |
import attr |
| 938 |
@attr.s |
| 939 |
class B(A): |
| 940 |
b = attr.ib() # type: int |
| 941 |
[file a.py] |
| 942 |
import attr |
| 943 |
@attr.s(init=False) |
| 944 |
class A: |
| 945 |
a = attr.ib() # type: int |
| 946 |
|
| 947 |
[file a.py.2] |
| 948 |
import attr |
| 949 |
@attr.s(init=False) |
| 950 |
class A: |
| 951 |
a = attr.ib() # type: int |
| 952 |
other = attr.ib() # type: int |
| 953 |
[builtins fixtures/list.pyi] |
| 954 |
[out] |
| 955 |
== |
| 956 |
main:2: error: Missing positional argument "b" in call to "B" |
| 957 |
|
| 958 |
[case testAttrsUpdate3] |
| 959 |
from b import B |
| 960 |
B(1, 2) |
| 961 |
[file b.py] |
| 962 |
from a import A |
| 963 |
import attr |
| 964 |
@attr.s(auto_attribs=True) |
| 965 |
class B(A): |
| 966 |
x: int |
| 967 |
[file a.py] |
| 968 |
import attr |
| 969 |
@attr.s(auto_attribs=True, init=False) |
| 970 |
class A: |
| 971 |
a: int |
| 972 |
|
| 973 |
[file a.py.2] |
| 974 |
import attr |
| 975 |
@attr.s(auto_attribs=True, init=False) |
| 976 |
class A: |
| 977 |
a: int |
| 978 |
other: int |
| 979 |
|
| 980 |
[file a.py.3] |
| 981 |
import attr |
| 982 |
@attr.s(auto_attribs=True, init=False) |
| 983 |
class A: |
| 984 |
a: int |
| 985 |
[builtins fixtures/list.pyi] |
| 986 |
|
| 987 |
[out] |
| 988 |
== |
| 989 |
main:2: error: Missing positional argument "x" in call to "B" |
| 990 |
== |
| 991 |
|
| 992 |
[case testAttrsUpdate4] |
| 993 |
from b import B |
| 994 |
B(1, 2) < B(1, 2) |
| 995 |
[file b.py] |
| 996 |
from a import A |
| 997 |
import attr |
| 998 |
@attr.s(eq=False) |
| 999 |
class B(A): |
| 1000 |
b = attr.ib() # type: int |
| 1001 |
[file a.py] |
| 1002 |
import attr |
| 1003 |
@attr.s(init=False) |
| 1004 |
class A: |
| 1005 |
a = attr.ib() # type: int |
| 1006 |
|
| 1007 |
[file a.py.2] |
| 1008 |
import attr |
| 1009 |
@attr.s(eq=False, init=False) |
| 1010 |
class A: |
| 1011 |
a = attr.ib() # type: int |
| 1012 |
[builtins fixtures/list.pyi] |
| 1013 |
[out] |
| 1014 |
== |
| 1015 |
main:2: error: Unsupported left operand type for < ("B") |
| 1016 |
|
| 1017 |
[case testAttrsUpdateBaseKwOnly] |
| 1018 |
from b import B |
| 1019 |
B(5) |
| 1020 |
[file a.py] |
| 1021 |
import attr |
| 1022 |
@attr.s() |
| 1023 |
class A: |
| 1024 |
a = attr.ib(15) # type: int |
| 1025 |
[file b.py] |
| 1026 |
from a import A |
| 1027 |
import attr |
| 1028 |
@attr.s(kw_only=True) |
| 1029 |
class B(A): |
| 1030 |
b = attr.ib("16") # type: str |
| 1031 |
|
| 1032 |
[file a.py.2] |
| 1033 |
import attr |
| 1034 |
@attr.s(kw_only=True) |
| 1035 |
class A: |
| 1036 |
a = attr.ib(15) # type: int |
| 1037 |
[builtins fixtures/plugin_attrs.pyi] |
| 1038 |
[out] |
| 1039 |
== |
| 1040 |
main:2: error: Too many positional arguments for "B" |
| 1041 |
|
| 1042 |
[case testAddBaseClassMethodCausingInvalidOverride] |
| 1043 |
import m |
| 1044 |
class B(m.A): |
| 1045 |
def f(self) -> str: pass |
| 1046 |
[file m.py] |
| 1047 |
class A: pass |
| 1048 |
[file m.py.2] |
| 1049 |
class A: |
| 1050 |
def f(self) -> int: pass |
| 1051 |
[file n.py.3] |
| 1052 |
[out] |
| 1053 |
== |
| 1054 |
main:3: error: Return type "str" of "f" incompatible with return type "int" in supertype "m.A" |
| 1055 |
== |
| 1056 |
main:3: error: Return type "str" of "f" incompatible with return type "int" in supertype "m.A" |
| 1057 |
|
| 1058 |
[case testModifyBaseClassMethodCausingInvalidOverride] |
| 1059 |
import m |
| 1060 |
class B(m.A): |
| 1061 |
def f(self) -> str: pass |
| 1062 |
[file m.py] |
| 1063 |
class A: |
| 1064 |
def f(self) -> str: pass |
| 1065 |
[file m.py.2] |
| 1066 |
class A: |
| 1067 |
def f(self) -> int: pass |
| 1068 |
[out] |
| 1069 |
== |
| 1070 |
main:3: error: Return type "str" of "f" incompatible with return type "int" in supertype "m.A" |
| 1071 |
|
| 1072 |
[case testAddBaseClassAttributeCausingErrorInSubclass] |
| 1073 |
import m |
| 1074 |
class B(m.A): |
| 1075 |
def a(self) -> None: |
| 1076 |
x = 1 |
| 1077 |
if int(): |
| 1078 |
x = self.x |
| 1079 |
|
| 1080 |
def f(self) -> None: |
| 1081 |
self.x = 1 |
| 1082 |
|
| 1083 |
def z(self) -> None: |
| 1084 |
x = 1 |
| 1085 |
if int(): |
| 1086 |
x = self.x |
| 1087 |
[file m.py] |
| 1088 |
class A: pass |
| 1089 |
[file m.py.2] |
| 1090 |
class A: |
| 1091 |
def g(self) -> None: |
| 1092 |
self.x = 'a' |
| 1093 |
[out] |
| 1094 |
== |
| 1095 |
main:6: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 1096 |
main:9: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 1097 |
main:14: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 1098 |
|
| 1099 |
[case testChangeBaseClassAttributeType] |
| 1100 |
import m |
| 1101 |
class B(m.A): |
| 1102 |
def f(sel) -> None: |
| 1103 |
sel.x = 1 |
| 1104 |
[file m.py] |
| 1105 |
class A: |
| 1106 |
def g(self) -> None: |
| 1107 |
self.x = 1 |
| 1108 |
[file m.py.2] |
| 1109 |
class A: |
| 1110 |
def g(self) -> None: |
| 1111 |
self.x = 'a' |
| 1112 |
[out] |
| 1113 |
== |
| 1114 |
main:4: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 1115 |
|
| 1116 |
[case testRemoveAttributeInBaseClass] |
| 1117 |
import m |
| 1118 |
class B(m.A): |
| 1119 |
def f(self) -> None: |
| 1120 |
a = 1 |
| 1121 |
a = self.x |
| 1122 |
[file m.py] |
| 1123 |
class A: |
| 1124 |
def g(self) -> None: |
| 1125 |
self.x = 1 |
| 1126 |
[file m.py.2] |
| 1127 |
class A: pass |
| 1128 |
[out] |
| 1129 |
== |
| 1130 |
main:5: error: "B" has no attribute "x" |
| 1131 |
|
| 1132 |
[case testTestSignatureOfInheritedMethod] |
| 1133 |
import m |
| 1134 |
class B(m.A): |
| 1135 |
def f(self) -> None: |
| 1136 |
self.g() |
| 1137 |
[file m.py] |
| 1138 |
class A: |
| 1139 |
def g(self) -> None: pass |
| 1140 |
[file m.py.2] |
| 1141 |
class A: |
| 1142 |
def g(self, a: 'A') -> None: pass |
| 1143 |
[out] |
| 1144 |
== |
| 1145 |
main:4: error: Missing positional argument "a" in call to "g" of "A" |
| 1146 |
|
| 1147 |
[case testRemoveBaseClass] |
| 1148 |
import m |
| 1149 |
class A(m.B): |
| 1150 |
def f(self) -> None: |
| 1151 |
self.g() |
| 1152 |
self.x |
| 1153 |
self.y = 1 |
| 1154 |
[file m.py] |
| 1155 |
class C: |
| 1156 |
def g(self) -> None: |
| 1157 |
self.x = 1 |
| 1158 |
class B(C): pass |
| 1159 |
[file m.py.2] |
| 1160 |
class C: pass |
| 1161 |
class B: pass |
| 1162 |
[out] |
| 1163 |
== |
| 1164 |
main:4: error: "A" has no attribute "g" |
| 1165 |
main:5: error: "A" has no attribute "x" |
| 1166 |
|
| 1167 |
[case testRemoveBaseClass2] |
| 1168 |
import m |
| 1169 |
class A(m.B): |
| 1170 |
def f(self) -> None: |
| 1171 |
self.g() |
| 1172 |
self.x |
| 1173 |
self.y = 1 |
| 1174 |
[file m.py] |
| 1175 |
class C: |
| 1176 |
def g(self) -> None: |
| 1177 |
self.x = 1 |
| 1178 |
class B(C): pass |
| 1179 |
[file m.py.2] |
| 1180 |
class C: |
| 1181 |
def g(self) -> None: |
| 1182 |
self.x = 1 |
| 1183 |
class B: pass |
| 1184 |
[out] |
| 1185 |
== |
| 1186 |
main:4: error: "A" has no attribute "g" |
| 1187 |
main:5: error: "A" has no attribute "x" |
| 1188 |
|
| 1189 |
[case testChangeInPackage] |
| 1190 |
import m.n |
| 1191 |
def f() -> None: |
| 1192 |
m.n.g() |
| 1193 |
[file m/__init__.py] |
| 1194 |
[file m/n.py] |
| 1195 |
def g() -> None: pass |
| 1196 |
[file m/n.py.2] |
| 1197 |
def g(x: int) -> None: pass |
| 1198 |
[out] |
| 1199 |
== |
| 1200 |
main:3: error: Missing positional argument "x" in call to "g" |
| 1201 |
|
| 1202 |
[case testTriggerTargetInPackage] |
| 1203 |
import m.n |
| 1204 |
[file m/__init__.py] |
| 1205 |
[file m/n.py] |
| 1206 |
import a |
| 1207 |
def f() -> None: |
| 1208 |
a.g() |
| 1209 |
[file a.py] |
| 1210 |
def g() -> None: pass |
| 1211 |
[file a.py.2] |
| 1212 |
def g(x: int) -> None: pass |
| 1213 |
[out] |
| 1214 |
== |
| 1215 |
m/n.py:3: error: Missing positional argument "x" in call to "g" |
| 1216 |
|
| 1217 |
[case testChangeInPackage__init__] |
| 1218 |
import m |
| 1219 |
import m.n |
| 1220 |
def f() -> None: |
| 1221 |
m.g() |
| 1222 |
[file m/__init__.py] |
| 1223 |
def g() -> None: pass |
| 1224 |
[file m/__init__.py.2] |
| 1225 |
def g(x: int) -> None: pass |
| 1226 |
[file m/n.py] |
| 1227 |
[out] |
| 1228 |
== |
| 1229 |
main:4: error: Missing positional argument "x" in call to "g" |
| 1230 |
|
| 1231 |
[case testTriggerTargetInPackage__init__] |
| 1232 |
import m |
| 1233 |
import m.n |
| 1234 |
[file m/__init__.py] |
| 1235 |
import a |
| 1236 |
def f() -> None: |
| 1237 |
a.g() |
| 1238 |
[file a.py] |
| 1239 |
def g() -> None: pass |
| 1240 |
[file a.py.2] |
| 1241 |
def g(x: int) -> None: pass |
| 1242 |
[file m/n.py] |
| 1243 |
[out] |
| 1244 |
== |
| 1245 |
m/__init__.py:3: error: Missing positional argument "x" in call to "g" |
| 1246 |
|
| 1247 |
[case testModuleAttributeTypeChanges] |
| 1248 |
import m |
| 1249 |
def f() -> None: |
| 1250 |
x = 1 |
| 1251 |
if int(): |
| 1252 |
x = m.x |
| 1253 |
[file m.py] |
| 1254 |
x = 1 |
| 1255 |
[file m.py.2] |
| 1256 |
x = '' |
| 1257 |
[out] |
| 1258 |
== |
| 1259 |
main:5: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 1260 |
|
| 1261 |
[case testTwoStepsDueToModuleAttribute] |
| 1262 |
import m |
| 1263 |
x = m.f() |
| 1264 |
|
| 1265 |
def g() -> None: |
| 1266 |
y = 1 |
| 1267 |
if int(): |
| 1268 |
y = x # E |
| 1269 |
[file m.py] |
| 1270 |
def f() -> int: pass |
| 1271 |
[file m.py.2] |
| 1272 |
def f() -> str: pass |
| 1273 |
[out] |
| 1274 |
== |
| 1275 |
main:7: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 1276 |
|
| 1277 |
[case testTwoStepsDueToMultipleNamespaces] |
| 1278 |
import m |
| 1279 |
x = m.f() |
| 1280 |
|
| 1281 |
def g() -> None: |
| 1282 |
xx = 1 |
| 1283 |
if int(): |
| 1284 |
xx = x # E |
| 1285 |
|
| 1286 |
class A: |
| 1287 |
def a(self) -> None: |
| 1288 |
self.y = m.f() |
| 1289 |
def b(self) -> None: |
| 1290 |
yy = 1 |
| 1291 |
if int(): |
| 1292 |
yy = self.y |
| 1293 |
|
| 1294 |
class B: |
| 1295 |
def c(self) -> None: |
| 1296 |
self.z = m.f() |
| 1297 |
def b(self) -> None: |
| 1298 |
zz = 1 |
| 1299 |
if int(): |
| 1300 |
zz = self.z |
| 1301 |
[file m.py] |
| 1302 |
def f() -> int: pass |
| 1303 |
[file m.py.2] |
| 1304 |
def f() -> str: pass |
| 1305 |
[out] |
| 1306 |
== |
| 1307 |
main:7: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 1308 |
main:15: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 1309 |
main:23: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 1310 |
|
| 1311 |
[case testConstructorSignatureChanged] |
| 1312 |
import m |
| 1313 |
|
| 1314 |
def f() -> None: |
| 1315 |
m.A() |
| 1316 |
[file m.py] |
| 1317 |
class A: |
| 1318 |
def __init__(self) -> None: pass |
| 1319 |
[file m.py.2] |
| 1320 |
class A: |
| 1321 |
def __init__(self, x: int) -> None: pass |
| 1322 |
[out] |
| 1323 |
== |
| 1324 |
main:4: error: Missing positional argument "x" in call to "A" |
| 1325 |
|
| 1326 |
[case testConstructorSignatureChanged2] |
| 1327 |
from typing import Callable |
| 1328 |
import m |
| 1329 |
|
| 1330 |
def use(x: Callable[[], m.A]) -> None: |
| 1331 |
x() |
| 1332 |
def f() -> None: |
| 1333 |
use(m.A) |
| 1334 |
[file m.py] |
| 1335 |
class A: |
| 1336 |
def __init__(self) -> None: pass |
| 1337 |
[file m.py.2] |
| 1338 |
class A: |
| 1339 |
def __init__(self, x: int) -> None: pass |
| 1340 |
[out] |
| 1341 |
== |
| 1342 |
-- This is a bad error message |
| 1343 |
main:7: error: Argument 1 to "use" has incompatible type "type[A]"; expected "Callable[[], A]" |
| 1344 |
|
| 1345 |
[case testConstructorSignatureChanged3] |
| 1346 |
from a import C |
| 1347 |
class D(C): |
| 1348 |
def g(self) -> None: |
| 1349 |
super().__init__() |
| 1350 |
D() |
| 1351 |
[file a.py] |
| 1352 |
class C: |
| 1353 |
def __init__(self) -> None: pass |
| 1354 |
[file a.py.2] |
| 1355 |
class C: |
| 1356 |
def __init__(self, x: int) -> None: pass |
| 1357 |
[out] |
| 1358 |
== |
| 1359 |
main:4: error: Missing positional argument "x" in call to "__init__" of "C" |
| 1360 |
main:5: error: Missing positional argument "x" in call to "D" |
| 1361 |
|
| 1362 |
[case testConstructorAdded] |
| 1363 |
import m |
| 1364 |
|
| 1365 |
def f() -> None: |
| 1366 |
m.A() |
| 1367 |
[file m.py] |
| 1368 |
class A: pass |
| 1369 |
[file m.py.2] |
| 1370 |
class A: |
| 1371 |
def __init__(self, x: int) -> None: pass |
| 1372 |
[out] |
| 1373 |
== |
| 1374 |
main:4: error: Missing positional argument "x" in call to "A" |
| 1375 |
|
| 1376 |
[case testConstructorDeleted] |
| 1377 |
import m |
| 1378 |
|
| 1379 |
def f() -> None: |
| 1380 |
m.A(1) |
| 1381 |
[file m.py] |
| 1382 |
class A: |
| 1383 |
def __init__(self, x: int) -> None: pass |
| 1384 |
[file m.py.2] |
| 1385 |
class A: pass |
| 1386 |
[out] |
| 1387 |
== |
| 1388 |
main:4: error: Too many arguments for "A" |
| 1389 |
|
| 1390 |
[case testBaseClassConstructorChanged] |
| 1391 |
import m |
| 1392 |
|
| 1393 |
def f() -> None: |
| 1394 |
m.B() |
| 1395 |
[file m.py] |
| 1396 |
class A: |
| 1397 |
def __init__(self) -> None: pass |
| 1398 |
class B(A): pass |
| 1399 |
[file m.py.2] |
| 1400 |
class A: |
| 1401 |
def __init__(self, x: int) -> None: pass |
| 1402 |
class B(A): pass |
| 1403 |
[out] |
| 1404 |
== |
| 1405 |
main:4: error: Missing positional argument "x" in call to "B" |
| 1406 |
|
| 1407 |
[case testSuperField] |
| 1408 |
from a import C |
| 1409 |
class D(C): |
| 1410 |
def g(self) -> int: |
| 1411 |
return super().x |
| 1412 |
[file a.py] |
| 1413 |
class C: |
| 1414 |
def __init__(self) -> None: self.x = 12 |
| 1415 |
[file a.py.2] |
| 1416 |
class C: |
| 1417 |
def __init__(self) -> None: self.x = 'ar' |
| 1418 |
[out] |
| 1419 |
== |
| 1420 |
main:4: error: Incompatible return value type (got "str", expected "int") |
| 1421 |
|
| 1422 |
[case testImportFrom] |
| 1423 |
from m import f |
| 1424 |
|
| 1425 |
def g() -> None: |
| 1426 |
f() |
| 1427 |
[file m.py] |
| 1428 |
def f() -> None: pass |
| 1429 |
[file m.py.2] |
| 1430 |
def f(x: int) -> None: pass |
| 1431 |
[builtins fixtures/fine_grained.pyi] |
| 1432 |
[out] |
| 1433 |
== |
| 1434 |
main:4: error: Missing positional argument "x" in call to "f" |
| 1435 |
|
| 1436 |
[case testImportFrom2] |
| 1437 |
from m import f |
| 1438 |
f() |
| 1439 |
[file m.py] |
| 1440 |
def f() -> None: pass |
| 1441 |
[file m.py.2] |
| 1442 |
def f(x: int) -> None: pass |
| 1443 |
[out] |
| 1444 |
== |
| 1445 |
main:2: error: Missing positional argument "x" in call to "f" |
| 1446 |
|
| 1447 |
[case testImportFromTargetsClass] |
| 1448 |
from m import C |
| 1449 |
|
| 1450 |
def f(c: C) -> None: |
| 1451 |
c.g() |
| 1452 |
[file m.py] |
| 1453 |
class C: |
| 1454 |
def g(self) -> None: pass |
| 1455 |
[file m.py.2] |
| 1456 |
class C: |
| 1457 |
def g(self, x: int) -> None: pass |
| 1458 |
[out] |
| 1459 |
== |
| 1460 |
main:4: error: Missing positional argument "x" in call to "g" of "C" |
| 1461 |
|
| 1462 |
[case testImportFromTargetsVariable] |
| 1463 |
from m import x |
| 1464 |
|
| 1465 |
def f() -> None: |
| 1466 |
y = 1 |
| 1467 |
if int(): |
| 1468 |
y = x |
| 1469 |
[file m.py] |
| 1470 |
x = 1 |
| 1471 |
[file m.py.2] |
| 1472 |
x = '' |
| 1473 |
[out] |
| 1474 |
== |
| 1475 |
main:6: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 1476 |
|
| 1477 |
[case testImportFromSubmoduleOfPackage] |
| 1478 |
from m import n |
| 1479 |
|
| 1480 |
def f() -> None: |
| 1481 |
n.g() |
| 1482 |
[file m/__init__.py] |
| 1483 |
[file m/n.py] |
| 1484 |
def g() -> None: pass |
| 1485 |
[file m/n.py.2] |
| 1486 |
def g(x: int) -> None: pass |
| 1487 |
[out] |
| 1488 |
== |
| 1489 |
main:4: error: Missing positional argument "x" in call to "g" |
| 1490 |
|
| 1491 |
[case testImportedFunctionGetsImported] |
| 1492 |
from m import f |
| 1493 |
|
| 1494 |
def g() -> None: |
| 1495 |
f() |
| 1496 |
[file m.py] |
| 1497 |
from n import f |
| 1498 |
[file n.py] |
| 1499 |
def f() -> None: pass |
| 1500 |
[file n.py.2] |
| 1501 |
def f(x: int) -> None: pass |
| 1502 |
[out] |
| 1503 |
== |
| 1504 |
main:4: error: Missing positional argument "x" in call to "f" |
| 1505 |
|
| 1506 |
[case testNestedClassMethodSignatureChanges] |
| 1507 |
from m import A |
| 1508 |
|
| 1509 |
def f(x: A.B) -> None: |
| 1510 |
x.g() |
| 1511 |
[file m.py] |
| 1512 |
class A: |
| 1513 |
class B: |
| 1514 |
def g(self) -> None: pass |
| 1515 |
[file m.py.2] |
| 1516 |
class A: |
| 1517 |
class B: |
| 1518 |
def g(self, x: int) -> None: pass |
| 1519 |
[out] |
| 1520 |
== |
| 1521 |
main:4: error: Missing positional argument "x" in call to "g" of "B" |
| 1522 |
|
| 1523 |
[case testNestedClassAttributeTypeChanges] |
| 1524 |
from m import A |
| 1525 |
|
| 1526 |
def f(x: A.B) -> None: |
| 1527 |
z = 1 |
| 1528 |
if int(): |
| 1529 |
z = x.y |
| 1530 |
[file m.py] |
| 1531 |
class A: |
| 1532 |
class B: |
| 1533 |
def g(self) -> None: |
| 1534 |
self.y = 1 |
| 1535 |
[file m.py.2] |
| 1536 |
class A: |
| 1537 |
class B: |
| 1538 |
def g(self) -> None: |
| 1539 |
self.y = '' |
| 1540 |
[out] |
| 1541 |
== |
| 1542 |
main:6: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 1543 |
|
| 1544 |
[case testReprocessMethodInNestedClass] |
| 1545 |
from m import f |
| 1546 |
|
| 1547 |
class A: |
| 1548 |
class B: |
| 1549 |
def g(self) -> None: |
| 1550 |
x = 1 |
| 1551 |
if int(): |
| 1552 |
x = f() |
| 1553 |
[file m.py] |
| 1554 |
def f() -> int: pass |
| 1555 |
[file m.py.2] |
| 1556 |
def f() -> str: pass |
| 1557 |
[file n.py.3] |
| 1558 |
[out] |
| 1559 |
== |
| 1560 |
main:8: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 1561 |
== |
| 1562 |
main:8: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 1563 |
|
| 1564 |
[case testReprocessMethodInNestedClassSemanal] |
| 1565 |
import a |
| 1566 |
[file a.py] |
| 1567 |
class A: |
| 1568 |
class B: |
| 1569 |
def g() -> None: pass |
| 1570 |
def foo(self) -> int: return 12 |
| 1571 |
[file b.py.2] |
| 1572 |
[file b.py.3] |
| 1573 |
2 |
| 1574 |
[out] |
| 1575 |
a.py:3: error: Method must have at least one argument. Did you forget the "self" argument? |
| 1576 |
== |
| 1577 |
a.py:3: error: Method must have at least one argument. Did you forget the "self" argument? |
| 1578 |
== |
| 1579 |
a.py:3: error: Method must have at least one argument. Did you forget the "self" argument? |
| 1580 |
|
| 1581 |
[case testBaseClassDeleted] |
| 1582 |
import m |
| 1583 |
|
| 1584 |
class A(m.C): |
| 1585 |
def f(self) -> None: |
| 1586 |
self.g() # No error here because m.C becomes an Any base class |
| 1587 |
def g(self) -> None: |
| 1588 |
self.x |
| 1589 |
[file m.py] |
| 1590 |
class C: |
| 1591 |
def g(self) -> None: pass |
| 1592 |
[file m.py.2] |
| 1593 |
[out] |
| 1594 |
main:7: error: "A" has no attribute "x" |
| 1595 |
== |
| 1596 |
main:3: error: Name "m.C" is not defined |
| 1597 |
|
| 1598 |
[case testBaseClassOfNestedClassDeleted] |
| 1599 |
import m |
| 1600 |
|
| 1601 |
class A: |
| 1602 |
class B(m.C): |
| 1603 |
def f(self) -> None: |
| 1604 |
self.g() # No error here because m.C becomes an Any base class |
| 1605 |
def g(self) -> None: |
| 1606 |
self.x |
| 1607 |
[file m.py] |
| 1608 |
class C: |
| 1609 |
def g(self) -> None: pass |
| 1610 |
[file m.py.2] |
| 1611 |
[out] |
| 1612 |
main:8: error: "B" has no attribute "x" |
| 1613 |
== |
| 1614 |
main:4: error: Name "m.C" is not defined |
| 1615 |
|
| 1616 |
[case testImportQualifiedModuleName] |
| 1617 |
import a |
| 1618 |
[file a.py] |
| 1619 |
import b.c |
| 1620 |
b.c.f() |
| 1621 |
[file a.py.2] |
| 1622 |
import b.c |
| 1623 |
b.c.f() # dummy change |
| 1624 |
[file b/__init__.py] |
| 1625 |
[file b/c.py] |
| 1626 |
def f() -> None: pass |
| 1627 |
[out] |
| 1628 |
== |
| 1629 |
|
| 1630 |
[case testTypeAliasRefresh] |
| 1631 |
from typing import Callable |
| 1632 |
from a import f |
| 1633 |
C = Callable[[int], str] |
| 1634 |
[file a.py] |
| 1635 |
def f() -> None: pass |
| 1636 |
[file a.py.2] |
| 1637 |
[out] |
| 1638 |
== |
| 1639 |
main:2: error: Module "a" has no attribute "f" |
| 1640 |
|
| 1641 |
[case testTypeVarRefresh] |
| 1642 |
from typing import TypeVar |
| 1643 |
from a import f |
| 1644 |
T = TypeVar('T') |
| 1645 |
[file a.py] |
| 1646 |
def f() -> None: pass |
| 1647 |
[file a.py.2] |
| 1648 |
[out] |
| 1649 |
== |
| 1650 |
main:2: error: Module "a" has no attribute "f" |
| 1651 |
|
| 1652 |
[case testRefreshTyping] |
| 1653 |
from typing import Sized |
| 1654 |
from c import A |
| 1655 |
import z |
| 1656 |
|
| 1657 |
# Force typing to get refreshed by using a protocol from it |
| 1658 |
x: Sized = A() |
| 1659 |
|
| 1660 |
[file c.py] |
| 1661 |
class D: |
| 1662 |
def __len__(self) -> int: return 0 |
| 1663 |
A = D |
| 1664 |
[file c.py.2] |
| 1665 |
class C: |
| 1666 |
def __len__(self) -> int: return 0 |
| 1667 |
A = C |
| 1668 |
[file z.py] |
| 1669 |
from typing import List |
| 1670 |
T = List[int] |
| 1671 |
[file z.py.2] |
| 1672 |
from typing import List |
| 1673 |
T = List[int] # yo |
| 1674 |
[builtins fixtures/list.pyi] |
| 1675 |
[typing fixtures/typing-medium.pyi] |
| 1676 |
[out] |
| 1677 |
== |
| 1678 |
|
| 1679 |
[case testNamedTupleRefresh] |
| 1680 |
from typing import NamedTuple |
| 1681 |
from a import f |
| 1682 |
N = NamedTuple('N', [('x', int)]) |
| 1683 |
[file a.py] |
| 1684 |
def f() -> None: pass |
| 1685 |
[file a.py.2] |
| 1686 |
[builtins fixtures/tuple.pyi] |
| 1687 |
[out] |
| 1688 |
== |
| 1689 |
main:2: error: Module "a" has no attribute "f" |
| 1690 |
|
| 1691 |
[case testModuleLevelAttributeRefresh] |
| 1692 |
from typing import Callable |
| 1693 |
from a import f |
| 1694 |
x = 1 |
| 1695 |
y = '' # type: str |
| 1696 |
[file a.py] |
| 1697 |
def f() -> None: pass |
| 1698 |
[file a.py.2] |
| 1699 |
[out] |
| 1700 |
== |
| 1701 |
main:2: error: Module "a" has no attribute "f" |
| 1702 |
|
| 1703 |
[case testClassBodyRefresh] |
| 1704 |
from a import f |
| 1705 |
class A: |
| 1706 |
x = 1 |
| 1707 |
y = '' # type: str |
| 1708 |
|
| 1709 |
def f(self) -> None: |
| 1710 |
self.x = 1 |
| 1711 |
[file a.py] |
| 1712 |
f = 1 |
| 1713 |
[file a.py.2] |
| 1714 |
[out] |
| 1715 |
== |
| 1716 |
main:1: error: Module "a" has no attribute "f" |
| 1717 |
|
| 1718 |
[case testDecoratedMethodRefresh] |
| 1719 |
from typing import Iterator, Callable, List, Optional |
| 1720 |
from a import f |
| 1721 |
import a |
| 1722 |
|
| 1723 |
def dec(f: Callable[['A'], Optional[Iterator[int]]]) -> Callable[['A', int], int]: pass |
| 1724 |
|
| 1725 |
class A: |
| 1726 |
@dec |
| 1727 |
def f(self) -> Optional[Iterator[int]]: |
| 1728 |
self.x = a.g() # type: int |
| 1729 |
return None |
| 1730 |
[builtins fixtures/list.pyi] |
| 1731 |
[file a.py] |
| 1732 |
f = 1 |
| 1733 |
def g() -> int: pass |
| 1734 |
[file a.py.2] |
| 1735 |
def f() -> None: pass |
| 1736 |
def g() -> int: pass |
| 1737 |
[file a.py.3] |
| 1738 |
def f() -> None: pass |
| 1739 |
def g() -> str: pass |
| 1740 |
[out] |
| 1741 |
== |
| 1742 |
== |
| 1743 |
main:10: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 1744 |
|
| 1745 |
[case testTwoPassTypeChecking] |
| 1746 |
import a |
| 1747 |
[file a.py] |
| 1748 |
[file a.py.2] |
| 1749 |
class A: |
| 1750 |
def __init__(self, b: B) -> None: |
| 1751 |
self.a = b.a |
| 1752 |
|
| 1753 |
class B: |
| 1754 |
def __init__(self) -> None: |
| 1755 |
self.a = int() |
| 1756 |
[file a.py.3] |
| 1757 |
class A: |
| 1758 |
def __init__(self, b: B) -> None: |
| 1759 |
self.a = b.a |
| 1760 |
reveal_type(self.a) # E |
| 1761 |
|
| 1762 |
class B: |
| 1763 |
def __init__(self) -> None: |
| 1764 |
self.a = int() |
| 1765 |
[out] |
| 1766 |
== |
| 1767 |
== |
| 1768 |
a.py:4: note: Revealed type is "builtins.int" |
| 1769 |
|
| 1770 |
[case testStripRevealType] |
| 1771 |
import a |
| 1772 |
reveal_type(a.f()) |
| 1773 |
[file a.py] |
| 1774 |
def f() -> int: pass |
| 1775 |
[file a.py.2] |
| 1776 |
def f() -> str: pass |
| 1777 |
[out] |
| 1778 |
main:2: note: Revealed type is "builtins.int" |
| 1779 |
== |
| 1780 |
main:2: note: Revealed type is "builtins.str" |
| 1781 |
|
| 1782 |
[case testDecoratorTypeAfterReprocessing] |
| 1783 |
import a |
| 1784 |
reveal_type(a.f()) |
| 1785 |
[file a.py] |
| 1786 |
from contextlib import contextmanager |
| 1787 |
from typing import Iterator |
| 1788 |
import b |
| 1789 |
@contextmanager |
| 1790 |
def f() -> Iterator[None]: |
| 1791 |
yield |
| 1792 |
[file b.py] |
| 1793 |
[delete b.py.2] |
| 1794 |
[file b.py.3] |
| 1795 |
[typing fixtures/typing-medium.pyi] |
| 1796 |
[builtins fixtures/list.pyi] |
| 1797 |
[triggered] |
| 1798 |
2: <b>, <b[wildcard]>, __main__ |
| 1799 |
3: <b>, <b[wildcard]>, __main__, a |
| 1800 |
[out] |
| 1801 |
main:2: note: Revealed type is "contextlib.GeneratorContextManager[None]" |
| 1802 |
== |
| 1803 |
main:2: note: Revealed type is "contextlib.GeneratorContextManager[None]" |
| 1804 |
a.py:3: error: Cannot find implementation or library stub for module named "b" |
| 1805 |
a.py:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports |
| 1806 |
== |
| 1807 |
main:2: note: Revealed type is "contextlib.GeneratorContextManager[None]" |
| 1808 |
|
| 1809 |
[case testDecoratorSpecialCase1] |
| 1810 |
import a |
| 1811 |
[file a.py] |
| 1812 |
import contextlib |
| 1813 |
from typing import List, Iterator |
| 1814 |
|
| 1815 |
@contextlib.contextmanager |
| 1816 |
def f(x: List[int]) -> Iterator[None]: |
| 1817 |
x.append(1) |
| 1818 |
yield |
| 1819 |
|
| 1820 |
def g() -> None: |
| 1821 |
import b |
| 1822 |
b.h(1) |
| 1823 |
[file b.py] |
| 1824 |
def h() -> None: pass |
| 1825 |
[delete b.py.2] |
| 1826 |
[file b.py.3] |
| 1827 |
def h() -> None: pass |
| 1828 |
[file a.py.4] |
| 1829 |
import contextlib |
| 1830 |
from typing import List, Iterator |
| 1831 |
|
| 1832 |
@contextlib.contextmanager |
| 1833 |
def f(x: List[int]) -> Iterator[None]: |
| 1834 |
x.append(1) |
| 1835 |
yield |
| 1836 |
|
| 1837 |
def g() -> None: |
| 1838 |
import b |
| 1839 |
b.h(1) |
| 1840 |
pass |
| 1841 |
[typing fixtures/typing-medium.pyi] |
| 1842 |
[builtins fixtures/list.pyi] |
| 1843 |
[triggered] |
| 1844 |
2: <b.h>, <b>, <b[wildcard]>, a.g |
| 1845 |
3: <b.h>, <b>, <b[wildcard]>, a |
| 1846 |
4: a.g |
| 1847 |
[out] |
| 1848 |
a.py:11: error: Too many arguments for "h" |
| 1849 |
== |
| 1850 |
a.py:10: error: Cannot find implementation or library stub for module named "b" |
| 1851 |
a.py:10: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports |
| 1852 |
== |
| 1853 |
a.py:11: error: Too many arguments for "h" |
| 1854 |
== |
| 1855 |
a.py:11: error: Too many arguments for "h" |
| 1856 |
|
| 1857 |
[case testDecoratorSpecialCase2] |
| 1858 |
import a |
| 1859 |
[file a.py] |
| 1860 |
from contextlib import contextmanager |
| 1861 |
from typing import Iterator, List |
| 1862 |
import b |
| 1863 |
|
| 1864 |
@contextmanager |
| 1865 |
def f(x: List[int]) -> Iterator[None]: |
| 1866 |
x.append(1) |
| 1867 |
yield |
| 1868 |
[file b.py] |
| 1869 |
[delete b.py.2] |
| 1870 |
[file b.py.3] |
| 1871 |
[file a.py.4] |
| 1872 |
from contextlib import contextmanager |
| 1873 |
from typing import Iterator, List |
| 1874 |
import b |
| 1875 |
|
| 1876 |
@contextmanager |
| 1877 |
def f(x: List[int]) -> Iterator[None]: |
| 1878 |
x.append(1) |
| 1879 |
yield |
| 1880 |
[typing fixtures/typing-medium.pyi] |
| 1881 |
[builtins fixtures/list.pyi] |
| 1882 |
[out] |
| 1883 |
== |
| 1884 |
a.py:3: error: Cannot find implementation or library stub for module named "b" |
| 1885 |
a.py:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports |
| 1886 |
== |
| 1887 |
== |
| 1888 |
|
| 1889 |
[case testDecoratorMethodCompat] |
| 1890 |
from typing import Callable, List, TypeVar |
| 1891 |
import x |
| 1892 |
|
| 1893 |
class Base: pass |
| 1894 |
_Base = TypeVar('_Base', bound=Base) |
| 1895 |
|
| 1896 |
def dec(f: Callable[[_Base], int]) -> Callable[[_Base], List[int]]: pass |
| 1897 |
|
| 1898 |
class B(Base): |
| 1899 |
def foo(self) -> List[int]: pass |
| 1900 |
|
| 1901 |
class A(B): |
| 1902 |
@dec |
| 1903 |
def foo(self) -> int: |
| 1904 |
x.lol() |
| 1905 |
return 12 |
| 1906 |
|
| 1907 |
[file x.py] |
| 1908 |
def lol() -> str: pass |
| 1909 |
[file x.py.2] |
| 1910 |
def lol() -> int: pass |
| 1911 |
[file x.py.3] |
| 1912 |
def lol() -> str: pass |
| 1913 |
|
| 1914 |
[builtins fixtures/list.pyi] |
| 1915 |
[out] |
| 1916 |
== |
| 1917 |
== |
| 1918 |
|
| 1919 |
[case testPreviousErrorInDecoratedFunction] |
| 1920 |
import a |
| 1921 |
[file a.py] |
| 1922 |
from typing import Callable |
| 1923 |
import b |
| 1924 |
|
| 1925 |
def dec(x: Callable[[], None]) -> Callable[[], None]: |
| 1926 |
return x |
| 1927 |
|
| 1928 |
@dec |
| 1929 |
def f() -> None: |
| 1930 |
1 + '' |
| 1931 |
[file b.py] |
| 1932 |
[file b.py.2] |
| 1933 |
1 |
| 1934 |
[file b.py.3] |
| 1935 |
2 |
| 1936 |
[file a.py.4] |
| 1937 |
from typing import Callable |
| 1938 |
import b |
| 1939 |
|
| 1940 |
def dec(f: Callable[[], None]) -> Callable[[], None]: |
| 1941 |
return f |
| 1942 |
|
| 1943 |
@dec |
| 1944 |
def f() -> None: |
| 1945 |
1 + 2 |
| 1946 |
[out] |
| 1947 |
a.py:9: error: Unsupported operand types for + ("int" and "str") |
| 1948 |
== |
| 1949 |
a.py:9: error: Unsupported operand types for + ("int" and "str") |
| 1950 |
== |
| 1951 |
a.py:9: error: Unsupported operand types for + ("int" and "str") |
| 1952 |
== |
| 1953 |
|
| 1954 |
[case testPreviousErrorInDecoratedMethodOverride] |
| 1955 |
import a |
| 1956 |
[file a.py] |
| 1957 |
from typing import Callable |
| 1958 |
from b import B |
| 1959 |
|
| 1960 |
def dec(x: Callable[['A'], int]) -> Callable[['A'], int]: |
| 1961 |
return x |
| 1962 |
|
| 1963 |
class A(B): |
| 1964 |
@dec |
| 1965 |
def foo(self) -> int: return 12 |
| 1966 |
|
| 1967 |
[file b.py] |
| 1968 |
class B: |
| 1969 |
def foo(self) -> str: return 'hi' |
| 1970 |
[file c.py.2] |
| 1971 |
[file c.py.3] |
| 1972 |
1 |
| 1973 |
[file b.py.4] |
| 1974 |
class B: |
| 1975 |
def foo(self) -> int: return 12 |
| 1976 |
[out] |
| 1977 |
a.py:9: error: Return type "int" of "foo" incompatible with return type "str" in supertype "b.B" |
| 1978 |
== |
| 1979 |
a.py:9: error: Return type "int" of "foo" incompatible with return type "str" in supertype "b.B" |
| 1980 |
== |
| 1981 |
a.py:9: error: Return type "int" of "foo" incompatible with return type "str" in supertype "b.B" |
| 1982 |
== |
| 1983 |
|
| 1984 |
[case testPreviousErrorInMethodSemanal1] |
| 1985 |
import a |
| 1986 |
[file a.py] |
| 1987 |
class A: |
| 1988 |
def foo() -> int: pass |
| 1989 |
[file c.py.2] |
| 1990 |
[file c.py.3] |
| 1991 |
1 |
| 1992 |
[file a.py.4] |
| 1993 |
class A: |
| 1994 |
def foo(self) -> int: pass |
| 1995 |
[out] |
| 1996 |
a.py:2: error: Method must have at least one argument. Did you forget the "self" argument? |
| 1997 |
== |
| 1998 |
a.py:2: error: Method must have at least one argument. Did you forget the "self" argument? |
| 1999 |
== |
| 2000 |
a.py:2: error: Method must have at least one argument. Did you forget the "self" argument? |
| 2001 |
== |
| 2002 |
|
| 2003 |
[case testPreviousErrorInMethodSemanal2] |
| 2004 |
import a |
| 2005 |
[file a.py] |
| 2006 |
class A: |
| 2007 |
def foo(self) -> None: |
| 2008 |
nothing |
| 2009 |
[file c.py.2] |
| 2010 |
[file c.py.3] |
| 2011 |
1 |
| 2012 |
[file a.py.4] |
| 2013 |
class A: |
| 2014 |
def foo(self) -> int: pass |
| 2015 |
[out] |
| 2016 |
a.py:3: error: Name "nothing" is not defined |
| 2017 |
== |
| 2018 |
a.py:3: error: Name "nothing" is not defined |
| 2019 |
== |
| 2020 |
a.py:3: error: Name "nothing" is not defined |
| 2021 |
== |
| 2022 |
|
| 2023 |
[case testPreviousErrorInMethodSemanalPass3] |
| 2024 |
import a |
| 2025 |
[file a.py] |
| 2026 |
from typing import List |
| 2027 |
class A: |
| 2028 |
def __init__(self) -> None: |
| 2029 |
self.x = [] # type: List[int, str] |
| 2030 |
[file c.py.2] |
| 2031 |
[file c.py.3] |
| 2032 |
1 |
| 2033 |
[file a.py.4] |
| 2034 |
from typing import List |
| 2035 |
class A: |
| 2036 |
def __init__(self) -> None: |
| 2037 |
self.x = [] # type: List[int] |
| 2038 |
[builtins fixtures/list.pyi] |
| 2039 |
[out] |
| 2040 |
a.py:4: error: "list" expects 1 type argument, but 2 given |
| 2041 |
== |
| 2042 |
a.py:4: error: "list" expects 1 type argument, but 2 given |
| 2043 |
== |
| 2044 |
a.py:4: error: "list" expects 1 type argument, but 2 given |
| 2045 |
== |
| 2046 |
|
| 2047 |
[case testPreviousErrorInOverloadedFunctionSemanalPass3] |
| 2048 |
import a |
| 2049 |
[file a.py] |
| 2050 |
from typing import overload, List |
| 2051 |
@overload |
| 2052 |
def f(x: str) -> None: ... |
| 2053 |
@overload |
| 2054 |
def f(x: int) -> List[int, str]: ... |
| 2055 |
def f(x: object) -> object: |
| 2056 |
pass |
| 2057 |
[file c.py.2] |
| 2058 |
[file c.py.3] |
| 2059 |
1 |
| 2060 |
[file a.py.4] |
| 2061 |
from typing import overload, List |
| 2062 |
@overload |
| 2063 |
def f(x: str) -> None: ... |
| 2064 |
@overload |
| 2065 |
def f(x: int) -> List[int]: ... |
| 2066 |
def f(x: object) -> object: |
| 2067 |
pass |
| 2068 |
[builtins fixtures/list.pyi] |
| 2069 |
[out] |
| 2070 |
a.py:5: error: "list" expects 1 type argument, but 2 given |
| 2071 |
== |
| 2072 |
a.py:5: error: "list" expects 1 type argument, but 2 given |
| 2073 |
== |
| 2074 |
a.py:5: error: "list" expects 1 type argument, but 2 given |
| 2075 |
== |
| 2076 |
|
| 2077 |
[case testPreviousErrorInOverloadedFunction] |
| 2078 |
import a |
| 2079 |
[file a.py] |
| 2080 |
from typing import overload |
| 2081 |
@overload |
| 2082 |
def f(x: str) -> None: ... |
| 2083 |
@overload |
| 2084 |
def f(x: int) -> int: ... |
| 2085 |
def f(x: object) -> None: |
| 2086 |
pass |
| 2087 |
[file b.py] |
| 2088 |
[file b.py.2] |
| 2089 |
1 |
| 2090 |
[file b.py.3] |
| 2091 |
2 |
| 2092 |
[file a.py.4] |
| 2093 |
from typing import overload |
| 2094 |
@overload |
| 2095 |
def f(x: str) -> None: ... |
| 2096 |
@overload |
| 2097 |
def f(x: int) -> None: ... |
| 2098 |
def f(x: object) -> None: |
| 2099 |
pass |
| 2100 |
[out] |
| 2101 |
a.py:6: error: Overloaded function implementation cannot produce return type of signature 2 |
| 2102 |
== |
| 2103 |
a.py:6: error: Overloaded function implementation cannot produce return type of signature 2 |
| 2104 |
== |
| 2105 |
a.py:6: error: Overloaded function implementation cannot produce return type of signature 2 |
| 2106 |
== |
| 2107 |
|
| 2108 |
[case testPreviousErrorInOverloadedFunctionSemanal] |
| 2109 |
import a |
| 2110 |
[file a.py] |
| 2111 |
from typing import overload |
| 2112 |
@overload |
| 2113 |
def f(x: str) -> None: ... |
| 2114 |
@overload |
| 2115 |
def f(x: int) -> None: ... |
| 2116 |
[file b.py] |
| 2117 |
[file b.py.2] |
| 2118 |
1 |
| 2119 |
[file b.py.3] |
| 2120 |
2 |
| 2121 |
[file a.py.4] |
| 2122 |
from typing import overload |
| 2123 |
@overload |
| 2124 |
def f(x: str) -> None: ... |
| 2125 |
@overload |
| 2126 |
def f(x: int) -> None: ... |
| 2127 |
def f(x: object) -> None: |
| 2128 |
pass |
| 2129 |
[out] |
| 2130 |
a.py:2: error: An overloaded function outside a stub file must have an implementation |
| 2131 |
== |
| 2132 |
a.py:2: error: An overloaded function outside a stub file must have an implementation |
| 2133 |
== |
| 2134 |
a.py:2: error: An overloaded function outside a stub file must have an implementation |
| 2135 |
== |
| 2136 |
|
| 2137 |
[case testPreviousErrorInDecoratedMethodSemanalPass3] |
| 2138 |
import a |
| 2139 |
[file a.py] |
| 2140 |
from typing import Callable, TypeVar, Any, List |
| 2141 |
|
| 2142 |
T = TypeVar('T', bound=Callable) |
| 2143 |
def dec(x: T) -> T: |
| 2144 |
return x |
| 2145 |
|
| 2146 |
@dec |
| 2147 |
def foo(self) -> List[str, int]: return [] |
| 2148 |
|
| 2149 |
[file c.py.2] |
| 2150 |
[file c.py.3] |
| 2151 |
[file a.py.4] |
| 2152 |
from typing import Callable, TypeVar, Any, List |
| 2153 |
|
| 2154 |
T = TypeVar('T', bound=Callable[..., Any]) |
| 2155 |
def dec(x: T) -> T: |
| 2156 |
return x |
| 2157 |
|
| 2158 |
@dec |
| 2159 |
def foo(self) -> List[str]: return [] |
| 2160 |
[builtins fixtures/list.pyi] |
| 2161 |
[out] |
| 2162 |
a.py:8: error: "list" expects 1 type argument, but 2 given |
| 2163 |
== |
| 2164 |
a.py:8: error: "list" expects 1 type argument, but 2 given |
| 2165 |
== |
| 2166 |
a.py:8: error: "list" expects 1 type argument, but 2 given |
| 2167 |
== |
| 2168 |
|
| 2169 |
[case testDecoratorUpdateMod] |
| 2170 |
import a |
| 2171 |
[file a.py] |
| 2172 |
import mod |
| 2173 |
|
| 2174 |
@mod.deca |
| 2175 |
@mod.decb(mod.C()) |
| 2176 |
def func(x: mod.B) -> mod.B: |
| 2177 |
x.x |
| 2178 |
return x |
| 2179 |
[file mod.py] |
| 2180 |
from typing import Callable, TypeVar |
| 2181 |
F = TypeVar('F', bound=Callable) |
| 2182 |
|
| 2183 |
def deca(func: Callable[[B], B]) -> Callable[[str], str]: |
| 2184 |
pass |
| 2185 |
def decb(arg: C) -> Callable[[F], F]: |
| 2186 |
pass |
| 2187 |
class C: |
| 2188 |
pass |
| 2189 |
class B: |
| 2190 |
x: int |
| 2191 |
[file mod.py.2] |
| 2192 |
from typing import Callable, TypeVar |
| 2193 |
F = TypeVar('F', bound=Callable) |
| 2194 |
|
| 2195 |
def deca(func: Callable[[str], str]) -> Callable[[str], str]: |
| 2196 |
pass |
| 2197 |
def decb(arg: C) -> Callable[[F], F]: |
| 2198 |
pass |
| 2199 |
class C: |
| 2200 |
pass |
| 2201 |
class B: |
| 2202 |
x: int |
| 2203 |
[file mod.py.3] |
| 2204 |
from typing import Callable, TypeVar |
| 2205 |
F = TypeVar('F', bound=Callable) |
| 2206 |
|
| 2207 |
def deca(func: Callable[[B], B]) -> Callable[[str], str]: |
| 2208 |
pass |
| 2209 |
def decb(arg: C) -> Callable[[F], F]: |
| 2210 |
pass |
| 2211 |
class C: |
| 2212 |
pass |
| 2213 |
class B: |
| 2214 |
y: int |
| 2215 |
[file mod.py.4] |
| 2216 |
from typing import Callable, TypeVar |
| 2217 |
F = TypeVar('F', bound=Callable) |
| 2218 |
|
| 2219 |
def deca(func: Callable[[B], B]) -> Callable[[str], str]: |
| 2220 |
pass |
| 2221 |
def decb(arg: C) -> Callable[[F], F]: |
| 2222 |
pass |
| 2223 |
class C: |
| 2224 |
def __init__(self, x: int) -> None: |
| 2225 |
pass |
| 2226 |
class B: |
| 2227 |
x: int |
| 2228 |
[out] |
| 2229 |
== |
| 2230 |
a.py:3: error: Argument 1 to "deca" has incompatible type "Callable[[B], B]"; expected "Callable[[str], str]" |
| 2231 |
== |
| 2232 |
a.py:6: error: "B" has no attribute "x" |
| 2233 |
== |
| 2234 |
a.py:4: error: Missing positional argument "x" in call to "C" |
| 2235 |
|
| 2236 |
[case testDecoratorUpdateFunc] |
| 2237 |
import a |
| 2238 |
[file a.py] |
| 2239 |
import mod |
| 2240 |
|
| 2241 |
def outer() -> None: |
| 2242 |
@mod.deca |
| 2243 |
@mod.decb(mod.C()) |
| 2244 |
def func(x: mod.B) -> mod.B: |
| 2245 |
x.x |
| 2246 |
return x |
| 2247 |
[file mod.py] |
| 2248 |
from typing import Callable, TypeVar |
| 2249 |
F = TypeVar('F', bound=Callable) |
| 2250 |
|
| 2251 |
def deca(func: Callable[[B], B]) -> Callable[[str], str]: |
| 2252 |
pass |
| 2253 |
def decb(arg: C) -> Callable[[F], F]: |
| 2254 |
pass |
| 2255 |
class C: |
| 2256 |
pass |
| 2257 |
class B: |
| 2258 |
x: int |
| 2259 |
[file mod.py.2] |
| 2260 |
from typing import Callable, TypeVar |
| 2261 |
F = TypeVar('F', bound=Callable) |
| 2262 |
|
| 2263 |
def deca(func: Callable[[str], str]) -> Callable[[str], str]: |
| 2264 |
pass |
| 2265 |
def decb(arg: C) -> Callable[[F], F]: |
| 2266 |
pass |
| 2267 |
class C: |
| 2268 |
pass |
| 2269 |
class B: |
| 2270 |
x: int |
| 2271 |
[file mod.py.3] |
| 2272 |
from typing import Callable, TypeVar |
| 2273 |
F = TypeVar('F', bound=Callable) |
| 2274 |
|
| 2275 |
def deca(func: Callable[[B], B]) -> Callable[[str], str]: |
| 2276 |
pass |
| 2277 |
def decb(arg: C) -> Callable[[F], F]: |
| 2278 |
pass |
| 2279 |
class C: |
| 2280 |
pass |
| 2281 |
class B: |
| 2282 |
y: int |
| 2283 |
[file mod.py.4] |
| 2284 |
from typing import Callable, TypeVar |
| 2285 |
F = TypeVar('F', bound=Callable) |
| 2286 |
|
| 2287 |
def deca(func: Callable[[B], B]) -> Callable[[str], str]: |
| 2288 |
pass |
| 2289 |
def decb(arg: C) -> Callable[[F], F]: |
| 2290 |
pass |
| 2291 |
class C: |
| 2292 |
def __init__(self, x: int) -> None: |
| 2293 |
pass |
| 2294 |
class B: |
| 2295 |
x: int |
| 2296 |
[out] |
| 2297 |
== |
| 2298 |
a.py:4: error: Argument 1 to "deca" has incompatible type "Callable[[B], B]"; expected "Callable[[str], str]" |
| 2299 |
== |
| 2300 |
a.py:7: error: "B" has no attribute "x" |
| 2301 |
== |
| 2302 |
a.py:5: error: Missing positional argument "x" in call to "C" |
| 2303 |
|
| 2304 |
[case DecoratorUpdateMethod] |
| 2305 |
import a |
| 2306 |
[file a.py] |
| 2307 |
import mod |
| 2308 |
|
| 2309 |
class D: |
| 2310 |
@mod.deca |
| 2311 |
@mod.decb(mod.C()) |
| 2312 |
def func(self, x: mod.B) -> mod.B: |
| 2313 |
x.x |
| 2314 |
return x |
| 2315 |
[file mod.py] |
| 2316 |
from typing import Callable, TypeVar |
| 2317 |
F = TypeVar('F', bound=Callable) |
| 2318 |
|
| 2319 |
def deca(func: Callable[..., B]) -> Callable[..., str]: |
| 2320 |
pass |
| 2321 |
def decb(arg: C) -> Callable[[F], F]: |
| 2322 |
pass |
| 2323 |
class C: |
| 2324 |
pass |
| 2325 |
class B: |
| 2326 |
x: int |
| 2327 |
[file mod.py.2] |
| 2328 |
from typing import Callable, TypeVar |
| 2329 |
F = TypeVar('F', bound=Callable) |
| 2330 |
|
| 2331 |
def deca(func: Callable[..., str]) -> Callable[..., str]: |
| 2332 |
pass |
| 2333 |
def decb(arg: C) -> Callable[[F], F]: |
| 2334 |
pass |
| 2335 |
class C: |
| 2336 |
pass |
| 2337 |
class B: |
| 2338 |
x: int |
| 2339 |
[file mod.py.3] |
| 2340 |
from typing import Callable, TypeVar |
| 2341 |
F = TypeVar('F', bound=Callable) |
| 2342 |
|
| 2343 |
def deca(func: Callable[..., B]) -> Callable[..., str]: |
| 2344 |
pass |
| 2345 |
def decb(arg: C) -> Callable[[F], F]: |
| 2346 |
pass |
| 2347 |
class C: |
| 2348 |
pass |
| 2349 |
class B: |
| 2350 |
y: int |
| 2351 |
[file mod.py.4] |
| 2352 |
from typing import Callable, TypeVar |
| 2353 |
F = TypeVar('F', bound=Callable) |
| 2354 |
|
| 2355 |
def deca(func: Callable[..., B]) -> Callable[..., str]: |
| 2356 |
pass |
| 2357 |
def decb(arg: C) -> Callable[[F], F]: |
| 2358 |
pass |
| 2359 |
class C: |
| 2360 |
def __init__(self, x: int) -> None: |
| 2361 |
pass |
| 2362 |
class B: |
| 2363 |
x: int |
| 2364 |
[out] |
| 2365 |
== |
| 2366 |
a.py:4: error: Argument 1 to "deca" has incompatible type "Callable[[D, B], B]"; expected "Callable[..., str]" |
| 2367 |
== |
| 2368 |
a.py:7: error: "B" has no attribute "x" |
| 2369 |
== |
| 2370 |
a.py:5: error: Missing positional argument "x" in call to "C" |
| 2371 |
|
| 2372 |
[case testDecoratorUpdateDeepNested] |
| 2373 |
import a |
| 2374 |
[file a.py] |
| 2375 |
import mod |
| 2376 |
|
| 2377 |
def outer() -> None: |
| 2378 |
def inner() -> None: |
| 2379 |
@mod.dec |
| 2380 |
def func(x: int) -> int: |
| 2381 |
pass |
| 2382 |
[file mod.py] |
| 2383 |
from typing import Callable |
| 2384 |
def dec(func: Callable[[int], int]) -> Callable[[str], str]: |
| 2385 |
pass |
| 2386 |
[file mod.py.2] |
| 2387 |
from typing import Callable |
| 2388 |
def dec(func: Callable[[str], str]) -> Callable[[str], str]: |
| 2389 |
pass |
| 2390 |
[out] |
| 2391 |
== |
| 2392 |
a.py:5: error: Argument 1 to "dec" has incompatible type "Callable[[int], int]"; expected "Callable[[str], str]" |
| 2393 |
|
| 2394 |
[case testDecoratorUpdateNestedClass] |
| 2395 |
import a |
| 2396 |
[file a.py] |
| 2397 |
import mod |
| 2398 |
|
| 2399 |
class Outer: |
| 2400 |
class Inner: |
| 2401 |
c = mod.C() |
| 2402 |
@c.dec |
| 2403 |
def func(self, x: int) -> int: |
| 2404 |
pass |
| 2405 |
[file mod.py] |
| 2406 |
from typing import Callable |
| 2407 |
class C: |
| 2408 |
def dec(self, func: Callable[..., int]) -> Callable[..., str]: |
| 2409 |
pass |
| 2410 |
[file mod.py.2] |
| 2411 |
from typing import Callable |
| 2412 |
class C: |
| 2413 |
def dec(self, func: Callable[..., str]) -> Callable[..., str]: |
| 2414 |
pass |
| 2415 |
[out] |
| 2416 |
== |
| 2417 |
a.py:6: error: Argument 1 to "dec" of "C" has incompatible type "Callable[[Inner, int], int]"; expected "Callable[..., str]" |
| 2418 |
|
| 2419 |
[case testDecoratorUpdateClassInFunction] |
| 2420 |
import a |
| 2421 |
[file a.py] |
| 2422 |
import mod |
| 2423 |
|
| 2424 |
def outer() -> None: |
| 2425 |
class Inner: |
| 2426 |
c = mod.C() |
| 2427 |
@c.dec |
| 2428 |
def func(self, x: mod.B) -> int: |
| 2429 |
return x.x |
| 2430 |
[file mod.py] |
| 2431 |
from typing import Callable |
| 2432 |
class C: |
| 2433 |
def dec(self, func: Callable[..., int]) -> Callable[..., str]: |
| 2434 |
pass |
| 2435 |
class B: |
| 2436 |
x: int |
| 2437 |
[file mod.py.2] |
| 2438 |
from typing import Callable |
| 2439 |
class C: |
| 2440 |
def dec(self, func: Callable[..., str]) -> Callable[..., str]: |
| 2441 |
pass |
| 2442 |
class B: |
| 2443 |
x: int |
| 2444 |
[file mod.py.3] |
| 2445 |
from typing import Callable |
| 2446 |
class C: |
| 2447 |
def dec(self, func: Callable[..., int]) -> Callable[..., str]: |
| 2448 |
pass |
| 2449 |
class B: |
| 2450 |
x: str |
| 2451 |
[out] |
| 2452 |
== |
| 2453 |
a.py:6: error: Argument 1 to "dec" of "C" has incompatible type "Callable[[Inner, B], int]"; expected "Callable[..., str]" |
| 2454 |
== |
| 2455 |
a.py:8: error: Incompatible return value type (got "str", expected "int") |
| 2456 |
|
| 2457 |
[case testDecoratorUpdateMROUpdated] |
| 2458 |
import a |
| 2459 |
[file a.py] |
| 2460 |
import mod |
| 2461 |
|
| 2462 |
@mod.dec |
| 2463 |
def func(x: mod.B) -> int: |
| 2464 |
pass |
| 2465 |
[file mod.py] |
| 2466 |
from typing import Callable |
| 2467 |
class B: |
| 2468 |
pass |
| 2469 |
class C(B): |
| 2470 |
pass |
| 2471 |
def dec(f: Callable[[C], int]) -> Callable[[int], int]: |
| 2472 |
pass |
| 2473 |
[file mod.py.2] |
| 2474 |
from typing import Callable |
| 2475 |
class B: |
| 2476 |
pass |
| 2477 |
class C: |
| 2478 |
pass |
| 2479 |
def dec(f: Callable[[C], int]) -> Callable[[int], int]: |
| 2480 |
pass |
| 2481 |
[out] |
| 2482 |
== |
| 2483 |
a.py:3: error: Argument 1 to "dec" has incompatible type "Callable[[B], int]"; expected "Callable[[C], int]" |
| 2484 |
|
| 2485 |
[case testOverloadRefresh] |
| 2486 |
from typing import overload |
| 2487 |
import m |
| 2488 |
|
| 2489 |
@overload |
| 2490 |
def f(x: m.A) -> None: ... |
| 2491 |
@overload |
| 2492 |
def f(x: int) -> None: ... |
| 2493 |
def f(x: object) -> None: |
| 2494 |
from n import g |
| 2495 |
[file m.py] |
| 2496 |
class A: pass |
| 2497 |
[file n.py] |
| 2498 |
def g() -> None: pass |
| 2499 |
[delete m.py.2] |
| 2500 |
[delete n.py.2] |
| 2501 |
[out] |
| 2502 |
== |
| 2503 |
main:2: error: Cannot find implementation or library stub for module named "m" |
| 2504 |
main:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports |
| 2505 |
main:7: error: Overloaded function signature 2 will never be matched: signature 1's parameter type(s) are the same or broader |
| 2506 |
main:9: error: Cannot find implementation or library stub for module named "n" |
| 2507 |
|
| 2508 |
[case testOverloadSpecialCase] |
| 2509 |
from typing import overload |
| 2510 |
import m |
| 2511 |
import sys |
| 2512 |
|
| 2513 |
class C: |
| 2514 |
if sys.platform == 'nonexistent': |
| 2515 |
def f(self, x): pass |
| 2516 |
else: |
| 2517 |
@overload |
| 2518 |
def f(self, x: m.A) -> None: pass |
| 2519 |
@overload |
| 2520 |
def f(self, x: int) -> None: pass |
| 2521 |
def f(self, x: object) -> None: |
| 2522 |
from n import g |
| 2523 |
[file m.py] |
| 2524 |
class A: pass |
| 2525 |
[file n.py] |
| 2526 |
def g() -> None: pass |
| 2527 |
[delete m.py.2] |
| 2528 |
[delete n.py.2] |
| 2529 |
[builtins fixtures/ops.pyi] |
| 2530 |
[out] |
| 2531 |
== |
| 2532 |
main:2: error: Cannot find implementation or library stub for module named "m" |
| 2533 |
main:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports |
| 2534 |
main:12: error: Overloaded function signature 2 will never be matched: signature 1's parameter type(s) are the same or broader |
| 2535 |
main:14: error: Cannot find implementation or library stub for module named "n" |
| 2536 |
|
| 2537 |
[case testOverloadClassmethodDisappears] |
| 2538 |
from typing import overload |
| 2539 |
from m import Wrapper |
| 2540 |
reveal_type(Wrapper.foo(3)) |
| 2541 |
[file m.pyi] |
| 2542 |
from typing import overload |
| 2543 |
class Wrapper: |
| 2544 |
@overload |
| 2545 |
@classmethod |
| 2546 |
def foo(self, x: int) -> int: ... |
| 2547 |
@overload |
| 2548 |
@classmethod |
| 2549 |
def foo(self, x: str) -> str: ... |
| 2550 |
[file m.pyi.2] |
| 2551 |
from typing import overload |
| 2552 |
class Wrapper: |
| 2553 |
@overload |
| 2554 |
def foo(cls, x: int) -> int: ... |
| 2555 |
@overload |
| 2556 |
def foo(cls, x: str) -> str: ... |
| 2557 |
[builtins fixtures/classmethod.pyi] |
| 2558 |
[out] |
| 2559 |
main:3: note: Revealed type is "builtins.int" |
| 2560 |
== |
| 2561 |
main:3: error: No overload variant of "foo" of "Wrapper" matches argument type "int" |
| 2562 |
main:3: note: Possible overload variants: |
| 2563 |
main:3: note: def foo(cls: Wrapper, x: int) -> int |
| 2564 |
main:3: note: def foo(cls: Wrapper, x: str) -> str |
| 2565 |
main:3: note: Revealed type is "Any" |
| 2566 |
|
| 2567 |
[case testRefreshGenericClass] |
| 2568 |
from typing import TypeVar, Generic |
| 2569 |
from a import A |
| 2570 |
|
| 2571 |
X = TypeVar('X') |
| 2572 |
|
| 2573 |
class C(Generic[X]): |
| 2574 |
def f(self, x: A) -> X: ... |
| 2575 |
[file a.py] |
| 2576 |
class A: pass |
| 2577 |
[file a.py.2] |
| 2578 |
[file a.py.3] |
| 2579 |
class A: pass |
| 2580 |
[out] |
| 2581 |
== |
| 2582 |
main:2: error: Module "a" has no attribute "A" |
| 2583 |
== |
| 2584 |
|
| 2585 |
[case testRefreshGenericAndFailInPass3] |
| 2586 |
# Failure in semantic analysis pass 3 |
| 2587 |
from a import C |
| 2588 |
a: C[int] |
| 2589 |
[file a.py] |
| 2590 |
from typing import TypeVar, Generic |
| 2591 |
T = TypeVar('T') |
| 2592 |
class C(Generic[T]): pass |
| 2593 |
[file a.py.2] |
| 2594 |
from typing import TypeVar, Generic |
| 2595 |
T = TypeVar('T') |
| 2596 |
S = TypeVar('S') |
| 2597 |
class C(Generic[T, S]): pass |
| 2598 |
[file a.py.3] |
| 2599 |
from typing import TypeVar, Generic |
| 2600 |
T = TypeVar('T') |
| 2601 |
class C(Generic[T]): pass |
| 2602 |
[out] |
| 2603 |
== |
| 2604 |
main:3: error: "C" expects 2 type arguments, but 1 given |
| 2605 |
== |
| 2606 |
|
| 2607 |
[case testUnannotatedClass] |
| 2608 |
import a |
| 2609 |
[file a.py] |
| 2610 |
class A: |
| 2611 |
def f(self, x): |
| 2612 |
self.y = x |
| 2613 |
self.g() |
| 2614 |
|
| 2615 |
def g(self): pass |
| 2616 |
[file a.py.2] |
| 2617 |
class A: |
| 2618 |
def f(self, x, y): |
| 2619 |
self.y = x |
| 2620 |
self.z = y |
| 2621 |
self.g() |
| 2622 |
|
| 2623 |
def g(self): pass |
| 2624 |
[triggered] |
| 2625 |
2: <a.A.f>, <a.A.z>, <a.A[wildcard]> |
| 2626 |
[out] |
| 2627 |
== |
| 2628 |
|
| 2629 |
[case testSuperBasics] |
| 2630 |
import a |
| 2631 |
[file a.py] |
| 2632 |
class A: |
| 2633 |
def f(self) -> None: pass |
| 2634 |
class B(A): |
| 2635 |
def f(self) -> None: |
| 2636 |
super(B, self).f() |
| 2637 |
[file a.py.2] |
| 2638 |
class A: |
| 2639 |
def f(self) -> None: pass |
| 2640 |
class B(A): |
| 2641 |
def f(self) -> None: |
| 2642 |
super(B, self).f() |
| 2643 |
[out] |
| 2644 |
== |
| 2645 |
|
| 2646 |
[case testErrorInTypeCheckSecondPassThroughPropagation] |
| 2647 |
import a |
| 2648 |
|
| 2649 |
def f() -> None: |
| 2650 |
x = a.C() |
| 2651 |
[file a.py] |
| 2652 |
[file a.py.2] |
| 2653 |
from typing import Generic, TypeVar |
| 2654 |
T = TypeVar('T') |
| 2655 |
class C(Generic[T]): pass |
| 2656 |
[out] |
| 2657 |
main:4: error: "object" has no attribute "C" |
| 2658 |
== |
| 2659 |
main:4: error: Need type annotation for "x" |
| 2660 |
|
| 2661 |
[case testPartialTypeInNestedClass] |
| 2662 |
import a |
| 2663 |
class C: |
| 2664 |
def f(self) -> None: |
| 2665 |
a.g() |
| 2666 |
class D: |
| 2667 |
def __init__(self) -> None: |
| 2668 |
self.x = {} |
| 2669 |
def meth(self) -> None: |
| 2670 |
self.x['a'] = 'b' |
| 2671 |
[file a.py] |
| 2672 |
def g() -> None: pass |
| 2673 |
[file a.py.2] |
| 2674 |
def g() -> int: pass |
| 2675 |
[builtins fixtures/dict.pyi] |
| 2676 |
[out] |
| 2677 |
main:7: error: Need type annotation for "x" (hint: "x: dict[<type>, <type>] = ...") |
| 2678 |
== |
| 2679 |
main:7: error: Need type annotation for "x" (hint: "x: dict[<type>, <type>] = ...") |
| 2680 |
|
| 2681 |
[case testRefreshPartialTypeInClass] |
| 2682 |
import a |
| 2683 |
class D: |
| 2684 |
def __init__(self) -> None: |
| 2685 |
a.g() |
| 2686 |
self.x = {} |
| 2687 |
def meth(self) -> None: |
| 2688 |
self.x['a'] = 'b' |
| 2689 |
[file a.py] |
| 2690 |
def g() -> None: pass |
| 2691 |
[file a.py.2] |
| 2692 |
def g() -> int: pass |
| 2693 |
[builtins fixtures/dict.pyi] |
| 2694 |
[out] |
| 2695 |
main:5: error: Need type annotation for "x" (hint: "x: dict[<type>, <type>] = ...") |
| 2696 |
== |
| 2697 |
main:5: error: Need type annotation for "x" (hint: "x: dict[<type>, <type>] = ...") |
| 2698 |
|
| 2699 |
[case testRefreshPartialTypeInferredAttributeIndex] |
| 2700 |
from c import C |
| 2701 |
reveal_type(C().a) |
| 2702 |
[file c.py] |
| 2703 |
from b import f |
| 2704 |
class C: |
| 2705 |
def __init__(self) -> None: |
| 2706 |
self.a = {} |
| 2707 |
if bool(): |
| 2708 |
self.a[0] = f() |
| 2709 |
[file b.py] |
| 2710 |
def f() -> int: ... |
| 2711 |
[file b.py.2] |
| 2712 |
from typing import List |
| 2713 |
def f() -> str: ... |
| 2714 |
[builtins fixtures/dict.pyi] |
| 2715 |
[out] |
| 2716 |
main:2: note: Revealed type is "builtins.dict[builtins.int, builtins.int]" |
| 2717 |
== |
| 2718 |
main:2: note: Revealed type is "builtins.dict[builtins.int, builtins.str]" |
| 2719 |
|
| 2720 |
[case testRefreshPartialTypeInferredAttributeAssign] |
| 2721 |
from c import C |
| 2722 |
reveal_type(C().a) |
| 2723 |
[file c.py] |
| 2724 |
from b import f |
| 2725 |
class C: |
| 2726 |
def __init__(self) -> None: |
| 2727 |
self.a = [] |
| 2728 |
if bool(): |
| 2729 |
self.a = f() |
| 2730 |
[file b.py] |
| 2731 |
from typing import List |
| 2732 |
def f() -> List[int]: ... |
| 2733 |
[file b.py.2] |
| 2734 |
from typing import List |
| 2735 |
def f() -> List[str]: ... |
| 2736 |
[builtins fixtures/list.pyi] |
| 2737 |
[out] |
| 2738 |
main:2: note: Revealed type is "builtins.list[builtins.int]" |
| 2739 |
== |
| 2740 |
main:2: note: Revealed type is "builtins.list[builtins.str]" |
| 2741 |
|
| 2742 |
[case testRefreshPartialTypeInferredAttributeAppend] |
| 2743 |
from c import C |
| 2744 |
reveal_type(C().a) |
| 2745 |
[file c.py] |
| 2746 |
from b import f |
| 2747 |
class C: |
| 2748 |
def __init__(self) -> None: |
| 2749 |
self.a = [] |
| 2750 |
if bool(): |
| 2751 |
self.a.append(f()) |
| 2752 |
[file b.py] |
| 2753 |
def f() -> int: ... |
| 2754 |
[file b.py.2] |
| 2755 |
def f() -> str: ... |
| 2756 |
[builtins fixtures/list.pyi] |
| 2757 |
[out] |
| 2758 |
main:2: note: Revealed type is "builtins.list[builtins.int]" |
| 2759 |
== |
| 2760 |
main:2: note: Revealed type is "builtins.list[builtins.str]" |
| 2761 |
|
| 2762 |
[case testRefreshTryExcept] |
| 2763 |
import a |
| 2764 |
def f() -> None: |
| 2765 |
a.g() |
| 2766 |
try: |
| 2767 |
pass |
| 2768 |
except BaseException as e: |
| 2769 |
e |
| 2770 |
[file a.py] |
| 2771 |
def g() -> int: pass |
| 2772 |
[file a.py.2] |
| 2773 |
def g() -> str: pass |
| 2774 |
[builtins fixtures/exception.pyi] |
| 2775 |
[out] |
| 2776 |
== |
| 2777 |
|
| 2778 |
[case testMroSpecialCase] |
| 2779 |
import b |
| 2780 |
import a |
| 2781 |
|
| 2782 |
[file a.py] |
| 2783 |
class C: pass |
| 2784 |
class D(C): |
| 2785 |
1() |
| 2786 |
class E(D): pass |
| 2787 |
|
| 2788 |
[file b.py] |
| 2789 |
import a |
| 2790 |
|
| 2791 |
[file a.py.2] |
| 2792 |
class C: pass |
| 2793 |
class D(C): |
| 2794 |
1() |
| 2795 |
class E(D): pass |
| 2796 |
# Something needs to change |
| 2797 |
|
| 2798 |
[file b.py.2] |
| 2799 |
import a |
| 2800 |
# Something needs to change |
| 2801 |
|
| 2802 |
[triggered] |
| 2803 |
2: a, a |
| 2804 |
[out] |
| 2805 |
a.py:3: error: "int" not callable |
| 2806 |
== |
| 2807 |
a.py:3: error: "int" not callable |
| 2808 |
|
| 2809 |
[case testMetaclassAttributes] |
| 2810 |
import a |
| 2811 |
[file a.py] |
| 2812 |
from mod import C |
| 2813 |
from typing import Type |
| 2814 |
def f(arg: Type[C]) -> None: |
| 2815 |
arg.x = int() |
| 2816 |
[file mod.py] |
| 2817 |
import submod |
| 2818 |
class C(metaclass=submod.M): |
| 2819 |
pass |
| 2820 |
[file submod.py] |
| 2821 |
class M(type): |
| 2822 |
x: int |
| 2823 |
[file submod.py.2] |
| 2824 |
class M(type): |
| 2825 |
x: str |
| 2826 |
[file submod.py.3] |
| 2827 |
class M(type): |
| 2828 |
y: str |
| 2829 |
[file submod.py.4] |
| 2830 |
class M(type): |
| 2831 |
x: int |
| 2832 |
[out] |
| 2833 |
== |
| 2834 |
a.py:4: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 2835 |
== |
| 2836 |
a.py:4: error: "type[C]" has no attribute "x" |
| 2837 |
== |
| 2838 |
|
| 2839 |
[case testMetaclassAttributesDirect] |
| 2840 |
import a |
| 2841 |
[file a.py] |
| 2842 |
from mod import C |
| 2843 |
def f() -> None: |
| 2844 |
C.x = int() |
| 2845 |
[file mod.py] |
| 2846 |
import submod |
| 2847 |
class C(metaclass=submod.M): |
| 2848 |
pass |
| 2849 |
[file submod.py] |
| 2850 |
class M(type): |
| 2851 |
x: int |
| 2852 |
[file submod.py.2] |
| 2853 |
class M(type): |
| 2854 |
x: str |
| 2855 |
[file submod.py.3] |
| 2856 |
class M(type): |
| 2857 |
y: str |
| 2858 |
[file submod.py.4] |
| 2859 |
class M(type): |
| 2860 |
x: int |
| 2861 |
[out] |
| 2862 |
== |
| 2863 |
a.py:3: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 2864 |
== |
| 2865 |
a.py:3: error: "type[C]" has no attribute "x" |
| 2866 |
== |
| 2867 |
|
| 2868 |
[case testMetaclassOperators] |
| 2869 |
import a |
| 2870 |
[file a.py] |
| 2871 |
from mod import C |
| 2872 |
from typing import Type |
| 2873 |
def f(arg: Type[C]) -> None: |
| 2874 |
arg + arg |
| 2875 |
[file mod.py] |
| 2876 |
import submod |
| 2877 |
class C(metaclass=submod.M): |
| 2878 |
pass |
| 2879 |
[file submod.py] |
| 2880 |
class M(type): |
| 2881 |
def __add__(self, other: M) -> M: |
| 2882 |
pass |
| 2883 |
[file submod.py.2] |
| 2884 |
class M(type): |
| 2885 |
def __add__(self, other: int) -> M: |
| 2886 |
pass |
| 2887 |
[out] |
| 2888 |
== |
| 2889 |
a.py:4: error: Unsupported operand types for + ("type[C]" and "type[C]") |
| 2890 |
|
| 2891 |
[case testMetaclassOperatorsDirect] |
| 2892 |
import a |
| 2893 |
[file a.py] |
| 2894 |
from mod import C |
| 2895 |
def f() -> None: |
| 2896 |
C + C |
| 2897 |
[file mod.py] |
| 2898 |
import submod |
| 2899 |
class C(metaclass=submod.M): |
| 2900 |
pass |
| 2901 |
[file submod.py] |
| 2902 |
class M(type): |
| 2903 |
def __add__(self, other: int) -> M: |
| 2904 |
pass |
| 2905 |
[file submod.py.2] |
| 2906 |
class M(type): |
| 2907 |
def __add__(self, other: M) -> M: |
| 2908 |
pass |
| 2909 |
[out] |
| 2910 |
a.py:3: error: Unsupported operand types for + ("type[C]" and "type[C]") |
| 2911 |
== |
| 2912 |
|
| 2913 |
[case testFineMetaclassUpdate] |
| 2914 |
import a |
| 2915 |
[file a.py] |
| 2916 |
from c import M |
| 2917 |
import b |
| 2918 |
def f(arg: M) -> None: |
| 2919 |
pass |
| 2920 |
|
| 2921 |
f(b.B) |
| 2922 |
[file b.py] |
| 2923 |
import c |
| 2924 |
class B: pass |
| 2925 |
|
| 2926 |
[file b.py.2] |
| 2927 |
import c |
| 2928 |
class B(metaclass=c.M): pass |
| 2929 |
|
| 2930 |
[file c.py] |
| 2931 |
class M(type): |
| 2932 |
pass |
| 2933 |
[out] |
| 2934 |
a.py:6: error: Argument 1 to "f" has incompatible type "type[B]"; expected "M" |
| 2935 |
== |
| 2936 |
|
| 2937 |
[case testFineMetaclassRecalculation] |
| 2938 |
import a |
| 2939 |
|
| 2940 |
[file a.py] |
| 2941 |
from b import B |
| 2942 |
class M2(type): pass |
| 2943 |
class D(B, metaclass=M2): pass |
| 2944 |
|
| 2945 |
[file b.py] |
| 2946 |
import c |
| 2947 |
class B: pass |
| 2948 |
|
| 2949 |
[file b.py.2] |
| 2950 |
import c |
| 2951 |
class B(metaclass=c.M): pass |
| 2952 |
|
| 2953 |
[file c.py] |
| 2954 |
class M(type): pass |
| 2955 |
[out] |
| 2956 |
== |
| 2957 |
a.py:3: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases |
| 2958 |
a.py:3: note: "a.M2" (metaclass of "a.D") conflicts with "c.M" (metaclass of "b.B") |
| 2959 |
|
| 2960 |
[case testFineMetaclassDeclaredUpdate] |
| 2961 |
import a |
| 2962 |
|
| 2963 |
[file a.py] |
| 2964 |
import b |
| 2965 |
class B(metaclass=b.M): pass |
| 2966 |
class D(B, metaclass=b.M2): pass |
| 2967 |
|
| 2968 |
[file b.py] |
| 2969 |
class M(type): pass |
| 2970 |
class M2(M): pass |
| 2971 |
|
| 2972 |
[file b.py.2] |
| 2973 |
class M(type): pass |
| 2974 |
class M2(type): pass |
| 2975 |
[out] |
| 2976 |
== |
| 2977 |
a.py:3: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases |
| 2978 |
a.py:3: note: "b.M2" (metaclass of "a.D") conflicts with "b.M" (metaclass of "a.B") |
| 2979 |
|
| 2980 |
[case testFineMetaclassRemoveFromClass] |
| 2981 |
import a |
| 2982 |
[file a.py] |
| 2983 |
import b |
| 2984 |
def func() -> int: |
| 2985 |
return b.B.x |
| 2986 |
[file b.py] |
| 2987 |
from c import M |
| 2988 |
class B(metaclass=M): |
| 2989 |
pass |
| 2990 |
[file b.py.2] |
| 2991 |
from c import M |
| 2992 |
class B: |
| 2993 |
pass |
| 2994 |
[file c.py] |
| 2995 |
class M(type): |
| 2996 |
x: int |
| 2997 |
[out] |
| 2998 |
== |
| 2999 |
a.py:3: error: "type[B]" has no attribute "x" |
| 3000 |
|
| 3001 |
[case testFineMetaclassRemoveFromClass2] |
| 3002 |
import a |
| 3003 |
[file a.py] |
| 3004 |
import b |
| 3005 |
def func() -> None: |
| 3006 |
b.test(b.B) |
| 3007 |
[file b.py] |
| 3008 |
import c |
| 3009 |
def test(cls: c.M) -> None: |
| 3010 |
pass |
| 3011 |
class B(metaclass=c.M): |
| 3012 |
pass |
| 3013 |
[file b.py.2] |
| 3014 |
import c |
| 3015 |
def test(cls: c.M) -> None: |
| 3016 |
pass |
| 3017 |
class B: |
| 3018 |
pass |
| 3019 |
[file c.py] |
| 3020 |
class M(type): |
| 3021 |
x: int |
| 3022 |
[out] |
| 3023 |
== |
| 3024 |
a.py:3: error: Argument 1 to "test" has incompatible type "type[B]"; expected "M" |
| 3025 |
|
| 3026 |
[case testBadMetaclassCorrected] |
| 3027 |
import a |
| 3028 |
[file a.py] |
| 3029 |
import b |
| 3030 |
class C(metaclass=b.M): |
| 3031 |
pass |
| 3032 |
[file b.py] |
| 3033 |
from c import M |
| 3034 |
[file c.py] |
| 3035 |
M = 1 |
| 3036 |
[file c.py.2] |
| 3037 |
class M(type): |
| 3038 |
pass |
| 3039 |
[out] |
| 3040 |
a.py:2: error: Invalid metaclass "b.M" |
| 3041 |
== |
| 3042 |
|
| 3043 |
[case testFixedAttrOnAddedMetaclass] |
| 3044 |
import a |
| 3045 |
[file a.py] |
| 3046 |
import b |
| 3047 |
def fun() -> None: |
| 3048 |
x: int = b.C.x |
| 3049 |
[file b.py] |
| 3050 |
import c |
| 3051 |
class C: |
| 3052 |
pass |
| 3053 |
[file b.py.2] |
| 3054 |
import c |
| 3055 |
class C(metaclass=c.M): |
| 3056 |
pass |
| 3057 |
[file c.py] |
| 3058 |
class M(type): |
| 3059 |
x: int |
| 3060 |
[out] |
| 3061 |
a.py:3: error: "type[C]" has no attribute "x" |
| 3062 |
== |
| 3063 |
|
| 3064 |
[case testIndirectSubclassReferenceMetaclass] |
| 3065 |
import a |
| 3066 |
[file a.py] |
| 3067 |
import b |
| 3068 |
def f() -> None: |
| 3069 |
b.x = int() |
| 3070 |
[file b.py] |
| 3071 |
import bb |
| 3072 |
x = bb.D.x |
| 3073 |
[file bb.py] |
| 3074 |
import mod |
| 3075 |
class D(mod.C): |
| 3076 |
pass |
| 3077 |
[file mod.py] |
| 3078 |
import submod |
| 3079 |
class C(metaclass=submod.M): |
| 3080 |
pass |
| 3081 |
[file submod.py] |
| 3082 |
class M(type): |
| 3083 |
x: int |
| 3084 |
[file submod.py.2] |
| 3085 |
class M(type): |
| 3086 |
x: str |
| 3087 |
[file submod.py.3] |
| 3088 |
class M(type): |
| 3089 |
y: str |
| 3090 |
[file submod.py.4] |
| 3091 |
class M(type): |
| 3092 |
x: int |
| 3093 |
[out] |
| 3094 |
== |
| 3095 |
a.py:3: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 3096 |
== |
| 3097 |
b.py:2: error: "type[D]" has no attribute "x" |
| 3098 |
== |
| 3099 |
|
| 3100 |
[case testMetaclassDeletion] |
| 3101 |
import a |
| 3102 |
[file a.py] |
| 3103 |
import b |
| 3104 |
def func() -> None: |
| 3105 |
b.B.x |
| 3106 |
[file b.py] |
| 3107 |
import c |
| 3108 |
class B(metaclass=c.M): |
| 3109 |
pass |
| 3110 |
[file c.py] |
| 3111 |
class M(type): |
| 3112 |
x: int |
| 3113 |
[file c.py.2] |
| 3114 |
whatever: int |
| 3115 |
[out] |
| 3116 |
== |
| 3117 |
b.py:2: error: Name "c.M" is not defined |
| 3118 |
|
| 3119 |
[case testFixMissingMetaclass] |
| 3120 |
import a |
| 3121 |
[file a.py] |
| 3122 |
import b |
| 3123 |
def func() -> None: |
| 3124 |
b.B.x |
| 3125 |
[file b.py] |
| 3126 |
import c |
| 3127 |
class B(metaclass=c.M): |
| 3128 |
pass |
| 3129 |
[file c.py] |
| 3130 |
whatever: int |
| 3131 |
[file c.py.2] |
| 3132 |
class M(type): |
| 3133 |
x: int |
| 3134 |
[out] |
| 3135 |
b.py:2: error: Name "c.M" is not defined |
| 3136 |
== |
| 3137 |
|
| 3138 |
[case testGoodMetaclassSpoiled] |
| 3139 |
import a |
| 3140 |
[file a.py] |
| 3141 |
import b |
| 3142 |
class C(metaclass=b.M): |
| 3143 |
pass |
| 3144 |
[file b.py] |
| 3145 |
class M(type): |
| 3146 |
pass |
| 3147 |
[file b.py.2] |
| 3148 |
M = 1 |
| 3149 |
[out] |
| 3150 |
== |
| 3151 |
a.py:2: error: Invalid metaclass "b.M" |
| 3152 |
|
| 3153 |
[case testRefreshGenericSubclass] |
| 3154 |
from typing import Generic, TypeVar |
| 3155 |
import m |
| 3156 |
m.x |
| 3157 |
|
| 3158 |
T = TypeVar('T') |
| 3159 |
|
| 3160 |
class C(Generic[T]): |
| 3161 |
def __init__(self, x: T) -> None: |
| 3162 |
pass |
| 3163 |
|
| 3164 |
class D(C[T]): |
| 3165 |
def __init__(self, x: T) -> None: |
| 3166 |
m.x |
| 3167 |
super(D, self).__init__(x) |
| 3168 |
[file m.py] |
| 3169 |
x = 0 |
| 3170 |
[file m.py.2] |
| 3171 |
x = '' |
| 3172 |
[out] |
| 3173 |
== |
| 3174 |
|
| 3175 |
[case testRefreshNamedTupleSubclass] |
| 3176 |
from typing import NamedTuple |
| 3177 |
import m |
| 3178 |
m.x |
| 3179 |
|
| 3180 |
N = NamedTuple('N', [('x', int)]) |
| 3181 |
|
| 3182 |
class C(N): |
| 3183 |
pass |
| 3184 |
[file m.py] |
| 3185 |
x = 0 |
| 3186 |
[file m.py.2] |
| 3187 |
x = '' |
| 3188 |
[builtins fixtures/tuple.pyi] |
| 3189 |
[out] |
| 3190 |
== |
| 3191 |
|
| 3192 |
[case testNewTypeRefresh] |
| 3193 |
import a |
| 3194 |
|
| 3195 |
[file a.py] |
| 3196 |
from typing import Dict, NewType |
| 3197 |
|
| 3198 |
class A: pass |
| 3199 |
N = NewType('N', A) |
| 3200 |
|
| 3201 |
a: Dict[N, int] |
| 3202 |
|
| 3203 |
def f(self, x: N) -> None: |
| 3204 |
a.get(x) |
| 3205 |
|
| 3206 |
[file a.py.2] |
| 3207 |
from typing import Dict, NewType # dummy change |
| 3208 |
|
| 3209 |
class A: pass |
| 3210 |
N = NewType('N', A) |
| 3211 |
|
| 3212 |
a: Dict[N, int] |
| 3213 |
|
| 3214 |
def f(self, x: N) -> None: |
| 3215 |
a.get(x) |
| 3216 |
|
| 3217 |
[builtins fixtures/dict.pyi] |
| 3218 |
[out] |
| 3219 |
== |
| 3220 |
|
| 3221 |
[case testRefreshFunctionalEnum] |
| 3222 |
import a |
| 3223 |
|
| 3224 |
[file a.py] |
| 3225 |
from typing import Dict |
| 3226 |
from enum import Enum |
| 3227 |
|
| 3228 |
N = Enum('N', 'x') |
| 3229 |
a: Dict[N, int] |
| 3230 |
|
| 3231 |
def f(self, x: N) -> None: |
| 3232 |
a.get(x) |
| 3233 |
|
| 3234 |
[file a.py.2] |
| 3235 |
from typing import Dict |
| 3236 |
from enum import Enum |
| 3237 |
|
| 3238 |
N = Enum('N', 'x') |
| 3239 |
a: Dict[N, int] |
| 3240 |
|
| 3241 |
def f(self, x: N) -> None: |
| 3242 |
a.get(x) |
| 3243 |
[builtins fixtures/dict.pyi] |
| 3244 |
[out] |
| 3245 |
== |
| 3246 |
|
| 3247 |
[case testFineGrainedCallable] |
| 3248 |
import a |
| 3249 |
[file a.py] |
| 3250 |
def f(o: object) -> None: |
| 3251 |
if callable(o): |
| 3252 |
o() |
| 3253 |
[file a.py.2] |
| 3254 |
def f(o: object) -> None: |
| 3255 |
if callable(o): |
| 3256 |
o() |
| 3257 |
[builtins fixtures/callable.pyi] |
| 3258 |
[out] |
| 3259 |
== |
| 3260 |
|
| 3261 |
[case testRefreshFunctionalNamedTuple] |
| 3262 |
import a |
| 3263 |
|
| 3264 |
[file a.py] |
| 3265 |
from typing import NamedTuple |
| 3266 |
from b import L |
| 3267 |
|
| 3268 |
A = NamedTuple('A', []) |
| 3269 |
a: A |
| 3270 |
|
| 3271 |
def g() -> None: |
| 3272 |
x = L(A()) |
| 3273 |
x.f(a) |
| 3274 |
|
| 3275 |
[file b.pyi] |
| 3276 |
from typing import TypeVar, Generic, overload |
| 3277 |
|
| 3278 |
T = TypeVar('T') |
| 3279 |
|
| 3280 |
class L(Generic[T]): |
| 3281 |
def __init__(self, x: T) -> None: pass |
| 3282 |
@overload |
| 3283 |
def f(self) -> None: pass |
| 3284 |
@overload |
| 3285 |
def f(self, a: T) -> None: pass |
| 3286 |
|
| 3287 |
[file a.py.2] |
| 3288 |
from typing import NamedTuple |
| 3289 |
from b import L |
| 3290 |
|
| 3291 |
A = NamedTuple('A', []) |
| 3292 |
a: A |
| 3293 |
|
| 3294 |
def g() -> None: |
| 3295 |
x = L(A()) |
| 3296 |
x.f(a) |
| 3297 |
[builtins fixtures/tuple.pyi] |
| 3298 |
[out] |
| 3299 |
== |
| 3300 |
|
| 3301 |
[case testRefreshSubclassNestedInFunction1] |
| 3302 |
from a import C |
| 3303 |
def f() -> None: |
| 3304 |
class D(C): pass |
| 3305 |
[file a.py] |
| 3306 |
class C: pass |
| 3307 |
[file a.py.2] |
| 3308 |
[out] |
| 3309 |
== |
| 3310 |
main:1: error: Module "a" has no attribute "C" |
| 3311 |
|
| 3312 |
[case testRefreshSubclassNestedInFunction2] |
| 3313 |
from a import C |
| 3314 |
def f() -> None: |
| 3315 |
class D(C): |
| 3316 |
def g(self) -> None: |
| 3317 |
super().__init__() |
| 3318 |
d = D() |
| 3319 |
[file a.py] |
| 3320 |
class C: |
| 3321 |
def __init__(self) -> None: pass |
| 3322 |
[file a.py.2] |
| 3323 |
class C: |
| 3324 |
def __init__(self, x: int) -> None: pass |
| 3325 |
[out] |
| 3326 |
== |
| 3327 |
main:5: error: Missing positional argument "x" in call to "__init__" of "C" |
| 3328 |
main:6: error: Missing positional argument "x" in call to "D" |
| 3329 |
|
| 3330 |
[case testInferAttributeTypeAndMultipleStaleTargets] |
| 3331 |
import a |
| 3332 |
|
| 3333 |
class A: |
| 3334 |
def g(self) -> None: |
| 3335 |
a.x |
| 3336 |
self.x = 1 |
| 3337 |
|
| 3338 |
def f(self) -> None: |
| 3339 |
a.x |
| 3340 |
b = self.x |
| 3341 |
self.x = 1 |
| 3342 |
|
| 3343 |
[file a.py] |
| 3344 |
x = 0 |
| 3345 |
[file a.py.2] |
| 3346 |
x = '' |
| 3347 |
[out] |
| 3348 |
== |
| 3349 |
|
| 3350 |
[case testNamedTupleUpdate] |
| 3351 |
import b |
| 3352 |
[file a.py] |
| 3353 |
from typing import NamedTuple |
| 3354 |
N = NamedTuple('N', [('x', int)]) |
| 3355 |
x = N(1) |
| 3356 |
[file a.py.2] |
| 3357 |
from typing import NamedTuple |
| 3358 |
N = NamedTuple('N', [('x', str)]) |
| 3359 |
x = N('hi') |
| 3360 |
[file b.py] |
| 3361 |
import a |
| 3362 |
def f(x: a.N) -> None: |
| 3363 |
pass |
| 3364 |
f(a.x) |
| 3365 |
[builtins fixtures/tuple.pyi] |
| 3366 |
[out] |
| 3367 |
== |
| 3368 |
|
| 3369 |
[case testNamedTupleUpdate2] |
| 3370 |
import b |
| 3371 |
[file a.py] |
| 3372 |
from typing import NamedTuple |
| 3373 |
N = NamedTuple('N', [('x', int)]) |
| 3374 |
x = N(1) |
| 3375 |
[file a.py.2] |
| 3376 |
from typing import NamedTuple |
| 3377 |
N = NamedTuple('N', [('y', int)]) |
| 3378 |
x = N(2) |
| 3379 |
[file b.py] |
| 3380 |
import a |
| 3381 |
def f(x: a.N) -> None: |
| 3382 |
pass |
| 3383 |
f(a.x) |
| 3384 |
[builtins fixtures/tuple.pyi] |
| 3385 |
[out] |
| 3386 |
== |
| 3387 |
|
| 3388 |
[case testNamedTupleUpdate3] |
| 3389 |
import c |
| 3390 |
[file a.py] |
| 3391 |
from typing import NamedTuple |
| 3392 |
N = NamedTuple('N', [('x', int)]) |
| 3393 |
x = N(1) |
| 3394 |
[file a.py.2] |
| 3395 |
from typing import NamedTuple |
| 3396 |
N = NamedTuple('N', [('x', str)]) |
| 3397 |
x = N('hi') |
| 3398 |
[file b.py] |
| 3399 |
import a |
| 3400 |
from typing import NamedTuple |
| 3401 |
M = NamedTuple('M', [('z', 'a.N')]) |
| 3402 |
x = M(a.x) |
| 3403 |
[file c.py] |
| 3404 |
import a |
| 3405 |
import b |
| 3406 |
from typing import Tuple |
| 3407 |
def lol(n: Tuple[Tuple[int]]) -> None: |
| 3408 |
pass |
| 3409 |
def f(x: b.M) -> None: |
| 3410 |
lol(x) |
| 3411 |
f(b.x) |
| 3412 |
lol(b.x) |
| 3413 |
[builtins fixtures/tuple.pyi] |
| 3414 |
[out] |
| 3415 |
== |
| 3416 |
c.py:7: error: Argument 1 to "lol" has incompatible type "M"; expected "tuple[tuple[int]]" |
| 3417 |
c.py:9: error: Argument 1 to "lol" has incompatible type "M"; expected "tuple[tuple[int]]" |
| 3418 |
|
| 3419 |
[case testNamedTupleUpdate4] |
| 3420 |
import b |
| 3421 |
[file a.py] |
| 3422 |
from typing import NamedTuple |
| 3423 |
class N(NamedTuple): |
| 3424 |
x: int |
| 3425 |
x = N(1) |
| 3426 |
[file a.py.2] |
| 3427 |
from typing import NamedTuple |
| 3428 |
class N(NamedTuple): |
| 3429 |
x: str |
| 3430 |
x = N('hi') |
| 3431 |
[file b.py] |
| 3432 |
import a |
| 3433 |
def f(x: a.N) -> None: |
| 3434 |
pass |
| 3435 |
f(a.x) |
| 3436 |
[builtins fixtures/tuple.pyi] |
| 3437 |
[out] |
| 3438 |
== |
| 3439 |
|
| 3440 |
[case testNamedTupleUpdate5] |
| 3441 |
import b |
| 3442 |
[file a.py] |
| 3443 |
from typing import NamedTuple, Optional |
| 3444 |
class N(NamedTuple): |
| 3445 |
r: Optional[N] |
| 3446 |
x: int |
| 3447 |
x = N(None, 1) |
| 3448 |
[file a.py.2] |
| 3449 |
from typing import NamedTuple, Optional |
| 3450 |
class N(NamedTuple): |
| 3451 |
r: Optional[N] |
| 3452 |
x: str |
| 3453 |
x = N(None, 'hi') |
| 3454 |
[file b.py] |
| 3455 |
import a |
| 3456 |
def f(x: a.N) -> None: |
| 3457 |
pass |
| 3458 |
f(a.x) |
| 3459 |
[builtins fixtures/tuple.pyi] |
| 3460 |
[out] |
| 3461 |
== |
| 3462 |
|
| 3463 |
[case testNamedTupleUpdateGeneric] |
| 3464 |
import b |
| 3465 |
[file a.py] |
| 3466 |
from typing import NamedTuple |
| 3467 |
class Point(NamedTuple): |
| 3468 |
x: int |
| 3469 |
y: int |
| 3470 |
[file a.py.2] |
| 3471 |
from typing import Generic, TypeVar, NamedTuple |
| 3472 |
|
| 3473 |
T = TypeVar("T") |
| 3474 |
class Point(NamedTuple, Generic[T]): |
| 3475 |
x: int |
| 3476 |
y: T |
| 3477 |
[file b.py] |
| 3478 |
from a import Point |
| 3479 |
def foo() -> None: |
| 3480 |
p = Point(x=0, y=1) |
| 3481 |
i: int = p.y |
| 3482 |
[file b.py.3] |
| 3483 |
from a import Point |
| 3484 |
def foo() -> None: |
| 3485 |
p = Point(x=0, y="no") |
| 3486 |
i: int = p.y |
| 3487 |
[builtins fixtures/tuple.pyi] |
| 3488 |
[out] |
| 3489 |
== |
| 3490 |
== |
| 3491 |
b.py:4: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 3492 |
|
| 3493 |
[case testNamedTupleUpdateNonRecursiveToRecursiveFine] |
| 3494 |
import c |
| 3495 |
[file a.py] |
| 3496 |
from b import M |
| 3497 |
from typing import NamedTuple, Optional |
| 3498 |
class N(NamedTuple): |
| 3499 |
r: Optional[M] |
| 3500 |
x: int |
| 3501 |
n: N |
| 3502 |
[file b.py] |
| 3503 |
from a import N |
| 3504 |
from typing import NamedTuple |
| 3505 |
class M(NamedTuple): |
| 3506 |
r: None |
| 3507 |
x: int |
| 3508 |
[file b.py.2] |
| 3509 |
from a import N |
| 3510 |
from typing import NamedTuple, Optional |
| 3511 |
class M(NamedTuple): |
| 3512 |
r: Optional[N] |
| 3513 |
x: int |
| 3514 |
[file c.py] |
| 3515 |
import a |
| 3516 |
def f(x: a.N) -> None: |
| 3517 |
if x.r is not None: |
| 3518 |
s: int = x.r.x |
| 3519 |
[file c.py.3] |
| 3520 |
import a |
| 3521 |
def f(x: a.N) -> None: |
| 3522 |
if x.r is not None and x.r.r is not None and x.r.r.r is not None: |
| 3523 |
reveal_type(x) |
| 3524 |
s: int = x.r.r.r.r |
| 3525 |
f(a.n) |
| 3526 |
reveal_type(a.n) |
| 3527 |
[builtins fixtures/tuple.pyi] |
| 3528 |
[out] |
| 3529 |
== |
| 3530 |
== |
| 3531 |
c.py:4: note: Revealed type is "tuple[tuple[tuple[... | None, builtins.int, fallback=a.N] | None, builtins.int, fallback=b.M] | None, builtins.int, fallback=a.N]" |
| 3532 |
c.py:5: error: Incompatible types in assignment (expression has type "N | None", variable has type "int") |
| 3533 |
c.py:7: note: Revealed type is "tuple[tuple[tuple[... | None, builtins.int, fallback=a.N] | None, builtins.int, fallback=b.M] | None, builtins.int, fallback=a.N]" |
| 3534 |
|
| 3535 |
[case testTupleTypeUpdateNonRecursiveToRecursiveFine] |
| 3536 |
import c |
| 3537 |
[file a.py] |
| 3538 |
from b import M |
| 3539 |
from typing import Tuple, Optional |
| 3540 |
class N(Tuple[Optional[M], int]): ... |
| 3541 |
[file b.py] |
| 3542 |
from a import N |
| 3543 |
from typing import Tuple |
| 3544 |
class M(Tuple[None, int]): ... |
| 3545 |
[file b.py.2] |
| 3546 |
from a import N |
| 3547 |
from typing import Tuple, Optional |
| 3548 |
class M(Tuple[Optional[N], int]): ... |
| 3549 |
[file c.py] |
| 3550 |
import a |
| 3551 |
def f(x: a.N) -> None: |
| 3552 |
if x[0] is not None: |
| 3553 |
s: int = x[0][1] |
| 3554 |
[file c.py.3] |
| 3555 |
import a |
| 3556 |
def f(x: a.N) -> None: |
| 3557 |
if x[0] is not None and x[0][0] is not None and x[0][0][0] is not None: |
| 3558 |
reveal_type(x) |
| 3559 |
s: int = x[0][0][0][0] |
| 3560 |
[builtins fixtures/tuple.pyi] |
| 3561 |
[out] |
| 3562 |
== |
| 3563 |
== |
| 3564 |
c.py:4: note: Revealed type is "tuple[tuple[... | None, builtins.int, fallback=b.M] | None, builtins.int, fallback=a.N]" |
| 3565 |
c.py:5: error: Incompatible types in assignment (expression has type "N | None", variable has type "int") |
| 3566 |
|
| 3567 |
[case testTypeAliasUpdateNonRecursiveToRecursiveFine] |
| 3568 |
import c |
| 3569 |
[file a.py] |
| 3570 |
from b import M |
| 3571 |
from typing import Tuple, Optional |
| 3572 |
N = Tuple[Optional[M], int] |
| 3573 |
[file b.py] |
| 3574 |
from a import N |
| 3575 |
from typing import Tuple |
| 3576 |
M = Tuple[None, int] |
| 3577 |
[file b.py.2] |
| 3578 |
from a import N |
| 3579 |
from typing import Tuple, Optional |
| 3580 |
M = Tuple[Optional[N], int] |
| 3581 |
[file c.py] |
| 3582 |
import a |
| 3583 |
def f(x: a.N) -> None: |
| 3584 |
if x[0] is not None: |
| 3585 |
s: int = x[0][1] |
| 3586 |
[file c.py.3] |
| 3587 |
import a |
| 3588 |
def f(x: a.N) -> None: |
| 3589 |
if x[0] is not None and x[0][0] is not None and x[0][0][0] is not None: |
| 3590 |
reveal_type(x) |
| 3591 |
s: int = x[0][0][0][0] |
| 3592 |
[builtins fixtures/tuple.pyi] |
| 3593 |
[out] |
| 3594 |
== |
| 3595 |
== |
| 3596 |
c.py:4: note: Revealed type is "tuple[tuple[... | None, builtins.int] | None, builtins.int]" |
| 3597 |
c.py:5: error: Incompatible types in assignment (expression has type "N | None", variable has type "int") |
| 3598 |
|
| 3599 |
[case testTypedDictRefresh] |
| 3600 |
import a |
| 3601 |
[file a.py] |
| 3602 |
from typing import TypedDict |
| 3603 |
Point = TypedDict('Point', {'x': int, 'y': int}) |
| 3604 |
p = Point(dict(x=42, y=1337)) |
| 3605 |
[file a.py.2] |
| 3606 |
from typing import TypedDict |
| 3607 |
Point = TypedDict('Point', {'x': int, 'y': int}) |
| 3608 |
p = Point(dict(x=42, y=1337)) # dummy change |
| 3609 |
[builtins fixtures/dict.pyi] |
| 3610 |
[typing fixtures/typing-typeddict.pyi] |
| 3611 |
[out] |
| 3612 |
== |
| 3613 |
|
| 3614 |
[case testTypedDictUpdate] |
| 3615 |
import b |
| 3616 |
[file a.py] |
| 3617 |
from typing import TypedDict |
| 3618 |
Point = TypedDict('Point', {'x': int, 'y': int}) |
| 3619 |
p = Point(dict(x=42, y=1337)) |
| 3620 |
[file a.py.2] |
| 3621 |
from typing import TypedDict |
| 3622 |
Point = TypedDict('Point', {'x': int, 'y': str}) |
| 3623 |
p = Point(dict(x=42, y='lurr')) |
| 3624 |
[file b.py] |
| 3625 |
from a import Point |
| 3626 |
def foo(x: Point) -> int: |
| 3627 |
return x['x'] + x['y'] |
| 3628 |
[builtins fixtures/dict.pyi] |
| 3629 |
[typing fixtures/typing-typeddict.pyi] |
| 3630 |
[out] |
| 3631 |
== |
| 3632 |
b.py:3: error: Unsupported operand types for + ("int" and "str") |
| 3633 |
|
| 3634 |
[case testTypedDictUpdate2] |
| 3635 |
import b |
| 3636 |
[file a.py] |
| 3637 |
from typing import TypedDict |
| 3638 |
class Point(TypedDict): |
| 3639 |
x: int |
| 3640 |
y: int |
| 3641 |
p = Point(dict(x=42, y=1337)) |
| 3642 |
[file a.py.2] |
| 3643 |
from typing import TypedDict |
| 3644 |
class Point(TypedDict): |
| 3645 |
x: int |
| 3646 |
y: str |
| 3647 |
p = Point(dict(x=42, y='lurr')) |
| 3648 |
[file b.py] |
| 3649 |
from a import Point |
| 3650 |
def foo(x: Point) -> int: |
| 3651 |
return x['x'] + x['y'] |
| 3652 |
[builtins fixtures/dict.pyi] |
| 3653 |
[typing fixtures/typing-typeddict.pyi] |
| 3654 |
[out] |
| 3655 |
== |
| 3656 |
b.py:3: error: Unsupported operand types for + ("int" and "str") |
| 3657 |
|
| 3658 |
[case testTypedDictUpdate3] |
| 3659 |
import b |
| 3660 |
[file a.py] |
| 3661 |
from typing import Optional, TypedDict |
| 3662 |
class Point(TypedDict): |
| 3663 |
x: Optional[Point] |
| 3664 |
y: int |
| 3665 |
z: int |
| 3666 |
p = Point(dict(x=None, y=1337, z=0)) |
| 3667 |
[file a.py.2] |
| 3668 |
from typing import Optional, TypedDict |
| 3669 |
class Point(TypedDict): |
| 3670 |
x: Optional[Point] |
| 3671 |
y: str |
| 3672 |
z: int |
| 3673 |
p = Point(dict(x=None, y='lurr', z=0)) |
| 3674 |
[file b.py] |
| 3675 |
from a import Point |
| 3676 |
def foo(x: Point) -> int: |
| 3677 |
assert x['x'] is not None |
| 3678 |
return x['x']['z'] + x['x']['y'] |
| 3679 |
[builtins fixtures/dict.pyi] |
| 3680 |
[typing fixtures/typing-typeddict.pyi] |
| 3681 |
[out] |
| 3682 |
== |
| 3683 |
b.py:4: error: Unsupported operand types for + ("int" and "str") |
| 3684 |
|
| 3685 |
[case testTypedDictUpdateGeneric] |
| 3686 |
import b |
| 3687 |
[file a.py] |
| 3688 |
from typing import TypedDict |
| 3689 |
class Point(TypedDict): |
| 3690 |
x: int |
| 3691 |
y: int |
| 3692 |
[file a.py.2] |
| 3693 |
from typing import Generic, TypedDict, TypeVar |
| 3694 |
|
| 3695 |
T = TypeVar("T") |
| 3696 |
class Point(TypedDict, Generic[T]): |
| 3697 |
x: int |
| 3698 |
y: T |
| 3699 |
[file b.py] |
| 3700 |
from a import Point |
| 3701 |
def foo() -> None: |
| 3702 |
p = Point(x=0, y=1) |
| 3703 |
i: int = p["y"] |
| 3704 |
[file b.py.3] |
| 3705 |
from a import Point |
| 3706 |
def foo() -> None: |
| 3707 |
p = Point(x=0, y="no") |
| 3708 |
i: int = p["y"] |
| 3709 |
[builtins fixtures/dict.pyi] |
| 3710 |
[typing fixtures/typing-typeddict.pyi] |
| 3711 |
[out] |
| 3712 |
== |
| 3713 |
== |
| 3714 |
b.py:4: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 3715 |
|
| 3716 |
[case testTypedDictUpdateReadOnly] |
| 3717 |
import b |
| 3718 |
[file a.py] |
| 3719 |
from typing import TypedDict |
| 3720 |
from typing_extensions import ReadOnly |
| 3721 |
Point = TypedDict('Point', {'x': int, 'y': int}) |
| 3722 |
p = Point(x=1, y=2) |
| 3723 |
[file a.py.2] |
| 3724 |
from typing import TypedDict |
| 3725 |
from typing_extensions import ReadOnly |
| 3726 |
class Point(TypedDict): |
| 3727 |
x: int |
| 3728 |
y: ReadOnly[int] |
| 3729 |
p = Point(x=1, y=2) |
| 3730 |
[file a.py.3] |
| 3731 |
from typing import TypedDict |
| 3732 |
from typing_extensions import ReadOnly |
| 3733 |
Point = TypedDict('Point', {'x': ReadOnly[int], 'y': int}) |
| 3734 |
p = Point(x=1, y=2) |
| 3735 |
[file b.py] |
| 3736 |
from a import Point |
| 3737 |
def foo(x: Point) -> None: |
| 3738 |
x['x'] = 1 |
| 3739 |
x['y'] = 2 |
| 3740 |
[builtins fixtures/dict.pyi] |
| 3741 |
[typing fixtures/typing-typeddict.pyi] |
| 3742 |
[out] |
| 3743 |
== |
| 3744 |
b.py:4: error: ReadOnly TypedDict key "y" TypedDict is mutated |
| 3745 |
== |
| 3746 |
b.py:3: error: ReadOnly TypedDict key "x" TypedDict is mutated |
| 3747 |
|
| 3748 |
[case testTypedDictUpdateClosed] |
| 3749 |
import b |
| 3750 |
[file a.py] |
| 3751 |
from typing import TypedDict, Union |
| 3752 |
class A(TypedDict): |
| 3753 |
a: int |
| 3754 |
class B(TypedDict, closed=True): |
| 3755 |
b: int |
| 3756 |
C = Union[A, B] |
| 3757 |
[file a.py.2] |
| 3758 |
from typing import TypedDict, Union |
| 3759 |
class A(TypedDict, closed=True): |
| 3760 |
a: int |
| 3761 |
class B(TypedDict): |
| 3762 |
b: int |
| 3763 |
C = Union[A, B] |
| 3764 |
[file a.py.3] |
| 3765 |
from typing import TypedDict, Union |
| 3766 |
class A(TypedDict, closed=True): |
| 3767 |
a: int |
| 3768 |
class B(TypedDict, closed=True): |
| 3769 |
b: int |
| 3770 |
C = Union[A, B] |
| 3771 |
[file b.py] |
| 3772 |
from a import C |
| 3773 |
def foo(x: C) -> int: |
| 3774 |
if "b" in x: |
| 3775 |
return x["b"] |
| 3776 |
else: |
| 3777 |
return x["a"] |
| 3778 |
def bar(x: C) -> int: |
| 3779 |
if "a" in x: |
| 3780 |
return x["a"] |
| 3781 |
else: |
| 3782 |
return x["b"] |
| 3783 |
[builtins fixtures/dict.pyi] |
| 3784 |
[typing fixtures/typing-typeddict.pyi] |
| 3785 |
[out] |
| 3786 |
b.py:4: error: TypedDict "A" has no key "b" |
| 3787 |
== |
| 3788 |
b.py:9: error: TypedDict "B" has no key "a" |
| 3789 |
== |
| 3790 |
|
| 3791 |
[case testTypedDictUpdateClosedPassingToFailing] |
| 3792 |
import b |
| 3793 |
[file a.py] |
| 3794 |
from typing import TypedDict, Union |
| 3795 |
class A(TypedDict, closed=True): |
| 3796 |
a: int |
| 3797 |
class B(TypedDict, closed=True): |
| 3798 |
b: int |
| 3799 |
C = Union[A, B] |
| 3800 |
[file a.py.2] |
| 3801 |
from typing import TypedDict, Union |
| 3802 |
class A(TypedDict): |
| 3803 |
a: int |
| 3804 |
class B(TypedDict, closed=True): |
| 3805 |
b: int |
| 3806 |
C = Union[A, B] |
| 3807 |
[file b.py] |
| 3808 |
from a import C |
| 3809 |
def foo(x: C) -> int: |
| 3810 |
if "b" in x: |
| 3811 |
return x["b"] |
| 3812 |
else: |
| 3813 |
return x["a"] |
| 3814 |
def bar(x: C) -> int: |
| 3815 |
if "a" in x: |
| 3816 |
return x["a"] |
| 3817 |
else: |
| 3818 |
return x["b"] |
| 3819 |
[builtins fixtures/dict.pyi] |
| 3820 |
[typing fixtures/typing-typeddict.pyi] |
| 3821 |
[out] |
| 3822 |
== |
| 3823 |
b.py:4: error: TypedDict "A" has no key "b" |
| 3824 |
|
| 3825 |
[case testBasicAliasUpdate] |
| 3826 |
import b |
| 3827 |
[file a.py] |
| 3828 |
N = int |
| 3829 |
x = 1 |
| 3830 |
[file a.py.2] |
| 3831 |
N = str |
| 3832 |
x = 'hi' |
| 3833 |
[file b.py] |
| 3834 |
import a |
| 3835 |
def f(x: a.N) -> None: |
| 3836 |
pass |
| 3837 |
f(a.x) |
| 3838 |
[out] |
| 3839 |
== |
| 3840 |
|
| 3841 |
[case testBasicAliasUpdateGeneric] |
| 3842 |
import b |
| 3843 |
[file a.py] |
| 3844 |
from typing import Dict, TypeVar |
| 3845 |
T = TypeVar('T') |
| 3846 |
D = Dict[int, T] |
| 3847 |
x = {1: 1} |
| 3848 |
[file a.py.2] |
| 3849 |
from typing import Dict, TypeVar |
| 3850 |
T = TypeVar('T') |
| 3851 |
D = Dict[str, T] |
| 3852 |
x = {'hi': 1} |
| 3853 |
[file b.py] |
| 3854 |
import a |
| 3855 |
def f(x: a.D[int]) -> None: |
| 3856 |
pass |
| 3857 |
f(a.x) |
| 3858 |
[builtins fixtures/dict.pyi] |
| 3859 |
[out] |
| 3860 |
== |
| 3861 |
|
| 3862 |
[case testAliasFineNormalMod] |
| 3863 |
import b |
| 3864 |
[file a.py] |
| 3865 |
A = int |
| 3866 |
[file a.py.2] |
| 3867 |
A = str |
| 3868 |
[file b.py] |
| 3869 |
import a |
| 3870 |
x: a.A = int() |
| 3871 |
[out] |
| 3872 |
== |
| 3873 |
b.py:2: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 3874 |
|
| 3875 |
[case testAliasFineNormalFunc] |
| 3876 |
import b |
| 3877 |
[file a.py] |
| 3878 |
A = int |
| 3879 |
[file a.py.2] |
| 3880 |
A = str |
| 3881 |
[file b.py] |
| 3882 |
import a |
| 3883 |
def f(x: a.A): |
| 3884 |
if int(): |
| 3885 |
x = int() |
| 3886 |
[out] |
| 3887 |
== |
| 3888 |
b.py:4: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 3889 |
|
| 3890 |
[case testAliasFineNormalClass] |
| 3891 |
import b |
| 3892 |
[file a.py] |
| 3893 |
A = int |
| 3894 |
[file a.py.2] |
| 3895 |
A = str |
| 3896 |
[file b.py] |
| 3897 |
import a |
| 3898 |
class C: |
| 3899 |
x: a.A |
| 3900 |
c = C() |
| 3901 |
c.x = int() |
| 3902 |
[out] |
| 3903 |
== |
| 3904 |
b.py:5: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 3905 |
|
| 3906 |
[case testAliasFineNormalClassBases] |
| 3907 |
import b |
| 3908 |
[file a.py] |
| 3909 |
import c |
| 3910 |
A = c.BaseI |
| 3911 |
[file a.py.2] |
| 3912 |
import c |
| 3913 |
A = c.BaseS |
| 3914 |
[file b.py] |
| 3915 |
import a |
| 3916 |
class C(a.A): |
| 3917 |
x = int() |
| 3918 |
[file c.py] |
| 3919 |
class BaseI: |
| 3920 |
x: int |
| 3921 |
class BaseS: |
| 3922 |
x: str |
| 3923 |
[out] |
| 3924 |
== |
| 3925 |
b.py:3: error: Incompatible types in assignment (expression has type "int", base class "BaseS" defined the type as "str") |
| 3926 |
|
| 3927 |
[case testAliasFineGenericMod] |
| 3928 |
import b |
| 3929 |
[file a.py] |
| 3930 |
from typing import Dict |
| 3931 |
A = Dict[str, int] |
| 3932 |
[file a.py.2] |
| 3933 |
from typing import Dict |
| 3934 |
A = Dict[str, str] |
| 3935 |
[file b.py] |
| 3936 |
import a |
| 3937 |
x: a.A = {str(): int()} |
| 3938 |
[builtins fixtures/dict.pyi] |
| 3939 |
[out] |
| 3940 |
== |
| 3941 |
b.py:2: error: Dict entry 0 has incompatible type "str": "int"; expected "str": "str" |
| 3942 |
|
| 3943 |
[case testAliasFineGenericFunc] |
| 3944 |
import b |
| 3945 |
[file a.py] |
| 3946 |
from typing import Dict |
| 3947 |
A = Dict[str, int] |
| 3948 |
[file a.py.2] |
| 3949 |
from typing import Dict |
| 3950 |
A = Dict[str, str] |
| 3951 |
[file b.py] |
| 3952 |
import a |
| 3953 |
def f(x: a.A): |
| 3954 |
pass |
| 3955 |
f({str(): int()}) |
| 3956 |
[builtins fixtures/dict.pyi] |
| 3957 |
[out] |
| 3958 |
== |
| 3959 |
b.py:4: error: Dict entry 0 has incompatible type "str": "int"; expected "str": "str" |
| 3960 |
|
| 3961 |
[case testAliasFineForwardMod] |
| 3962 |
import b |
| 3963 |
[file b.py] |
| 3964 |
x: A = int() |
| 3965 |
A = int |
| 3966 |
[file b.py.2] |
| 3967 |
x: A = int() |
| 3968 |
A = str |
| 3969 |
[out] |
| 3970 |
== |
| 3971 |
b.py:1: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 3972 |
|
| 3973 |
[case testAliasFineForwardFunc] |
| 3974 |
import b |
| 3975 |
[file b.py] |
| 3976 |
def f(x: A): |
| 3977 |
x = int() |
| 3978 |
A = int |
| 3979 |
[file b.py.2] |
| 3980 |
def f(x: A): |
| 3981 |
if int(): |
| 3982 |
x = int() |
| 3983 |
A = str |
| 3984 |
[out] |
| 3985 |
== |
| 3986 |
b.py:3: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 3987 |
|
| 3988 |
[case testAliasFineChainedFunc] |
| 3989 |
import b |
| 3990 |
[file a.py] |
| 3991 |
A = int |
| 3992 |
[file a.py.2] |
| 3993 |
A = str |
| 3994 |
[file aa.py] |
| 3995 |
import a |
| 3996 |
B = a.A |
| 3997 |
[file b.py] |
| 3998 |
import aa |
| 3999 |
def f(x: aa.B): |
| 4000 |
if int(): |
| 4001 |
x = int() |
| 4002 |
[out] |
| 4003 |
== |
| 4004 |
b.py:4: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 4005 |
|
| 4006 |
[case testAliasFineChainedClass] |
| 4007 |
import b |
| 4008 |
[file a.py] |
| 4009 |
A = int |
| 4010 |
[file a.py.2] |
| 4011 |
A = str |
| 4012 |
[file aa.py] |
| 4013 |
import a |
| 4014 |
B = a.A |
| 4015 |
[file b.py] |
| 4016 |
import aa |
| 4017 |
class C: |
| 4018 |
x: aa.B |
| 4019 |
c = C() |
| 4020 |
c.x = int() |
| 4021 |
[out] |
| 4022 |
== |
| 4023 |
b.py:5: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 4024 |
|
| 4025 |
[case testAliasFineNestedMod] |
| 4026 |
import b |
| 4027 |
[file a.py] |
| 4028 |
from typing import Dict |
| 4029 |
A = Dict[str, int] |
| 4030 |
[file a.py.2] |
| 4031 |
from typing import Dict |
| 4032 |
A = Dict[str, str] |
| 4033 |
[file aa.py] |
| 4034 |
from typing import Dict |
| 4035 |
import a |
| 4036 |
B = Dict[str, a.A] |
| 4037 |
[file b.py] |
| 4038 |
import aa |
| 4039 |
|
| 4040 |
x: aa.B = {'first': {str(): int()}} |
| 4041 |
[builtins fixtures/dict.pyi] |
| 4042 |
[out] |
| 4043 |
== |
| 4044 |
b.py:3: error: Dict entry 0 has incompatible type "str": "int"; expected "str": "str" |
| 4045 |
|
| 4046 |
[case testAliasFineNestedFunc] |
| 4047 |
import b |
| 4048 |
[file a.py] |
| 4049 |
from typing import Dict |
| 4050 |
A = Dict[str, int] |
| 4051 |
[file a.py.2] |
| 4052 |
from typing import Dict |
| 4053 |
A = Dict[str, str] |
| 4054 |
[file aa.py] |
| 4055 |
from typing import Dict |
| 4056 |
import a |
| 4057 |
B = Dict[str, a.A] |
| 4058 |
[file b.py] |
| 4059 |
import aa |
| 4060 |
def f(x: aa.B): |
| 4061 |
if int(): |
| 4062 |
x = {'first': {str(): int()}} |
| 4063 |
[builtins fixtures/dict.pyi] |
| 4064 |
[out] |
| 4065 |
== |
| 4066 |
b.py:4: error: Dict entry 0 has incompatible type "str": "int"; expected "str": "str" |
| 4067 |
|
| 4068 |
[case testAliasFineNestedFuncDirect] |
| 4069 |
import b |
| 4070 |
[file a.py] |
| 4071 |
from typing import Dict |
| 4072 |
A = Dict[str, int] |
| 4073 |
[file a.py.2] |
| 4074 |
from typing import Dict |
| 4075 |
A = Dict[str, str] |
| 4076 |
[file aa.py] |
| 4077 |
from typing import Dict |
| 4078 |
import a |
| 4079 |
E = Dict |
| 4080 |
[file b.py] |
| 4081 |
import aa |
| 4082 |
def f(x: aa.E[str, aa.a.A]): |
| 4083 |
if int(): |
| 4084 |
x = {'first': {str(): int()}} |
| 4085 |
[builtins fixtures/dict.pyi] |
| 4086 |
[out] |
| 4087 |
== |
| 4088 |
b.py:4: error: Dict entry 0 has incompatible type "str": "int"; expected "str": "str" |
| 4089 |
|
| 4090 |
[case testAliasFineNonGenericToGeneric] |
| 4091 |
import b |
| 4092 |
[file a.py] |
| 4093 |
from typing import Dict, TypeVar |
| 4094 |
T = TypeVar('T') |
| 4095 |
A = Dict[T, int] |
| 4096 |
[file a.py.2] |
| 4097 |
A = str |
| 4098 |
[file b.py] |
| 4099 |
import a |
| 4100 |
def f(x: a.A[str]): |
| 4101 |
pass |
| 4102 |
[builtins fixtures/dict.pyi] |
| 4103 |
[out] |
| 4104 |
== |
| 4105 |
b.py:2: error: "str" expects no type arguments, but 1 given |
| 4106 |
|
| 4107 |
[case testAliasFineGenericToNonGeneric] |
| 4108 |
import b |
| 4109 |
[file a.py] |
| 4110 |
A = str |
| 4111 |
[file a.py.2] |
| 4112 |
from typing import Dict, TypeVar |
| 4113 |
T = TypeVar('T') |
| 4114 |
A = Dict[T, int] |
| 4115 |
[file b.py] |
| 4116 |
import a |
| 4117 |
def f(x: a.A): |
| 4118 |
pass |
| 4119 |
reveal_type(f) |
| 4120 |
[builtins fixtures/dict.pyi] |
| 4121 |
[out] |
| 4122 |
b.py:4: note: Revealed type is "def (x: builtins.str) -> Any" |
| 4123 |
== |
| 4124 |
b.py:4: note: Revealed type is "def (x: builtins.dict[Any, builtins.int]) -> Any" |
| 4125 |
|
| 4126 |
[case testAliasFineChangedNumberOfTypeVars] |
| 4127 |
import b |
| 4128 |
[file a.py] |
| 4129 |
from typing import Dict, TypeVar |
| 4130 |
T = TypeVar('T') |
| 4131 |
A = Dict[T, int] |
| 4132 |
[file a.py.2] |
| 4133 |
from typing import Dict, TypeVar |
| 4134 |
T = TypeVar('T') |
| 4135 |
S = TypeVar('S') |
| 4136 |
A = Dict[T, S] |
| 4137 |
[file b.py] |
| 4138 |
import a |
| 4139 |
def f(x: a.A[str]): |
| 4140 |
pass |
| 4141 |
[builtins fixtures/dict.pyi] |
| 4142 |
[out] |
| 4143 |
== |
| 4144 |
b.py:2: error: Bad number of arguments for type alias, expected 2, given 1 |
| 4145 |
|
| 4146 |
[case testAliasFineAdded] |
| 4147 |
import b |
| 4148 |
[file a.py] |
| 4149 |
[file a.py.2] |
| 4150 |
A = int |
| 4151 |
[file b.py] |
| 4152 |
import a |
| 4153 |
x: a.A |
| 4154 |
[out] |
| 4155 |
b.py:2: error: Name "a.A" is not defined |
| 4156 |
== |
| 4157 |
|
| 4158 |
[case testAliasFineDeleted] |
| 4159 |
import b |
| 4160 |
[file a.py] |
| 4161 |
A = int |
| 4162 |
[file a.py.2] |
| 4163 |
[file b.py] |
| 4164 |
import a |
| 4165 |
x: a.A |
| 4166 |
[out] |
| 4167 |
== |
| 4168 |
b.py:2: error: Name "a.A" is not defined |
| 4169 |
|
| 4170 |
[case testAliasFineClassToAlias] |
| 4171 |
import b |
| 4172 |
[file a.py] |
| 4173 |
class A: pass |
| 4174 |
[file a.py.2] |
| 4175 |
A = int |
| 4176 |
[file b.py] |
| 4177 |
import a |
| 4178 |
x: a.A |
| 4179 |
x = 1 |
| 4180 |
[out] |
| 4181 |
b.py:3: error: Incompatible types in assignment (expression has type "int", variable has type "A") |
| 4182 |
== |
| 4183 |
|
| 4184 |
[case testAliasFineAliasToClass] |
| 4185 |
import b |
| 4186 |
[file a.py] |
| 4187 |
A = int |
| 4188 |
[file a.py.2] |
| 4189 |
class A: pass |
| 4190 |
[file b.py] |
| 4191 |
import a |
| 4192 |
x: a.A |
| 4193 |
x = 1 |
| 4194 |
[out] |
| 4195 |
== |
| 4196 |
b.py:3: error: Incompatible types in assignment (expression has type "int", variable has type "A") |
| 4197 |
|
| 4198 |
[case testAliasFineComponentDeleted] |
| 4199 |
import b |
| 4200 |
[file a.py] |
| 4201 |
class B: pass |
| 4202 |
[file a.py.2] |
| 4203 |
x = 1 |
| 4204 |
[file b.py] |
| 4205 |
import a |
| 4206 |
from typing import Dict, TypeVar |
| 4207 |
T = TypeVar('T') |
| 4208 |
A = Dict[T, a.B] |
| 4209 |
def f(x: A[int]): |
| 4210 |
pass |
| 4211 |
[builtins fixtures/dict.pyi] |
| 4212 |
[out] |
| 4213 |
== |
| 4214 |
b.py:4: error: Name "a.B" is not defined |
| 4215 |
|
| 4216 |
[case testAliasFineTargetDeleted] |
| 4217 |
import c |
| 4218 |
[file a.py] |
| 4219 |
A = int |
| 4220 |
[file b.py] |
| 4221 |
import a |
| 4222 |
B = a.A |
| 4223 |
[file b.py.2] |
| 4224 |
x = 1 |
| 4225 |
[file c.py] |
| 4226 |
import b |
| 4227 |
def f(x: b.B): |
| 4228 |
pass |
| 4229 |
[out] |
| 4230 |
== |
| 4231 |
c.py:2: error: Name "b.B" is not defined |
| 4232 |
|
| 4233 |
[case testAliasFineClassInFunction] |
| 4234 |
import b |
| 4235 |
[file a.py] |
| 4236 |
A = int |
| 4237 |
[file a.py.2] |
| 4238 |
A = str |
| 4239 |
[file b.py] |
| 4240 |
import a |
| 4241 |
def f() -> None: |
| 4242 |
class C: |
| 4243 |
x: a.A = int() |
| 4244 |
[out] |
| 4245 |
== |
| 4246 |
b.py:4: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 4247 |
|
| 4248 |
[case testAliasFineInitNormalMod] |
| 4249 |
import c |
| 4250 |
[file a.py] |
| 4251 |
class A: |
| 4252 |
def __init__(self, x: int) -> None: |
| 4253 |
pass |
| 4254 |
[file a.py.2] |
| 4255 |
class A: |
| 4256 |
def __init__(self, x: str) -> None: |
| 4257 |
pass |
| 4258 |
[file b.py] |
| 4259 |
import a |
| 4260 |
B = a.A |
| 4261 |
[file c.py] |
| 4262 |
from b import B |
| 4263 |
B(int()) |
| 4264 |
[out] |
| 4265 |
== |
| 4266 |
c.py:2: error: Argument 1 to "A" has incompatible type "int"; expected "str" |
| 4267 |
|
| 4268 |
[case testAliasFineInitNormalFunc] |
| 4269 |
import c |
| 4270 |
[file a.py] |
| 4271 |
class A: |
| 4272 |
def __init__(self, x: int) -> None: |
| 4273 |
pass |
| 4274 |
[file a.py.2] |
| 4275 |
class A: |
| 4276 |
def __init__(self, x: str) -> None: |
| 4277 |
pass |
| 4278 |
[file b.py] |
| 4279 |
import a |
| 4280 |
B = a.A |
| 4281 |
[file c.py] |
| 4282 |
from b import B |
| 4283 |
def f() -> None: |
| 4284 |
B(int()) |
| 4285 |
[out] |
| 4286 |
== |
| 4287 |
c.py:3: error: Argument 1 to "A" has incompatible type "int"; expected "str" |
| 4288 |
|
| 4289 |
[case testAliasFineInitGenericMod] |
| 4290 |
import c |
| 4291 |
[file a.py] |
| 4292 |
from typing import Generic, TypeVar |
| 4293 |
T = TypeVar('T') |
| 4294 |
S = TypeVar('S') |
| 4295 |
class A(Generic[T, S]): |
| 4296 |
def __init__(self, x: T) -> None: |
| 4297 |
pass |
| 4298 |
[file a.py.2] |
| 4299 |
from typing import Generic, TypeVar |
| 4300 |
T = TypeVar('T') |
| 4301 |
S = TypeVar('S') |
| 4302 |
class A(Generic[T, S]): |
| 4303 |
def __init__(self, x: S) -> None: |
| 4304 |
pass |
| 4305 |
[file b.py] |
| 4306 |
import a |
| 4307 |
B = a.A[int, str] |
| 4308 |
[file c.py] |
| 4309 |
from b import B |
| 4310 |
B(int()) |
| 4311 |
[out] |
| 4312 |
== |
| 4313 |
c.py:2: error: Argument 1 to "A" has incompatible type "int"; expected "str" |
| 4314 |
|
| 4315 |
[case testAliasFineInitGenericFunc] |
| 4316 |
import c |
| 4317 |
[file a.py] |
| 4318 |
from typing import Generic, TypeVar |
| 4319 |
T = TypeVar('T') |
| 4320 |
S = TypeVar('S') |
| 4321 |
class A(Generic[T, S]): |
| 4322 |
def __init__(self, x: T) -> None: |
| 4323 |
pass |
| 4324 |
[file a.py.2] |
| 4325 |
from typing import Generic, TypeVar |
| 4326 |
T = TypeVar('T') |
| 4327 |
S = TypeVar('S') |
| 4328 |
class A(Generic[T, S]): |
| 4329 |
def __init__(self, x: S) -> None: |
| 4330 |
pass |
| 4331 |
[file b.py] |
| 4332 |
import a |
| 4333 |
B = a.A[int, str] |
| 4334 |
[file c.py] |
| 4335 |
from b import B |
| 4336 |
def f() -> None: |
| 4337 |
B(str()) |
| 4338 |
[out] |
| 4339 |
c.py:3: error: Argument 1 to "A" has incompatible type "str"; expected "int" |
| 4340 |
== |
| 4341 |
|
| 4342 |
[case testAliasFineInitChainedMod] |
| 4343 |
import d |
| 4344 |
[file a.py] |
| 4345 |
class A: |
| 4346 |
def __init__(self, x: int) -> None: |
| 4347 |
pass |
| 4348 |
[file a.py.2] |
| 4349 |
class A: |
| 4350 |
def __init__(self, x: str) -> None: |
| 4351 |
pass |
| 4352 |
[file b.py] |
| 4353 |
import a |
| 4354 |
B = a.A |
| 4355 |
[file c.py] |
| 4356 |
import b |
| 4357 |
C = b.B |
| 4358 |
[file d.py] |
| 4359 |
from c import C |
| 4360 |
C(int()) |
| 4361 |
[out] |
| 4362 |
== |
| 4363 |
d.py:2: error: Argument 1 to "A" has incompatible type "int"; expected "str" |
| 4364 |
|
| 4365 |
[case testAliasFineInitChainedFunc] |
| 4366 |
import d |
| 4367 |
[file a.py] |
| 4368 |
class A: |
| 4369 |
def __init__(self, x: int) -> None: |
| 4370 |
pass |
| 4371 |
[file a.py.2] |
| 4372 |
class A: |
| 4373 |
def __init__(self, x: str) -> None: |
| 4374 |
pass |
| 4375 |
[file b.py] |
| 4376 |
import a |
| 4377 |
B = a.A |
| 4378 |
[file c.py] |
| 4379 |
import b |
| 4380 |
C = b.B |
| 4381 |
[file d.py] |
| 4382 |
from c import C |
| 4383 |
def f() -> None: |
| 4384 |
C(str()) |
| 4385 |
[out] |
| 4386 |
d.py:3: error: Argument 1 to "A" has incompatible type "str"; expected "int" |
| 4387 |
== |
| 4388 |
|
| 4389 |
[case testNonePartialType1] |
| 4390 |
from typing import Optional |
| 4391 |
import m |
| 4392 |
|
| 4393 |
def foo() -> Optional[int]: |
| 4394 |
return m.x |
| 4395 |
[file m.py] |
| 4396 |
import a |
| 4397 |
|
| 4398 |
x = None |
| 4399 |
|
| 4400 |
def f() -> None: |
| 4401 |
global x |
| 4402 |
x = a.y |
| 4403 |
[file a.py] |
| 4404 |
y = 0 |
| 4405 |
[file a.py.2] |
| 4406 |
y = '' |
| 4407 |
[out] |
| 4408 |
== |
| 4409 |
main:5: error: Incompatible return value type (got "str | None", expected "int | None") |
| 4410 |
|
| 4411 |
[case testNonePartialType2] |
| 4412 |
from typing import Optional |
| 4413 |
import m |
| 4414 |
|
| 4415 |
def foo() -> Optional[int]: |
| 4416 |
return m.x |
| 4417 |
[file m.py] |
| 4418 |
from typing import TypeVar |
| 4419 |
import a |
| 4420 |
|
| 4421 |
x = None |
| 4422 |
|
| 4423 |
F = TypeVar("F") |
| 4424 |
def dec(fn: F) -> F: ... |
| 4425 |
|
| 4426 |
@dec |
| 4427 |
def f() -> None: |
| 4428 |
global x |
| 4429 |
x = a.y |
| 4430 |
[file a.py] |
| 4431 |
y = 0 |
| 4432 |
[file a.py.2] |
| 4433 |
y = '' |
| 4434 |
[out] |
| 4435 |
== |
| 4436 |
main:5: error: Incompatible return value type (got "str | None", expected "int | None") |
| 4437 |
|
| 4438 |
[case testNonePartialType3] |
| 4439 |
import a |
| 4440 |
[file a.py] |
| 4441 |
[file a.py.2] |
| 4442 |
y = None |
| 4443 |
def f() -> None: |
| 4444 |
global y |
| 4445 |
y = '' |
| 4446 |
[out] |
| 4447 |
== |
| 4448 |
|
| 4449 |
[case testNonePartialType4] |
| 4450 |
from typing import Optional |
| 4451 |
import a |
| 4452 |
|
| 4453 |
def foo() -> Optional[str]: |
| 4454 |
return a.y |
| 4455 |
[file a.py] |
| 4456 |
y = None |
| 4457 |
def f() -> None: |
| 4458 |
global y |
| 4459 |
y = '' |
| 4460 |
[file a.py.2] |
| 4461 |
from typing import Optional |
| 4462 |
y: Optional[str] = None |
| 4463 |
def f() -> None: |
| 4464 |
global y |
| 4465 |
y = '' |
| 4466 |
[out] |
| 4467 |
== |
| 4468 |
|
| 4469 |
[case testSkippedClass1] |
| 4470 |
import a |
| 4471 |
[file a.py] |
| 4472 |
class A: pass |
| 4473 |
[file a.py.2] |
| 4474 |
import sys |
| 4475 |
if sys.platform == 'xyz': |
| 4476 |
class A: pass |
| 4477 |
[builtins fixtures/ops.pyi] |
| 4478 |
[out] |
| 4479 |
== |
| 4480 |
|
| 4481 |
[case testSkippedClass2] |
| 4482 |
import a |
| 4483 |
[file a.py] |
| 4484 |
import sys |
| 4485 |
if sys.platform == 'xyz': |
| 4486 |
class A: pass |
| 4487 |
[file a.py.2] |
| 4488 |
import sys |
| 4489 |
if sys.platform == 'xyz': |
| 4490 |
class A: pass |
| 4491 |
[builtins fixtures/ops.pyi] |
| 4492 |
[out] |
| 4493 |
== |
| 4494 |
|
| 4495 |
[case testSkippedClass3] |
| 4496 |
import a |
| 4497 |
[file a.py] |
| 4498 |
import sys |
| 4499 |
if sys.platform == 'xyz': |
| 4500 |
class A: pass |
| 4501 |
[file a.py.2] |
| 4502 |
class A: pass |
| 4503 |
[builtins fixtures/ops.pyi] |
| 4504 |
[out] |
| 4505 |
== |
| 4506 |
|
| 4507 |
[case testSkippedClass4] |
| 4508 |
import a |
| 4509 |
[file a.py] |
| 4510 |
import sys |
| 4511 |
if sys.platform == 'xyz': |
| 4512 |
class A: pass |
| 4513 |
else: |
| 4514 |
class A: pass |
| 4515 |
[file a.py.2] |
| 4516 |
import sys |
| 4517 |
if sys.platform == 'xyz': |
| 4518 |
class A: pass |
| 4519 |
else: |
| 4520 |
class A: pass |
| 4521 |
[builtins fixtures/ops.pyi] |
| 4522 |
[out] |
| 4523 |
== |
| 4524 |
|
| 4525 |
[case testNewTypeDependencies1] |
| 4526 |
from a import N |
| 4527 |
|
| 4528 |
def f(x: N) -> None: |
| 4529 |
x.y = 1 |
| 4530 |
[file a.py] |
| 4531 |
from typing import NewType |
| 4532 |
from b import C |
| 4533 |
|
| 4534 |
N = NewType('N', C) |
| 4535 |
[file b.py] |
| 4536 |
class C: |
| 4537 |
y: int |
| 4538 |
[file b.py.2] |
| 4539 |
class C: |
| 4540 |
y: str |
| 4541 |
[out] |
| 4542 |
== |
| 4543 |
main:4: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 4544 |
|
| 4545 |
[case testNewTypeDependencies2] |
| 4546 |
from a import N |
| 4547 |
from b import C, D |
| 4548 |
|
| 4549 |
def f(x: C) -> None: pass |
| 4550 |
|
| 4551 |
def g(x: N) -> None: |
| 4552 |
f(x) |
| 4553 |
[file a.py] |
| 4554 |
from typing import NewType |
| 4555 |
from b import D |
| 4556 |
|
| 4557 |
N = NewType('N', D) |
| 4558 |
[file b.py] |
| 4559 |
class C: pass |
| 4560 |
class D(C): pass |
| 4561 |
[file b.py.2] |
| 4562 |
class C: pass |
| 4563 |
class D: pass |
| 4564 |
[out] |
| 4565 |
== |
| 4566 |
main:7: error: Argument 1 to "f" has incompatible type "N"; expected "C" |
| 4567 |
|
| 4568 |
[case testNewTypeDependencies3] |
| 4569 |
from a import N |
| 4570 |
|
| 4571 |
def f(x: N) -> None: |
| 4572 |
x.y |
| 4573 |
[file a.py] |
| 4574 |
from typing import NewType |
| 4575 |
from b import C |
| 4576 |
N = NewType('N', C) |
| 4577 |
[file a.py.2] |
| 4578 |
from typing import NewType |
| 4579 |
from b import D |
| 4580 |
N = NewType('N', D) |
| 4581 |
[file b.py] |
| 4582 |
class C: |
| 4583 |
y: int |
| 4584 |
class D: |
| 4585 |
pass |
| 4586 |
[out] |
| 4587 |
== |
| 4588 |
main:4: error: "N" has no attribute "y" |
| 4589 |
|
| 4590 |
[case testNamedTupleWithinFunction] |
| 4591 |
from typing import NamedTuple |
| 4592 |
import b |
| 4593 |
def f() -> None: |
| 4594 |
b.x |
| 4595 |
n = NamedTuple('n', []) |
| 4596 |
[file b.py] |
| 4597 |
x = 0 |
| 4598 |
[file b.py.2] |
| 4599 |
x = '' |
| 4600 |
[builtins fixtures/tuple.pyi] |
| 4601 |
[out] |
| 4602 |
== |
| 4603 |
|
| 4604 |
[case testNamedTupleFallback] |
| 4605 |
# This test will fail without semantic analyzer pass 2 patches |
| 4606 |
import a |
| 4607 |
[file a.py] |
| 4608 |
import b |
| 4609 |
[file b.py] |
| 4610 |
from typing import NamedTuple |
| 4611 |
import c |
| 4612 |
c.x |
| 4613 |
class N(NamedTuple): |
| 4614 |
count: int |
| 4615 |
[file c.py] |
| 4616 |
x = 0 |
| 4617 |
[file c.py.2] |
| 4618 |
x = '' |
| 4619 |
[builtins fixtures/tuple.pyi] |
| 4620 |
[out] |
| 4621 |
b.py:5: error: Incompatible types in assignment (expression has type "int", base class "tuple" defined the type as "Callable[[object], int]") |
| 4622 |
== |
| 4623 |
b.py:5: error: Incompatible types in assignment (expression has type "int", base class "tuple" defined the type as "Callable[[object], int]") |
| 4624 |
|
| 4625 |
[case testReprocessEllipses1] |
| 4626 |
import a |
| 4627 |
[file a.py] |
| 4628 |
from typing import Tuple |
| 4629 |
def foo(x: Tuple[int, ...]) -> None: pass |
| 4630 |
[file a.py.2] |
| 4631 |
from typing import Tuple |
| 4632 |
def foo(x: Tuple[int, ...]) -> None: pass |
| 4633 |
[builtins fixtures/tuple.pyi] |
| 4634 |
[out] |
| 4635 |
== |
| 4636 |
|
| 4637 |
[case testReprocessEllipses2] |
| 4638 |
import a |
| 4639 |
[file a.py] |
| 4640 |
from typing import Callable |
| 4641 |
def foo(x: Callable[..., int]) -> None: pass |
| 4642 |
[file a.py.2] |
| 4643 |
from typing import Callable |
| 4644 |
def foo(x: Callable[..., int]) -> None: pass |
| 4645 |
[out] |
| 4646 |
== |
| 4647 |
|
| 4648 |
[case testReprocessCallableArg] |
| 4649 |
import a |
| 4650 |
[file a.py] |
| 4651 |
from typing import Callable |
| 4652 |
from mypy_extensions import Arg |
| 4653 |
def a(f: Callable[[Arg(int, 'x')], int]) -> None: pass |
| 4654 |
[file a.py.2] |
| 4655 |
from typing import Callable |
| 4656 |
from mypy_extensions import Arg |
| 4657 |
def a(f: Callable[[Arg(int, 'x')], int]) -> None: pass |
| 4658 |
[builtins fixtures/dict.pyi] |
| 4659 |
[out] |
| 4660 |
== |
| 4661 |
|
| 4662 |
[case testImplicitTuple1] |
| 4663 |
import a |
| 4664 |
[file a.py] |
| 4665 |
# Bogus annotation in nested function masked because outer function |
| 4666 |
# isn't annotated |
| 4667 |
def unchecked(): |
| 4668 |
def inner(): |
| 4669 |
# type: () -> (str, int) |
| 4670 |
return 'lol', 10 |
| 4671 |
[file a.py.2] |
| 4672 |
# dummy change |
| 4673 |
def unchecked(): |
| 4674 |
def inner(): |
| 4675 |
# type: () -> (str, int) |
| 4676 |
return 'lol', 10 |
| 4677 |
[builtins fixtures/tuple.pyi] |
| 4678 |
[out] |
| 4679 |
== |
| 4680 |
|
| 4681 |
[case testImplicitTuple2] |
| 4682 |
import a |
| 4683 |
[file a.py] |
| 4684 |
def inner(): |
| 4685 |
# type: () -> (str, int) |
| 4686 |
return 'lol', 10 |
| 4687 |
[file a.py.2] |
| 4688 |
# dummy change |
| 4689 |
def inner(): |
| 4690 |
# type: () -> (str, int) |
| 4691 |
return 'lol', 10 |
| 4692 |
[builtins fixtures/tuple.pyi] |
| 4693 |
[out] |
| 4694 |
a.py:1: error: Syntax error in type annotation |
| 4695 |
a.py:1: note: Suggestion: Use Tuple[T1, ..., Tn] instead of (T1, ..., Tn) |
| 4696 |
== |
| 4697 |
a.py:2: error: Syntax error in type annotation |
| 4698 |
a.py:2: note: Suggestion: Use Tuple[T1, ..., Tn] instead of (T1, ..., Tn) |
| 4699 |
|
| 4700 |
[case testImplicitTuple3] |
| 4701 |
import a |
| 4702 |
[file a.py] |
| 4703 |
(x, y) = 1, 'hi' # type: (int, str) |
| 4704 |
[file a.py.2] |
| 4705 |
# dummy change |
| 4706 |
(x, y) = 1, 'hi' # type: (int, str) |
| 4707 |
[builtins fixtures/tuple.pyi] |
| 4708 |
[out] |
| 4709 |
== |
| 4710 |
|
| 4711 |
[case testCastConfusion] |
| 4712 |
import b |
| 4713 |
[file a.py] |
| 4714 |
from typing import cast |
| 4715 |
class Thing: |
| 4716 |
def foo(self) -> None: pass |
| 4717 |
|
| 4718 |
thing = cast(Thing, Thing()) |
| 4719 |
|
| 4720 |
[file b.py] |
| 4721 |
from typing import Optional |
| 4722 |
from a import Thing, thing |
| 4723 |
class User: |
| 4724 |
def __init__(self, x: Optional[Thing]) -> None: |
| 4725 |
self.x = x if x else thing |
| 4726 |
def use(self) -> None: self.x.foo() |
| 4727 |
|
| 4728 |
[file a.py.2] |
| 4729 |
from typing import cast |
| 4730 |
class Thing: |
| 4731 |
def foo(self) -> None: pass |
| 4732 |
|
| 4733 |
thing = cast(Thing, Thing()) |
| 4734 |
# update |
| 4735 |
|
| 4736 |
[file b.py.2] |
| 4737 |
from typing import Optional |
| 4738 |
from a import Thing, thing |
| 4739 |
class User: |
| 4740 |
def __init__(self, x: Optional[Thing]) -> None: |
| 4741 |
self.x = x if x else thing |
| 4742 |
def use(self) -> None: self.x.foo() |
| 4743 |
# update |
| 4744 |
[builtins fixtures/ops.pyi] |
| 4745 |
[out] |
| 4746 |
== |
| 4747 |
|
| 4748 |
[case testNoStrictOptionalModule] |
| 4749 |
# flags: --no-strict-optional |
| 4750 |
import a |
| 4751 |
a.y = a.x |
| 4752 |
[file a.py] |
| 4753 |
from typing import Optional |
| 4754 |
x: int |
| 4755 |
y: int |
| 4756 |
[file a.py.2] |
| 4757 |
from typing import Optional |
| 4758 |
x: Optional[int] |
| 4759 |
y: int |
| 4760 |
[file a.py.3] |
| 4761 |
from typing import Optional |
| 4762 |
x: Optional[str] |
| 4763 |
y: int |
| 4764 |
[out] |
| 4765 |
== |
| 4766 |
== |
| 4767 |
main:3: error: Incompatible types in assignment (expression has type "str | None", variable has type "int") |
| 4768 |
|
| 4769 |
[case testNoStrictOptionalFunction] |
| 4770 |
# flags: --no-strict-optional |
| 4771 |
import a |
| 4772 |
from typing import Optional |
| 4773 |
def f() -> None: |
| 4774 |
x: Optional[int] |
| 4775 |
a.g(x) |
| 4776 |
[file a.py] |
| 4777 |
from typing import Optional |
| 4778 |
def g(x: Optional[int]) -> None: |
| 4779 |
pass |
| 4780 |
[file a.py.2] |
| 4781 |
from typing import Optional |
| 4782 |
def g(x: int) -> None: |
| 4783 |
pass |
| 4784 |
[file a.py.3] |
| 4785 |
from typing import Optional |
| 4786 |
def g(x: str) -> None: |
| 4787 |
pass |
| 4788 |
[out] |
| 4789 |
== |
| 4790 |
== |
| 4791 |
main:6: error: Argument 1 to "g" has incompatible type "int | None"; expected "str" |
| 4792 |
|
| 4793 |
[case testNoStrictOptionalMethod] |
| 4794 |
# flags: --no-strict-optional |
| 4795 |
import a |
| 4796 |
from typing import Optional |
| 4797 |
class C: |
| 4798 |
def f(self) -> None: |
| 4799 |
x: Optional[int] |
| 4800 |
a.B().g(x) |
| 4801 |
[file a.py] |
| 4802 |
from typing import Optional |
| 4803 |
class B: |
| 4804 |
def g(self, x: Optional[int]) -> None: |
| 4805 |
pass |
| 4806 |
[file a.py.2] |
| 4807 |
from typing import Optional |
| 4808 |
class B: |
| 4809 |
def g(self, x: int) -> None: |
| 4810 |
pass |
| 4811 |
[file a.py.3] |
| 4812 |
from typing import Optional |
| 4813 |
class B: |
| 4814 |
def g(self, x: str) -> None: |
| 4815 |
pass |
| 4816 |
[out] |
| 4817 |
== |
| 4818 |
== |
| 4819 |
main:7: error: Argument 1 to "g" of "B" has incompatible type "int | None"; expected "str" |
| 4820 |
|
| 4821 |
[case testStrictOptionalModule] |
| 4822 |
import a |
| 4823 |
a.y = a.x |
| 4824 |
[file a.py] |
| 4825 |
from typing import Optional |
| 4826 |
x: int |
| 4827 |
y: int |
| 4828 |
[file a.py.2] |
| 4829 |
from typing import Optional |
| 4830 |
x: Optional[int] |
| 4831 |
y: int |
| 4832 |
[out] |
| 4833 |
== |
| 4834 |
main:2: error: Incompatible types in assignment (expression has type "int | None", variable has type "int") |
| 4835 |
|
| 4836 |
[case testStrictOptionalFunction] |
| 4837 |
import a |
| 4838 |
from typing import Optional |
| 4839 |
def f() -> None: |
| 4840 |
x: Optional[int] |
| 4841 |
a.g(x) |
| 4842 |
[file a.py] |
| 4843 |
from typing import Optional |
| 4844 |
def g(x: Optional[int]) -> None: |
| 4845 |
pass |
| 4846 |
[file a.py.2] |
| 4847 |
from typing import Optional |
| 4848 |
def g(x: int) -> None: |
| 4849 |
pass |
| 4850 |
[out] |
| 4851 |
== |
| 4852 |
main:5: error: Argument 1 to "g" has incompatible type "int | None"; expected "int" |
| 4853 |
|
| 4854 |
[case testStrictOptionalMethod] |
| 4855 |
import a |
| 4856 |
from typing import Optional |
| 4857 |
class C: |
| 4858 |
def f(self) -> None: |
| 4859 |
x: Optional[int] |
| 4860 |
a.B().g(x) |
| 4861 |
[file a.py] |
| 4862 |
from typing import Optional |
| 4863 |
class B: |
| 4864 |
def g(self, x: Optional[int]) -> None: |
| 4865 |
pass |
| 4866 |
[file a.py.2] |
| 4867 |
from typing import Optional |
| 4868 |
class B: |
| 4869 |
def g(self, x: int) -> None: |
| 4870 |
pass |
| 4871 |
[out] |
| 4872 |
== |
| 4873 |
main:6: error: Argument 1 to "g" of "B" has incompatible type "int | None"; expected "int" |
| 4874 |
|
| 4875 |
[case testPerFileStrictOptionalModule] |
| 4876 |
import a |
| 4877 |
[file mypy.ini] |
| 4878 |
\[mypy] |
| 4879 |
strict_optional = False |
| 4880 |
\[mypy-a.*] |
| 4881 |
strict_optional = True |
| 4882 |
[file a.py] |
| 4883 |
from typing import Optional |
| 4884 |
import b |
| 4885 |
x: int |
| 4886 |
y: int = x |
| 4887 |
[file b.py] |
| 4888 |
from typing import Optional |
| 4889 |
x: int |
| 4890 |
y: int = x |
| 4891 |
[file b.py.2] |
| 4892 |
from typing import Optional |
| 4893 |
x: Optional[int] |
| 4894 |
y: int = x |
| 4895 |
[file a.py.3] |
| 4896 |
from typing import Optional |
| 4897 |
import b |
| 4898 |
x: Optional[int] |
| 4899 |
y: int = x |
| 4900 |
[out] |
| 4901 |
== |
| 4902 |
== |
| 4903 |
a.py:4: error: Incompatible types in assignment (expression has type "int | None", variable has type "int") |
| 4904 |
|
| 4905 |
[case testPerFileStrictOptionalModuleOnly] |
| 4906 |
import a |
| 4907 |
[file mypy.ini] |
| 4908 |
\[mypy] |
| 4909 |
strict_optional = False |
| 4910 |
\[mypy-a.*] |
| 4911 |
strict_optional = True |
| 4912 |
[file a.py] |
| 4913 |
from typing import Optional |
| 4914 |
import b |
| 4915 |
y: int = b.x |
| 4916 |
class Dummy: |
| 4917 |
def f(self) -> None: |
| 4918 |
pass |
| 4919 |
[file b.py] |
| 4920 |
from typing import Optional |
| 4921 |
import c |
| 4922 |
x: int |
| 4923 |
y: int = c.x |
| 4924 |
class Dummy: |
| 4925 |
def f(self) -> None: |
| 4926 |
pass |
| 4927 |
[file c.py] |
| 4928 |
from typing import Optional |
| 4929 |
x: int |
| 4930 |
[file c.py.2] |
| 4931 |
from typing import Optional |
| 4932 |
x: Optional[int] |
| 4933 |
[file b.py.3] |
| 4934 |
from typing import Optional |
| 4935 |
import c |
| 4936 |
x: Optional[int] |
| 4937 |
y: int = c.x |
| 4938 |
[file a.py.4] |
| 4939 |
from typing import Optional |
| 4940 |
import b |
| 4941 |
y: Optional[int] = b.x |
| 4942 |
class Dummy: |
| 4943 |
def f(self) -> None: |
| 4944 |
pass |
| 4945 |
[out] |
| 4946 |
== |
| 4947 |
== |
| 4948 |
a.py:3: error: Incompatible types in assignment (expression has type "int | None", variable has type "int") |
| 4949 |
== |
| 4950 |
|
| 4951 |
[case testPerFileStrictOptionalFunction] |
| 4952 |
import a |
| 4953 |
[file mypy.ini] |
| 4954 |
\[mypy] |
| 4955 |
strict_optional = False |
| 4956 |
\[mypy-b.*] |
| 4957 |
strict_optional = True |
| 4958 |
[file a.py] |
| 4959 |
from typing import Optional |
| 4960 |
import b |
| 4961 |
def f() -> None: |
| 4962 |
x: int |
| 4963 |
x = b.g(x) |
| 4964 |
[file b.py] |
| 4965 |
from typing import Optional |
| 4966 |
import c |
| 4967 |
def g(x: Optional[int]) -> Optional[int]: |
| 4968 |
return c.h(x) |
| 4969 |
[file c.py] |
| 4970 |
from typing import Optional |
| 4971 |
def h(x: Optional[int]) -> int: |
| 4972 |
pass |
| 4973 |
[file c.py.2] |
| 4974 |
from typing import Optional |
| 4975 |
def h(x: int) -> int: |
| 4976 |
pass |
| 4977 |
[file b.py.3] |
| 4978 |
from typing import Optional |
| 4979 |
import c |
| 4980 |
def g(x: int) -> Optional[int]: |
| 4981 |
return c.h(x) |
| 4982 |
[out] |
| 4983 |
== |
| 4984 |
b.py:4: error: Argument 1 to "h" has incompatible type "int | None"; expected "int" |
| 4985 |
== |
| 4986 |
|
| 4987 |
[case testPerFileStrictOptionalMethod] |
| 4988 |
import a |
| 4989 |
[file mypy.ini] |
| 4990 |
\[mypy] |
| 4991 |
strict_optional = False |
| 4992 |
\[mypy-b.*] |
| 4993 |
strict_optional = True |
| 4994 |
[file a.py] |
| 4995 |
from typing import Optional |
| 4996 |
import b |
| 4997 |
class A: |
| 4998 |
def f(self) -> None: |
| 4999 |
x: int |
| 5000 |
x = b.B().g(x) |
| 5001 |
[file b.py] |
| 5002 |
from typing import Optional |
| 5003 |
import c |
| 5004 |
class B: |
| 5005 |
def g(self, x: Optional[int]) -> Optional[int]: |
| 5006 |
return c.C().h(x) |
| 5007 |
[file c.py] |
| 5008 |
from typing import Optional |
| 5009 |
class C: |
| 5010 |
def h(self, x: Optional[int]) -> int: |
| 5011 |
pass |
| 5012 |
[file c.py.2] |
| 5013 |
from typing import Optional |
| 5014 |
class C: |
| 5015 |
def h(self, x: int) -> int: |
| 5016 |
pass |
| 5017 |
[file b.py.3] |
| 5018 |
from typing import Optional |
| 5019 |
import c |
| 5020 |
class B: |
| 5021 |
def g(self, x: int) -> Optional[int]: |
| 5022 |
return c.C().h(x) |
| 5023 |
[out] |
| 5024 |
== |
| 5025 |
b.py:5: error: Argument 1 to "h" of "C" has incompatible type "int | None"; expected "int" |
| 5026 |
== |
| 5027 |
|
| 5028 |
[case testTypeVarValuesFunction] |
| 5029 |
import a |
| 5030 |
[file a.py] |
| 5031 |
from typing import TypeVar |
| 5032 |
from c import A, B |
| 5033 |
T = TypeVar('T', A, B) |
| 5034 |
|
| 5035 |
def f(x: T) -> T: |
| 5036 |
x.x = int() |
| 5037 |
return x |
| 5038 |
[file c.py] |
| 5039 |
class A: |
| 5040 |
x: int |
| 5041 |
class B: |
| 5042 |
x: int |
| 5043 |
[file c.py.2] |
| 5044 |
class A: |
| 5045 |
x: int |
| 5046 |
class B: |
| 5047 |
x: str |
| 5048 |
[out] |
| 5049 |
== |
| 5050 |
a.py:6: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 5051 |
|
| 5052 |
[case testTypeVarValuesClass] |
| 5053 |
import a |
| 5054 |
[file a.py] |
| 5055 |
import c |
| 5056 |
class C: |
| 5057 |
x: c.D[c.A] |
| 5058 |
[file c.py] |
| 5059 |
from typing import TypeVar, Generic |
| 5060 |
class A: pass |
| 5061 |
class B: pass |
| 5062 |
class C: pass |
| 5063 |
T = TypeVar('T', A, B, C) |
| 5064 |
class D(Generic[T]): |
| 5065 |
pass |
| 5066 |
[file c.py.2] |
| 5067 |
from typing import TypeVar, Generic |
| 5068 |
class A: pass |
| 5069 |
class B: pass |
| 5070 |
class C: pass |
| 5071 |
T = TypeVar('T', B, C) |
| 5072 |
class D(Generic[T]): |
| 5073 |
pass |
| 5074 |
[out] |
| 5075 |
== |
| 5076 |
a.py:3: error: Value of type variable "T" of "D" cannot be "A" |
| 5077 |
|
| 5078 |
[case testTypeVarValuesMethod1] |
| 5079 |
import a |
| 5080 |
[file a.py] |
| 5081 |
from typing import Generic |
| 5082 |
import c |
| 5083 |
class G(Generic[c.T]): |
| 5084 |
def f(self, x: c.T) -> None: |
| 5085 |
x.x = int() |
| 5086 |
[file c.py] |
| 5087 |
from typing import TypeVar |
| 5088 |
class A: |
| 5089 |
x: int |
| 5090 |
class B: |
| 5091 |
x: int |
| 5092 |
class C: |
| 5093 |
x: str |
| 5094 |
T = TypeVar('T', A, B, C) |
| 5095 |
[file c.py.2] |
| 5096 |
from typing import TypeVar |
| 5097 |
class A: |
| 5098 |
x: int |
| 5099 |
class B: |
| 5100 |
x: int |
| 5101 |
class C: |
| 5102 |
x: str |
| 5103 |
T = TypeVar('T', A, B) |
| 5104 |
[out] |
| 5105 |
a.py:5: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 5106 |
== |
| 5107 |
|
| 5108 |
[case testTypeVarValuesMethod2] |
| 5109 |
import a |
| 5110 |
[file a.py] |
| 5111 |
from typing import Generic |
| 5112 |
import c |
| 5113 |
class G(Generic[c.T]): |
| 5114 |
def f(self, x: c.T) -> None: |
| 5115 |
x.x = int() |
| 5116 |
[file c.py] |
| 5117 |
from typing import TypeVar |
| 5118 |
class A: |
| 5119 |
x: int |
| 5120 |
class B: |
| 5121 |
x: int |
| 5122 |
T = TypeVar('T', A, B) |
| 5123 |
[file c.py.2] |
| 5124 |
from typing import TypeVar |
| 5125 |
class A: |
| 5126 |
x: int |
| 5127 |
class B: |
| 5128 |
x: str |
| 5129 |
T = TypeVar('T', A, B) |
| 5130 |
[out] |
| 5131 |
== |
| 5132 |
a.py:5: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 5133 |
|
| 5134 |
[case testTypeVarBoundFunction] |
| 5135 |
import a |
| 5136 |
[file a.py] |
| 5137 |
from typing import TypeVar |
| 5138 |
from c import B |
| 5139 |
T = TypeVar('T', bound=B) |
| 5140 |
|
| 5141 |
def f(x: T) -> T: |
| 5142 |
x.x = int() |
| 5143 |
return x |
| 5144 |
[file c.py] |
| 5145 |
class B: |
| 5146 |
x: int |
| 5147 |
[file c.py.2] |
| 5148 |
class B: |
| 5149 |
x: str |
| 5150 |
[out] |
| 5151 |
== |
| 5152 |
a.py:6: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 5153 |
|
| 5154 |
[case testTypeVarBoundClass] |
| 5155 |
import a |
| 5156 |
[file a.py] |
| 5157 |
import c |
| 5158 |
class C: |
| 5159 |
x: c.D[c.A] |
| 5160 |
[file c.py] |
| 5161 |
from typing import TypeVar, Generic |
| 5162 |
class A: pass |
| 5163 |
class B: pass |
| 5164 |
T = TypeVar('T', bound=A) |
| 5165 |
class D(Generic[T]): |
| 5166 |
pass |
| 5167 |
[file c.py.2] |
| 5168 |
from typing import TypeVar, Generic |
| 5169 |
class A: pass |
| 5170 |
class B: pass |
| 5171 |
T = TypeVar('T', bound=B) |
| 5172 |
class D(Generic[T]): |
| 5173 |
pass |
| 5174 |
[out] |
| 5175 |
== |
| 5176 |
a.py:3: error: Type argument "A" of "D" must be a subtype of "B" |
| 5177 |
|
| 5178 |
[case testTypeVarValuesRuntime] |
| 5179 |
from mod import I, S, D |
| 5180 |
A = I |
| 5181 |
x = D[S, A]() |
| 5182 |
[file mod.py] |
| 5183 |
import submod |
| 5184 |
from typing import Generic |
| 5185 |
class D(Generic[submod.T, submod.U]): pass |
| 5186 |
class I: pass |
| 5187 |
class S: pass |
| 5188 |
[file submod.py] |
| 5189 |
from typing import TypeVar |
| 5190 |
T = TypeVar('T') |
| 5191 |
U = TypeVar('U') |
| 5192 |
[file submod.py.2] |
| 5193 |
from typing import TypeVar |
| 5194 |
T = TypeVar('T', int, str) |
| 5195 |
U = TypeVar('U', int, str) |
| 5196 |
[out] |
| 5197 |
== |
| 5198 |
main:3: error: Value of type variable "submod.T" of "D" cannot be "S" |
| 5199 |
main:3: error: Value of type variable "submod.U" of "D" cannot be "I" |
| 5200 |
|
| 5201 |
[case testTypeVarBoundRuntime] |
| 5202 |
from mod import I, S, D |
| 5203 |
A = I |
| 5204 |
x = D[S, A]() |
| 5205 |
[file mod.py] |
| 5206 |
import submod |
| 5207 |
from typing import Generic |
| 5208 |
class D(Generic[submod.T, submod.U]): pass |
| 5209 |
class I: pass |
| 5210 |
class S: pass |
| 5211 |
[file submod.py] |
| 5212 |
from typing import TypeVar |
| 5213 |
T = TypeVar('T', bound=int) |
| 5214 |
U = TypeVar('U', bound=int) |
| 5215 |
[file submod.py.2] |
| 5216 |
from typing import TypeVar |
| 5217 |
T = TypeVar('T') |
| 5218 |
U = TypeVar('U') |
| 5219 |
[out] |
| 5220 |
main:3: error: Value of type variable "submod.T" of "D" cannot be "S" |
| 5221 |
main:3: error: Value of type variable "submod.U" of "D" cannot be "I" |
| 5222 |
== |
| 5223 |
|
| 5224 |
[case testGenericFineCallableNormal] |
| 5225 |
import a |
| 5226 |
[file a.py] |
| 5227 |
import b |
| 5228 |
x: int = b.f(int()) |
| 5229 |
[file b.py] |
| 5230 |
from c import g |
| 5231 |
f = g |
| 5232 |
[file c.py] |
| 5233 |
from typing import TypeVar |
| 5234 |
class B: pass |
| 5235 |
T = TypeVar('T') |
| 5236 |
def g(x: T) -> T: |
| 5237 |
pass |
| 5238 |
[file c.py.2] |
| 5239 |
from typing import TypeVar |
| 5240 |
class B: pass |
| 5241 |
T = TypeVar('T', str, B) |
| 5242 |
def g(x: T) -> T: |
| 5243 |
pass |
| 5244 |
[out] |
| 5245 |
== |
| 5246 |
a.py:2: error: Value of type variable "T" of function cannot be "int" |
| 5247 |
|
| 5248 |
[case testGenericFineCallableNamed] |
| 5249 |
import a |
| 5250 |
[file a.py] |
| 5251 |
import b |
| 5252 |
x: int = b.f(x=int()) |
| 5253 |
[file b.py] |
| 5254 |
from c import g |
| 5255 |
f = g |
| 5256 |
[file c.py] |
| 5257 |
from typing import TypeVar |
| 5258 |
class B: pass |
| 5259 |
T = TypeVar('T') |
| 5260 |
def g(x: T) -> T: |
| 5261 |
pass |
| 5262 |
[file c.py.2] |
| 5263 |
from typing import TypeVar |
| 5264 |
class B: pass |
| 5265 |
T = TypeVar('T') |
| 5266 |
def g(y: T) -> T: |
| 5267 |
pass |
| 5268 |
[out] |
| 5269 |
== |
| 5270 |
a.py:2: error: Unexpected keyword argument "x" |
| 5271 |
a.py:2: note: Called function defined in "c" |
| 5272 |
|
| 5273 |
[case testGenericFineCallableInBound] |
| 5274 |
import a |
| 5275 |
[file a.py] |
| 5276 |
import b |
| 5277 |
x: int = b.f()(int()) |
| 5278 |
[file b.py] |
| 5279 |
from c import g |
| 5280 |
f = g |
| 5281 |
[file c.py] |
| 5282 |
from typing import Callable, TypeVar |
| 5283 |
class B: pass |
| 5284 |
T = TypeVar('T') |
| 5285 |
def g() -> Callable[[T], T]: |
| 5286 |
pass |
| 5287 |
[file c.py.2] |
| 5288 |
from typing import Callable, TypeVar |
| 5289 |
class B: pass |
| 5290 |
T = TypeVar('T', str, B) |
| 5291 |
def g() -> Callable[[T], T]: |
| 5292 |
pass |
| 5293 |
[out] |
| 5294 |
== |
| 5295 |
a.py:2: error: Value of type variable "T" of function cannot be "int" |
| 5296 |
|
| 5297 |
[case testGenericFineCallableAddedBound] |
| 5298 |
import a |
| 5299 |
[file a.py] |
| 5300 |
import b |
| 5301 |
x: int = b.f(int()) |
| 5302 |
[file b.py] |
| 5303 |
from c import g |
| 5304 |
f = g |
| 5305 |
[file c.py] |
| 5306 |
from typing import TypeVar |
| 5307 |
class B: pass |
| 5308 |
T = TypeVar('T') |
| 5309 |
def g(x: T) -> T: |
| 5310 |
pass |
| 5311 |
[file c.py.2] |
| 5312 |
from typing import TypeVar |
| 5313 |
class B: pass |
| 5314 |
T = TypeVar('T', bound=B) |
| 5315 |
def g(x: T) -> T: |
| 5316 |
pass |
| 5317 |
[out] |
| 5318 |
== |
| 5319 |
a.py:2: error: Value of type variable "T" of function cannot be "int" |
| 5320 |
|
| 5321 |
[case testGenericFineCallableBoundDeleted-only_when_cache] |
| 5322 |
# See https://github.com/python/mypy/issues/4783 |
| 5323 |
import a |
| 5324 |
[file a.py] |
| 5325 |
import b |
| 5326 |
x: int = b.f(int()) |
| 5327 |
[file b.py] |
| 5328 |
from c import g |
| 5329 |
f = g |
| 5330 |
[file c.py] |
| 5331 |
from typing import TypeVar |
| 5332 |
import d |
| 5333 |
T = TypeVar('T', bound=d.B) |
| 5334 |
def g(x: T) -> T: |
| 5335 |
pass |
| 5336 |
[file d.py] |
| 5337 |
class B: |
| 5338 |
pass |
| 5339 |
[file d.py.2] |
| 5340 |
# empty |
| 5341 |
[out] |
| 5342 |
a.py:2: error: Value of type variable "T" of function cannot be "int" |
| 5343 |
== |
| 5344 |
c.py:3: error: Name "d.B" is not defined |
| 5345 |
|
| 5346 |
[case testGenericFineCallableToNonGeneric] |
| 5347 |
import a |
| 5348 |
[file a.py] |
| 5349 |
import b |
| 5350 |
x: int = b.f(x=int()) |
| 5351 |
[file b.py] |
| 5352 |
from c import g |
| 5353 |
f = g |
| 5354 |
[file c.py] |
| 5355 |
from typing import TypeVar |
| 5356 |
T = TypeVar('T') |
| 5357 |
def g(x: T) -> T: |
| 5358 |
pass |
| 5359 |
[file c.py.2] |
| 5360 |
from typing import TypeVar |
| 5361 |
class T: pass |
| 5362 |
def g(x: T) -> T: |
| 5363 |
pass |
| 5364 |
[out] |
| 5365 |
== |
| 5366 |
a.py:2: error: Incompatible types in assignment (expression has type "T", variable has type "int") |
| 5367 |
a.py:2: error: Argument "x" has incompatible type "int"; expected "T" |
| 5368 |
|
| 5369 |
[case testGenericFineCallableToGenericClass] |
| 5370 |
import a |
| 5371 |
[file a.py] |
| 5372 |
import b |
| 5373 |
x: int = b.f(x=int()) |
| 5374 |
[file b.py] |
| 5375 |
from c import g |
| 5376 |
f = g |
| 5377 |
[file c.py] |
| 5378 |
from typing import TypeVar, Generic |
| 5379 |
T = TypeVar('T') |
| 5380 |
def g(x: T) -> T: |
| 5381 |
pass |
| 5382 |
[file c.py.2] |
| 5383 |
from typing import TypeVar, Generic |
| 5384 |
T = TypeVar('T') |
| 5385 |
class g(Generic[T]): |
| 5386 |
def __init__(self, x: T) -> None: |
| 5387 |
pass |
| 5388 |
[out] |
| 5389 |
== |
| 5390 |
a.py:2: error: Incompatible types in assignment (expression has type "g[int]", variable has type "int") |
| 5391 |
|
| 5392 |
[case testMakeClassNoLongerAbstract1] |
| 5393 |
[file z.py] |
| 5394 |
from abc import abstractmethod, ABCMeta |
| 5395 |
class I(metaclass=ABCMeta): |
| 5396 |
@abstractmethod |
| 5397 |
def f(self) -> None: pass |
| 5398 |
[file b.py] |
| 5399 |
from typing import Optional |
| 5400 |
from z import I |
| 5401 |
class Foo(I): |
| 5402 |
pass |
| 5403 |
def x() -> Optional[Foo]: return None |
| 5404 |
[file z.py.2] |
| 5405 |
from abc import abstractmethod, ABCMeta |
| 5406 |
class I(metaclass=ABCMeta): |
| 5407 |
pass |
| 5408 |
[file b.py.2] |
| 5409 |
from z import I |
| 5410 |
class Foo(I): |
| 5411 |
pass |
| 5412 |
def x() -> Foo: return Foo() |
| 5413 |
[out] |
| 5414 |
== |
| 5415 |
|
| 5416 |
[case testMakeClassNoLongerAbstract2] |
| 5417 |
-- this version never failed, but it is just a file-renaming |
| 5418 |
-- away from the above test that did |
| 5419 |
[file a.py] |
| 5420 |
from abc import abstractmethod, ABCMeta |
| 5421 |
class I(metaclass=ABCMeta): |
| 5422 |
@abstractmethod |
| 5423 |
def f(self) -> None: pass |
| 5424 |
[file b.py] |
| 5425 |
from typing import Optional |
| 5426 |
from a import I |
| 5427 |
class Foo(I): |
| 5428 |
pass |
| 5429 |
def x() -> Optional[Foo]: return None |
| 5430 |
[file a.py.2] |
| 5431 |
from abc import abstractmethod, ABCMeta |
| 5432 |
class I(metaclass=ABCMeta): |
| 5433 |
pass |
| 5434 |
[file b.py.2] |
| 5435 |
from a import I |
| 5436 |
class Foo(I): |
| 5437 |
pass |
| 5438 |
def x() -> Foo: return Foo() |
| 5439 |
[out] |
| 5440 |
== |
| 5441 |
|
| 5442 |
[case testRefreshClassBasedEnum] |
| 5443 |
import aa |
| 5444 |
[file aa.py] |
| 5445 |
import a |
| 5446 |
[file a.py] |
| 5447 |
from enum import Enum |
| 5448 |
import b |
| 5449 |
b.x |
| 5450 |
class C(Enum): |
| 5451 |
X = 0 |
| 5452 |
[file b.py] |
| 5453 |
x = 0 |
| 5454 |
[file b.py.2] |
| 5455 |
x = '' |
| 5456 |
[file aa.py.3] |
| 5457 |
from a import C |
| 5458 |
c: C |
| 5459 |
c = C.X |
| 5460 |
if int(): |
| 5461 |
c = 1 |
| 5462 |
[builtins fixtures/enum.pyi] |
| 5463 |
[out] |
| 5464 |
== |
| 5465 |
== |
| 5466 |
aa.py:5: error: Incompatible types in assignment (expression has type "int", variable has type "C") |
| 5467 |
|
| 5468 |
[case testRefreshClassBasedIntEnum] |
| 5469 |
import aa |
| 5470 |
[file aa.py] |
| 5471 |
import a |
| 5472 |
[file a.py] |
| 5473 |
from enum import IntEnum |
| 5474 |
import b |
| 5475 |
b.x |
| 5476 |
class C(IntEnum): |
| 5477 |
X = 0 |
| 5478 |
x: int |
| 5479 |
x = C.X |
| 5480 |
[file b.py] |
| 5481 |
x = 0 |
| 5482 |
[file b.py.2] |
| 5483 |
x = '' |
| 5484 |
[file aa.py.3] |
| 5485 |
from a import C |
| 5486 |
c: C |
| 5487 |
c = C.X |
| 5488 |
if int(): |
| 5489 |
c = 1 |
| 5490 |
n: int |
| 5491 |
n = C.X |
| 5492 |
if int(): |
| 5493 |
n = c |
| 5494 |
[builtins fixtures/enum.pyi] |
| 5495 |
[out] |
| 5496 |
== |
| 5497 |
== |
| 5498 |
aa.py:5: error: Incompatible types in assignment (expression has type "int", variable has type "C") |
| 5499 |
|
| 5500 |
[case testClassBasedEnumPropagation1] |
| 5501 |
import a |
| 5502 |
[file a.py] |
| 5503 |
from b import C |
| 5504 |
|
| 5505 |
def f(x: C) -> None: pass |
| 5506 |
f(C.X) |
| 5507 |
f(C.Y) |
| 5508 |
[file b.py] |
| 5509 |
from enum import Enum |
| 5510 |
|
| 5511 |
class C(Enum): |
| 5512 |
X = 0 |
| 5513 |
Y = 1 |
| 5514 |
[file b.py.2] |
| 5515 |
from enum import Enum |
| 5516 |
|
| 5517 |
class C(Enum): |
| 5518 |
X = 0 |
| 5519 |
[builtins fixtures/tuple.pyi] |
| 5520 |
[typing fixtures/typing-medium.pyi] |
| 5521 |
[out] |
| 5522 |
== |
| 5523 |
a.py:5: error: "type[C]" has no attribute "Y" |
| 5524 |
|
| 5525 |
[case testClassBasedEnumPropagation2] |
| 5526 |
import a |
| 5527 |
[file a.py] |
| 5528 |
from b import C |
| 5529 |
|
| 5530 |
def f(x: int) -> None: pass |
| 5531 |
f(C.X) |
| 5532 |
f(C.Y) |
| 5533 |
[file b.py] |
| 5534 |
class C: |
| 5535 |
X = 0 |
| 5536 |
Y = 1 |
| 5537 |
[file b.py.2] |
| 5538 |
from enum import Enum |
| 5539 |
class C(Enum): |
| 5540 |
X = 0 |
| 5541 |
Y = 1 |
| 5542 |
[builtins fixtures/enum.pyi] |
| 5543 |
[out] |
| 5544 |
== |
| 5545 |
a.py:4: error: Argument 1 to "f" has incompatible type "C"; expected "int" |
| 5546 |
a.py:5: error: Argument 1 to "f" has incompatible type "C"; expected "int" |
| 5547 |
|
| 5548 |
[case testRefreshFuncBasedEnum] |
| 5549 |
import aa |
| 5550 |
[file aa.py] |
| 5551 |
import a |
| 5552 |
[file a.py] |
| 5553 |
from enum import Enum |
| 5554 |
import b |
| 5555 |
b.x |
| 5556 |
C = Enum('C', [('X', 0)]) |
| 5557 |
[file b.py] |
| 5558 |
x = 0 |
| 5559 |
[file b.py.2] |
| 5560 |
x = '' |
| 5561 |
[file aa.py.3] |
| 5562 |
from a import C |
| 5563 |
c: C |
| 5564 |
c = C.X |
| 5565 |
if int(): |
| 5566 |
c = 1 |
| 5567 |
[builtins fixtures/tuple.pyi] |
| 5568 |
[out] |
| 5569 |
== |
| 5570 |
== |
| 5571 |
aa.py:5: error: Incompatible types in assignment (expression has type "int", variable has type "C") |
| 5572 |
|
| 5573 |
[case testRefreshFuncBasedIntEnum] |
| 5574 |
import aa |
| 5575 |
[file aa.py] |
| 5576 |
import a |
| 5577 |
[file a.py] |
| 5578 |
from enum import IntEnum |
| 5579 |
import b |
| 5580 |
b.x |
| 5581 |
C = IntEnum('C', 'X') |
| 5582 |
x: int |
| 5583 |
x = C.X |
| 5584 |
[file b.py] |
| 5585 |
x = 0 |
| 5586 |
[file b.py.2] |
| 5587 |
x = '' |
| 5588 |
[file aa.py.3] |
| 5589 |
from a import C |
| 5590 |
c: C |
| 5591 |
c = C.X |
| 5592 |
if int(): |
| 5593 |
c = 1 # Error |
| 5594 |
n: int |
| 5595 |
n = C.X |
| 5596 |
n = c |
| 5597 |
[builtins fixtures/enum.pyi] |
| 5598 |
[out] |
| 5599 |
== |
| 5600 |
== |
| 5601 |
aa.py:5: error: Incompatible types in assignment (expression has type "int", variable has type "C") |
| 5602 |
|
| 5603 |
[case testFuncBasedEnumPropagation1] |
| 5604 |
import a |
| 5605 |
[file a.py] |
| 5606 |
from b import C |
| 5607 |
|
| 5608 |
def f(x: C) -> None: pass |
| 5609 |
f(C.X) |
| 5610 |
f(C.Y) |
| 5611 |
[file b.py] |
| 5612 |
from enum import Enum |
| 5613 |
|
| 5614 |
C = Enum('C', 'X Y') |
| 5615 |
[file b.py.2] |
| 5616 |
from enum import Enum |
| 5617 |
|
| 5618 |
C = Enum('C', 'X') |
| 5619 |
[builtins fixtures/tuple.pyi] |
| 5620 |
[typing fixtures/typing-medium.pyi] |
| 5621 |
[out] |
| 5622 |
== |
| 5623 |
a.py:5: error: "type[C]" has no attribute "Y" |
| 5624 |
|
| 5625 |
[case testFuncBasedEnumPropagation2] |
| 5626 |
import a |
| 5627 |
[file a.py] |
| 5628 |
from b import C |
| 5629 |
|
| 5630 |
def f(x: int) -> None: pass |
| 5631 |
f(C.X) |
| 5632 |
f(C.Y) |
| 5633 |
[file b.py] |
| 5634 |
class C: |
| 5635 |
X = 0 |
| 5636 |
Y = 1 |
| 5637 |
[file b.py.2] |
| 5638 |
from enum import Enum |
| 5639 |
C = Enum('C', [('X', 0), ('Y', 1)]) |
| 5640 |
[builtins fixtures/tuple.pyi] |
| 5641 |
[out] |
| 5642 |
== |
| 5643 |
a.py:4: error: Argument 1 to "f" has incompatible type "C"; expected "int" |
| 5644 |
a.py:5: error: Argument 1 to "f" has incompatible type "C"; expected "int" |
| 5645 |
|
| 5646 |
[case testChangeTypeVarToFunction] |
| 5647 |
|
| 5648 |
import a |
| 5649 |
from typing import Generic |
| 5650 |
|
| 5651 |
class C(Generic[a.T]): |
| 5652 |
def meth(self, x: a.T) -> None: |
| 5653 |
pass |
| 5654 |
|
| 5655 |
Alias = C[C[a.T]] |
| 5656 |
|
| 5657 |
def outer() -> None: |
| 5658 |
def func(x: a.T) -> Alias[a.T]: |
| 5659 |
pass |
| 5660 |
[file a.py] |
| 5661 |
from typing import TypeVar |
| 5662 |
T = TypeVar('T') |
| 5663 |
[file a.py.2] |
| 5664 |
from typing import TypeVar |
| 5665 |
def T() -> None: |
| 5666 |
pass |
| 5667 |
[out] |
| 5668 |
== |
| 5669 |
main:5: error: Free type variable expected in Generic[...] |
| 5670 |
main:6: error: Function "a.T" is not valid as a type |
| 5671 |
main:6: note: Perhaps you need "Callable[...]" or a callback protocol? |
| 5672 |
main:9: error: "C" expects no type arguments, but 1 given |
| 5673 |
main:9: error: Function "a.T" is not valid as a type |
| 5674 |
main:9: note: Perhaps you need "Callable[...]" or a callback protocol? |
| 5675 |
main:12: error: Function "a.T" is not valid as a type |
| 5676 |
main:12: note: Perhaps you need "Callable[...]" or a callback protocol? |
| 5677 |
main:12: error: Bad number of arguments for type alias, expected 0, given 1 |
| 5678 |
|
| 5679 |
[case testChangeTypeVarToModule] |
| 5680 |
|
| 5681 |
import a |
| 5682 |
from typing import Generic |
| 5683 |
|
| 5684 |
class C(Generic[a.T]): |
| 5685 |
def meth(self, x: a.T) -> None: |
| 5686 |
pass |
| 5687 |
|
| 5688 |
Alias = C[C[a.T]] |
| 5689 |
|
| 5690 |
def outer() -> None: |
| 5691 |
def func(x: a.T) -> Alias[a.T]: |
| 5692 |
pass |
| 5693 |
[file a.py] |
| 5694 |
from typing import TypeVar |
| 5695 |
T = TypeVar('T') |
| 5696 |
[file T.py.2] |
| 5697 |
[file a.py.3] |
| 5698 |
from typing import TypeVar |
| 5699 |
import T |
| 5700 |
[out] |
| 5701 |
== |
| 5702 |
== |
| 5703 |
main:5: error: Free type variable expected in Generic[...] |
| 5704 |
main:6: error: Module "T" is not valid as a type |
| 5705 |
main:6: note: Perhaps you meant to use a protocol matching the module structure? |
| 5706 |
main:9: error: "C" expects no type arguments, but 1 given |
| 5707 |
main:9: error: Module "T" is not valid as a type |
| 5708 |
main:9: note: Perhaps you meant to use a protocol matching the module structure? |
| 5709 |
main:12: error: Module "T" is not valid as a type |
| 5710 |
main:12: note: Perhaps you meant to use a protocol matching the module structure? |
| 5711 |
main:12: error: Bad number of arguments for type alias, expected 0, given 1 |
| 5712 |
|
| 5713 |
[case testChangeClassToModule] |
| 5714 |
|
| 5715 |
import a |
| 5716 |
x: a.C |
| 5717 |
def f() -> None: |
| 5718 |
a.C() |
| 5719 |
class A: |
| 5720 |
def meth(self) -> None: |
| 5721 |
def inner() -> a.C: |
| 5722 |
pass |
| 5723 |
[file a.py] |
| 5724 |
class C: |
| 5725 |
pass |
| 5726 |
[file C.py.2] |
| 5727 |
[file a.py.3] |
| 5728 |
import C |
| 5729 |
[builtins fixtures/module.pyi] |
| 5730 |
[out] |
| 5731 |
== |
| 5732 |
== |
| 5733 |
main:3: error: Module "C" is not valid as a type |
| 5734 |
main:3: note: Perhaps you meant to use a protocol matching the module structure? |
| 5735 |
main:5: error: Module not callable |
| 5736 |
main:8: error: Module "C" is not valid as a type |
| 5737 |
main:8: note: Perhaps you meant to use a protocol matching the module structure? |
| 5738 |
|
| 5739 |
[case testChangeTypeVarToTypeAlias] |
| 5740 |
|
| 5741 |
import a |
| 5742 |
from typing import Generic |
| 5743 |
|
| 5744 |
class C(Generic[a.T]): |
| 5745 |
def meth(self, x: a.T) -> None: |
| 5746 |
pass |
| 5747 |
|
| 5748 |
Alias = C[C[a.T]] |
| 5749 |
|
| 5750 |
def outer() -> None: |
| 5751 |
def func(x: a.T) -> Alias[a.T]: |
| 5752 |
pass |
| 5753 |
[file a.py] |
| 5754 |
from typing import TypeVar |
| 5755 |
T = TypeVar('T') |
| 5756 |
[file a.py.2] |
| 5757 |
from typing import TypeVar |
| 5758 |
T = int |
| 5759 |
[out] |
| 5760 |
== |
| 5761 |
main:5: error: Free type variable expected in Generic[...] |
| 5762 |
main:9: error: "C" expects no type arguments, but 1 given |
| 5763 |
main:12: error: Bad number of arguments for type alias, expected 0, given 1 |
| 5764 |
|
| 5765 |
[case testChangeTypeAliasToModule] |
| 5766 |
|
| 5767 |
import a |
| 5768 |
x: a.C |
| 5769 |
def f() -> None: |
| 5770 |
a.C() |
| 5771 |
class A: |
| 5772 |
def meth(self) -> None: |
| 5773 |
def inner() -> a.C: |
| 5774 |
pass |
| 5775 |
[file a.py] |
| 5776 |
import b |
| 5777 |
C = b.D |
| 5778 |
[file b.py] |
| 5779 |
class D: |
| 5780 |
pass |
| 5781 |
[file D.py.2] |
| 5782 |
[file b.py.3] |
| 5783 |
import D |
| 5784 |
[builtins fixtures/module.pyi] |
| 5785 |
[out] |
| 5786 |
== |
| 5787 |
== |
| 5788 |
main:3: error: Module "D" is not valid as a type |
| 5789 |
main:3: note: Perhaps you meant to use a protocol matching the module structure? |
| 5790 |
main:5: error: Module not callable |
| 5791 |
main:8: error: Module "D" is not valid as a type |
| 5792 |
main:8: note: Perhaps you meant to use a protocol matching the module structure? |
| 5793 |
|
| 5794 |
[case testChangeTypeAliasToModuleUnqualified] |
| 5795 |
|
| 5796 |
from a import C |
| 5797 |
x: C |
| 5798 |
def f() -> None: |
| 5799 |
C() |
| 5800 |
class A: |
| 5801 |
def meth(self) -> None: |
| 5802 |
def inner() -> C: |
| 5803 |
pass |
| 5804 |
[file a.py] |
| 5805 |
from b import D |
| 5806 |
C = D |
| 5807 |
[file b.py] |
| 5808 |
class D: |
| 5809 |
pass |
| 5810 |
[file D.py.2] |
| 5811 |
[file b.py.3] |
| 5812 |
import D |
| 5813 |
[builtins fixtures/module.pyi] |
| 5814 |
[out] |
| 5815 |
== |
| 5816 |
== |
| 5817 |
main:3: error: Module "D" is not valid as a type |
| 5818 |
main:3: note: Perhaps you meant to use a protocol matching the module structure? |
| 5819 |
main:5: error: Module not callable |
| 5820 |
main:8: error: Module "D" is not valid as a type |
| 5821 |
main:8: note: Perhaps you meant to use a protocol matching the module structure? |
| 5822 |
|
| 5823 |
[case testChangeFunctionToVariableAndRefreshUsingStaleDependency] |
| 5824 |
import a |
| 5825 |
import c |
| 5826 |
[file a.py] |
| 5827 |
import c |
| 5828 |
def f() -> c.A: pass |
| 5829 |
[file a.py.2] |
| 5830 |
f = 1 |
| 5831 |
[file c.py] |
| 5832 |
class A: pass |
| 5833 |
[file c.py.3] |
| 5834 |
[out] |
| 5835 |
== |
| 5836 |
== |
| 5837 |
|
| 5838 |
[case testChangeFunctionToTypeVarAndRefreshUsingStaleDependency] |
| 5839 |
import a |
| 5840 |
import c |
| 5841 |
[file a.py] |
| 5842 |
import c |
| 5843 |
def f() -> c.A: pass |
| 5844 |
[file a.py.2] |
| 5845 |
from typing import TypeVar |
| 5846 |
f = TypeVar('f') |
| 5847 |
[file c.py] |
| 5848 |
class A: pass |
| 5849 |
[file c.py.3] |
| 5850 |
[out] |
| 5851 |
== |
| 5852 |
== |
| 5853 |
|
| 5854 |
[case testChangeFunctionToModuleAndRefreshUsingStaleDependency] |
| 5855 |
import a |
| 5856 |
import c |
| 5857 |
[file a.py] |
| 5858 |
import c |
| 5859 |
def f() -> c.A: pass |
| 5860 |
[file a.py.2] |
| 5861 |
import c as f |
| 5862 |
[file c.py] |
| 5863 |
class A: pass |
| 5864 |
[file c.py.3] |
| 5865 |
[out] |
| 5866 |
== |
| 5867 |
== |
| 5868 |
|
| 5869 |
[case testChangeFunctionToTypeAliasAndRefreshUsingStaleDependency1] |
| 5870 |
import a |
| 5871 |
import c |
| 5872 |
[file a.py] |
| 5873 |
import c |
| 5874 |
def f() -> c.A: pass |
| 5875 |
[file a.py.2] |
| 5876 |
f = int |
| 5877 |
[file c.py] |
| 5878 |
class A: pass |
| 5879 |
[file c.py.3] |
| 5880 |
[out] |
| 5881 |
== |
| 5882 |
== |
| 5883 |
|
| 5884 |
[case testChangeFunctionToTypeAliasAndRefreshUsingStaleDependency2] |
| 5885 |
import a |
| 5886 |
import c |
| 5887 |
[file a.py] |
| 5888 |
import c |
| 5889 |
def f() -> c.A: pass |
| 5890 |
[file a.py.2] |
| 5891 |
from typing import List |
| 5892 |
f = List[int] |
| 5893 |
[file c.py] |
| 5894 |
class A: pass |
| 5895 |
[file c.py.3] |
| 5896 |
[builtins fixtures/list.pyi] |
| 5897 |
[out] |
| 5898 |
== |
| 5899 |
== |
| 5900 |
|
| 5901 |
[case testChangeFunctionToClassAndRefreshUsingStaleDependency] |
| 5902 |
import a |
| 5903 |
import c |
| 5904 |
[file a.py] |
| 5905 |
import c |
| 5906 |
def f() -> c.A: pass |
| 5907 |
[file a.py.2] |
| 5908 |
class f: pass |
| 5909 |
[file c.py] |
| 5910 |
class A: pass |
| 5911 |
[file c.py.3] |
| 5912 |
[out] |
| 5913 |
== |
| 5914 |
== |
| 5915 |
|
| 5916 |
[case testClassToVariableAndRefreshUsingStaleDependency] |
| 5917 |
import a |
| 5918 |
import c |
| 5919 |
[file a.py] |
| 5920 |
import c |
| 5921 |
class A: |
| 5922 |
def f(self) -> c.A: pass |
| 5923 |
[file a.py.2] |
| 5924 |
A = 0 |
| 5925 |
[file c.py] |
| 5926 |
class A: pass |
| 5927 |
[file c.py.3] |
| 5928 |
[out] |
| 5929 |
== |
| 5930 |
== |
| 5931 |
|
| 5932 |
[case testFunctionToImportedFunctionAndRefreshUsingStaleDependency] |
| 5933 |
import a |
| 5934 |
import c |
| 5935 |
[file a.py] |
| 5936 |
import c |
| 5937 |
def f() -> c.A: pass |
| 5938 |
[file a.py.2] |
| 5939 |
from d import f |
| 5940 |
[file c.py] |
| 5941 |
class A: pass |
| 5942 |
[file c.py.3] |
| 5943 |
[file d.py] |
| 5944 |
def g() -> None: pass |
| 5945 |
def f() -> None: |
| 5946 |
g() |
| 5947 |
[out] |
| 5948 |
== |
| 5949 |
== |
| 5950 |
|
| 5951 |
[case testMethodToVariableAndRefreshUsingStaleDependency] |
| 5952 |
import a |
| 5953 |
import c |
| 5954 |
[file a.py] |
| 5955 |
import c |
| 5956 |
class B: |
| 5957 |
def f(self) -> c.A: pass |
| 5958 |
[file a.py.2] |
| 5959 |
class B: |
| 5960 |
f = 0 |
| 5961 |
[file c.py] |
| 5962 |
class A: pass |
| 5963 |
[file c.py.3] |
| 5964 |
[out] |
| 5965 |
== |
| 5966 |
== |
| 5967 |
|
| 5968 |
[case testChangeGenericFunctionToVariable] |
| 5969 |
import a |
| 5970 |
x: int |
| 5971 |
y: int = a.f(x) |
| 5972 |
class Dummy: |
| 5973 |
def g(self) -> None: |
| 5974 |
a.f(x) |
| 5975 |
[file a.py] |
| 5976 |
from typing import TypeVar |
| 5977 |
T = TypeVar('T') |
| 5978 |
def f(x: T) -> T: |
| 5979 |
pass |
| 5980 |
[file a.py.2] |
| 5981 |
from typing import TypeVar |
| 5982 |
T = TypeVar('T') |
| 5983 |
f = 42 |
| 5984 |
[out] |
| 5985 |
== |
| 5986 |
main:3: error: "int" not callable |
| 5987 |
main:6: error: "int" not callable |
| 5988 |
|
| 5989 |
[case testChangeGenericClassToVariable] |
| 5990 |
import a |
| 5991 |
x: int |
| 5992 |
a.A(x) |
| 5993 |
class Dummy: |
| 5994 |
def g(self) -> None: |
| 5995 |
a.A(x) |
| 5996 |
[file a.py] |
| 5997 |
from typing import TypeVar, Generic |
| 5998 |
T = TypeVar('T') |
| 5999 |
class A(Generic[T]): |
| 6000 |
def __init__(self, x: T) -> None: |
| 6001 |
pass |
| 6002 |
[file a.py.2] |
| 6003 |
from typing import TypeVar, Generic |
| 6004 |
T = TypeVar('T') |
| 6005 |
A = 'no way' |
| 6006 |
[out] |
| 6007 |
== |
| 6008 |
main:3: error: "str" not callable |
| 6009 |
main:6: error: "str" not callable |
| 6010 |
|
| 6011 |
[case testChangeGenericMethodToVariable] |
| 6012 |
import a |
| 6013 |
x: int |
| 6014 |
y: int = a.A(x).f() |
| 6015 |
class Dummy: |
| 6016 |
def g(self) -> None: |
| 6017 |
a.A(x).f() |
| 6018 |
[file a.py] |
| 6019 |
from typing import TypeVar, Generic |
| 6020 |
T = TypeVar('T') |
| 6021 |
class A(Generic[T]): |
| 6022 |
def __init__(self, x: T) -> None: |
| 6023 |
pass |
| 6024 |
def f(self) -> T: |
| 6025 |
pass |
| 6026 |
[file a.py.2] |
| 6027 |
from typing import TypeVar, Generic |
| 6028 |
T = TypeVar('T') |
| 6029 |
class A(Generic[T]): |
| 6030 |
f: T |
| 6031 |
def __init__(self, x: T) -> None: |
| 6032 |
pass |
| 6033 |
[out] |
| 6034 |
== |
| 6035 |
main:3: error: "int" not callable |
| 6036 |
main:6: error: "int" not callable |
| 6037 |
|
| 6038 |
[case testRefreshNestedClassWithSelfReference] |
| 6039 |
import a |
| 6040 |
[file a.py] |
| 6041 |
import b |
| 6042 |
|
| 6043 |
def f(self) -> None: |
| 6044 |
b.y |
| 6045 |
class C: |
| 6046 |
z: C |
| 6047 |
[file b.py] |
| 6048 |
y = 0 |
| 6049 |
[file b.py.2] |
| 6050 |
y = '' |
| 6051 |
[file b.py.3] |
| 6052 |
y = 0 |
| 6053 |
[out] |
| 6054 |
== |
| 6055 |
== |
| 6056 |
|
| 6057 |
[case testMultipleAssignment] |
| 6058 |
import a |
| 6059 |
[file a.py] |
| 6060 |
from b import f |
| 6061 |
|
| 6062 |
def h(x: str) -> None: pass |
| 6063 |
|
| 6064 |
class C: |
| 6065 |
def __init__(self) -> None: |
| 6066 |
self.a, self.b = f() |
| 6067 |
|
| 6068 |
def g(self) -> None: |
| 6069 |
h(self.a) |
| 6070 |
[file b.py] |
| 6071 |
from typing import Tuple |
| 6072 |
def f() -> Tuple[str, int]: pass |
| 6073 |
[file b.py.2] |
| 6074 |
from typing import Tuple |
| 6075 |
def f() -> Tuple[int, object]: pass |
| 6076 |
[file b.py.3] |
| 6077 |
from typing import Tuple |
| 6078 |
def f() -> Tuple[str, int]: pass |
| 6079 |
[builtins fixtures/tuple.pyi] |
| 6080 |
[out] |
| 6081 |
== |
| 6082 |
a.py:10: error: Argument 1 to "h" has incompatible type "int"; expected "str" |
| 6083 |
== |
| 6084 |
|
| 6085 |
[case testMultipleLvalues] |
| 6086 |
import a |
| 6087 |
[file a.py] |
| 6088 |
from b import f |
| 6089 |
|
| 6090 |
def h(x: str) -> None: pass |
| 6091 |
|
| 6092 |
class C: |
| 6093 |
def __init__(self) -> None: |
| 6094 |
self.a = self.b = f() |
| 6095 |
|
| 6096 |
def g(self) -> None: |
| 6097 |
h(self.a) |
| 6098 |
h(self.b) |
| 6099 |
[file b.py] |
| 6100 |
def f() -> str: pass |
| 6101 |
[file b.py.2] |
| 6102 |
def f() -> int: pass |
| 6103 |
[file b.py.3] |
| 6104 |
def f() -> str: pass |
| 6105 |
[out] |
| 6106 |
== |
| 6107 |
a.py:10: error: Argument 1 to "h" has incompatible type "int"; expected "str" |
| 6108 |
a.py:11: error: Argument 1 to "h" has incompatible type "int"; expected "str" |
| 6109 |
== |
| 6110 |
|
| 6111 |
[case testNoOpUpdateFineGrainedIncremental1] |
| 6112 |
# cmd: mypy a.py |
| 6113 |
[file a.py] |
| 6114 |
1() |
| 6115 |
[file b.py.2] |
| 6116 |
# Note: this file is not part of the build |
| 6117 |
[file a.py.3] |
| 6118 |
x = 1 |
| 6119 |
[out] |
| 6120 |
a.py:1: error: "int" not callable |
| 6121 |
== |
| 6122 |
a.py:1: error: "int" not callable |
| 6123 |
== |
| 6124 |
|
| 6125 |
[case testNoOpUpdateFineGrainedIncremental2] |
| 6126 |
# cmd: mypy a.py |
| 6127 |
[file a.py] |
| 6128 |
1() |
| 6129 |
[file a.py.2] |
| 6130 |
1() |
| 6131 |
[file a.py.3] |
| 6132 |
x = 1 |
| 6133 |
[file a.py.4] |
| 6134 |
x = 1 |
| 6135 |
[out] |
| 6136 |
a.py:1: error: "int" not callable |
| 6137 |
== |
| 6138 |
a.py:1: error: "int" not callable |
| 6139 |
== |
| 6140 |
== |
| 6141 |
|
| 6142 |
[case testNonExistentFileOnCommandLine1] |
| 6143 |
# cmd: mypy a.py nonexistent.py |
| 6144 |
[file a.py] |
| 6145 |
[file a.py.2] |
| 6146 |
1() |
| 6147 |
[out] |
| 6148 |
mypy: error: Cannot read file 'tmp/nonexistent.py': No such file or directory |
| 6149 |
== |
| 6150 |
mypy: error: Cannot read file 'tmp/nonexistent.py': No such file or directory |
| 6151 |
|
| 6152 |
[case testNonExistentFileOnCommandLine2] |
| 6153 |
# cmd: mypy a.py |
| 6154 |
# cmd2: mypy a.py nonexistent.py |
| 6155 |
[file a.py] |
| 6156 |
[file a.py.2] |
| 6157 |
1() |
| 6158 |
[out] |
| 6159 |
== |
| 6160 |
a.py:1: error: "int" not callable |
| 6161 |
|
| 6162 |
[case testNonExistentFileOnCommandLine3] |
| 6163 |
# cmd: mypy a.py |
| 6164 |
# cmd2: mypy a.py nonexistent.py |
| 6165 |
[file a.py] |
| 6166 |
[file nonexistent.py] |
| 6167 |
[delete nonexistent.py.2] |
| 6168 |
[out] |
| 6169 |
== |
| 6170 |
|
| 6171 |
[case testNonExistentFileOnCommandLine4] |
| 6172 |
# cmd: mypy a.py nonexistent.py |
| 6173 |
[file a.py] |
| 6174 |
[file nonexistent.py] |
| 6175 |
[delete nonexistent.py.2] |
| 6176 |
[out] |
| 6177 |
== |
| 6178 |
|
| 6179 |
[case testNonExistentFileOnCommandLine5] |
| 6180 |
# cmd: mypy a.py nonexistent_stub.pyi |
| 6181 |
# TODO: Should generate an error for missing file |
| 6182 |
[file a.py] |
| 6183 |
[file nonexistent_stub.pyi] |
| 6184 |
[delete nonexistent_stub.pyi.2] |
| 6185 |
[out] |
| 6186 |
== |
| 6187 |
|
| 6188 |
[case testDunderNewUpdatedMethod] |
| 6189 |
import a |
| 6190 |
[file a.py] |
| 6191 |
import b |
| 6192 |
class A: |
| 6193 |
def func(self) -> None: |
| 6194 |
b.C(int()) |
| 6195 |
[file b.py] |
| 6196 |
class C: |
| 6197 |
def __new__(cls, x: str) -> C: |
| 6198 |
pass |
| 6199 |
[file b.py.2] |
| 6200 |
class C: |
| 6201 |
def __new__(cls, x: int) -> C: |
| 6202 |
pass |
| 6203 |
[out] |
| 6204 |
a.py:4: error: Argument 1 to "C" has incompatible type "int"; expected "str" |
| 6205 |
== |
| 6206 |
|
| 6207 |
[case testDunderNewUpdatedSubclass] |
| 6208 |
import a |
| 6209 |
[file a.py] |
| 6210 |
import b |
| 6211 |
|
| 6212 |
b.D(int()) |
| 6213 |
[file b.py] |
| 6214 |
from c import C |
| 6215 |
class D(C): pass |
| 6216 |
[file c.py] |
| 6217 |
class C: |
| 6218 |
def __new__(cls, x: str) -> C: |
| 6219 |
pass |
| 6220 |
[file c.py.2] |
| 6221 |
class C: |
| 6222 |
def __new__(cls, x: int) -> C: |
| 6223 |
pass |
| 6224 |
[out] |
| 6225 |
a.py:3: error: Argument 1 to "D" has incompatible type "int"; expected "str" |
| 6226 |
== |
| 6227 |
|
| 6228 |
[case testDunderNewUpdatedAlias] |
| 6229 |
import a |
| 6230 |
[file a.py] |
| 6231 |
import b |
| 6232 |
|
| 6233 |
b.D(int()) |
| 6234 |
[file b.py] |
| 6235 |
from c import C |
| 6236 |
D = C |
| 6237 |
[file c.py] |
| 6238 |
class C: |
| 6239 |
def __new__(cls, x: int) -> C: |
| 6240 |
pass |
| 6241 |
[file c.py.2] |
| 6242 |
class C: |
| 6243 |
def __new__(cls, x: str) -> C: |
| 6244 |
pass |
| 6245 |
[out] |
| 6246 |
== |
| 6247 |
a.py:3: error: Argument 1 to "C" has incompatible type "int"; expected "str" |
| 6248 |
|
| 6249 |
[case testDunderNewUpdatedCallable] |
| 6250 |
import a |
| 6251 |
[file a.py] |
| 6252 |
from typing import Callable, Any |
| 6253 |
import b |
| 6254 |
|
| 6255 |
def func(arg: Callable[[int], Any]) -> None: |
| 6256 |
pass |
| 6257 |
func(b.C) |
| 6258 |
[file b.py] |
| 6259 |
class C: |
| 6260 |
def __new__(cls, x: int) -> C: |
| 6261 |
pass |
| 6262 |
[file b.py.2] |
| 6263 |
class C: |
| 6264 |
def __new__(cls, x: str) -> C: |
| 6265 |
pass |
| 6266 |
[out] |
| 6267 |
== |
| 6268 |
a.py:6: error: Argument 1 to "func" has incompatible type "type[C]"; expected "Callable[[int], Any]" |
| 6269 |
|
| 6270 |
[case testDunderNewDefine] |
| 6271 |
import a |
| 6272 |
[file a.py] |
| 6273 |
import b |
| 6274 |
class A: |
| 6275 |
def func(self) -> None: |
| 6276 |
b.C() |
| 6277 |
[file b.py] |
| 6278 |
class C: |
| 6279 |
pass |
| 6280 |
[file b.py.2] |
| 6281 |
class C: |
| 6282 |
def __new__(cls, x: int) -> C: |
| 6283 |
pass |
| 6284 |
[out] |
| 6285 |
== |
| 6286 |
a.py:4: error: Missing positional argument "x" in call to "C" |
| 6287 |
|
| 6288 |
[case testDunderNewInsteadOfInit] |
| 6289 |
import a |
| 6290 |
[file a.py] |
| 6291 |
import b |
| 6292 |
class A: |
| 6293 |
def func(self) -> None: |
| 6294 |
b.C(int()) |
| 6295 |
[file b.py] |
| 6296 |
class C: |
| 6297 |
def __init__(cls, x: int) -> None: |
| 6298 |
pass |
| 6299 |
[file b.py.2] |
| 6300 |
class C: |
| 6301 |
def __new__(cls, x: int) -> C: |
| 6302 |
pass |
| 6303 |
[file b.py.3] |
| 6304 |
class C: |
| 6305 |
pass |
| 6306 |
[out] |
| 6307 |
== |
| 6308 |
== |
| 6309 |
a.py:4: error: Too many arguments for "C" |
| 6310 |
|
| 6311 |
-- Protocol tests |
| 6312 |
|
| 6313 |
[case testProtocolUpdateTypeInVariable] |
| 6314 |
import a |
| 6315 |
[file a.py] |
| 6316 |
import b |
| 6317 |
class C: |
| 6318 |
x: int |
| 6319 |
x: b.P = C() |
| 6320 |
[file b.py] |
| 6321 |
from typing import Protocol |
| 6322 |
class P(Protocol): |
| 6323 |
x: int |
| 6324 |
[file b.py.2] |
| 6325 |
from typing import Protocol |
| 6326 |
class P(Protocol): |
| 6327 |
x: str |
| 6328 |
[out] |
| 6329 |
== |
| 6330 |
a.py:4: error: Incompatible types in assignment (expression has type "C", variable has type "P") |
| 6331 |
a.py:4: note: Following member(s) of "C" have conflicts: |
| 6332 |
a.py:4: note: x: expected "str", got "int" |
| 6333 |
|
| 6334 |
[case testProtocolUpdateTypeInFunction] |
| 6335 |
import a |
| 6336 |
[file a.py] |
| 6337 |
import b |
| 6338 |
class C: |
| 6339 |
x: int |
| 6340 |
c: C |
| 6341 |
def f() -> None: |
| 6342 |
def g(x: b.P) -> None: |
| 6343 |
pass |
| 6344 |
g(c) |
| 6345 |
[file b.py] |
| 6346 |
from typing import Protocol |
| 6347 |
class P(Protocol): |
| 6348 |
x: int |
| 6349 |
[file b.py.2] |
| 6350 |
from typing import Protocol |
| 6351 |
class P(Protocol): |
| 6352 |
x: str |
| 6353 |
[out] |
| 6354 |
== |
| 6355 |
a.py:8: error: Argument 1 to "g" has incompatible type "C"; expected "P" |
| 6356 |
a.py:8: note: Following member(s) of "C" have conflicts: |
| 6357 |
a.py:8: note: x: expected "str", got "int" |
| 6358 |
|
| 6359 |
[case testProtocolUpdateTypeInClass] |
| 6360 |
import a |
| 6361 |
[file a.py] |
| 6362 |
import b |
| 6363 |
class C: |
| 6364 |
x: int |
| 6365 |
class A: |
| 6366 |
class B: |
| 6367 |
x: b.P |
| 6368 |
y: B |
| 6369 |
A().y.x = C() |
| 6370 |
[file b.py] |
| 6371 |
from typing import Protocol |
| 6372 |
class P(Protocol): |
| 6373 |
x: int |
| 6374 |
[file b.py.2] |
| 6375 |
from typing import Protocol |
| 6376 |
class P(Protocol): |
| 6377 |
x: str |
| 6378 |
[out] |
| 6379 |
== |
| 6380 |
a.py:8: error: Incompatible types in assignment (expression has type "C", variable has type "P") |
| 6381 |
a.py:8: note: Following member(s) of "C" have conflicts: |
| 6382 |
a.py:8: note: x: expected "str", got "int" |
| 6383 |
|
| 6384 |
[case testProtocolAddAttrInFunction] |
| 6385 |
import a |
| 6386 |
[file a.py] |
| 6387 |
import b |
| 6388 |
class C: |
| 6389 |
x: int |
| 6390 |
def f() -> None: |
| 6391 |
c: C |
| 6392 |
def g(x: b.P) -> None: |
| 6393 |
pass |
| 6394 |
g(c) |
| 6395 |
[file b.py] |
| 6396 |
from typing import Protocol |
| 6397 |
class P(Protocol): |
| 6398 |
x: int |
| 6399 |
[file b.py.2] |
| 6400 |
from typing import Protocol |
| 6401 |
class P(Protocol): |
| 6402 |
x: int |
| 6403 |
y: str |
| 6404 |
[out] |
| 6405 |
== |
| 6406 |
a.py:8: error: Argument 1 to "g" has incompatible type "C"; expected "P" |
| 6407 |
a.py:8: note: "C" is missing following "P" protocol member: |
| 6408 |
a.py:8: note: y |
| 6409 |
|
| 6410 |
[case testProtocolRemoveAttrInClass] |
| 6411 |
import a |
| 6412 |
[file a.py] |
| 6413 |
import b |
| 6414 |
class C: |
| 6415 |
x: int |
| 6416 |
class A: |
| 6417 |
class B: |
| 6418 |
x: b.P |
| 6419 |
y: B |
| 6420 |
A().y.x = C() |
| 6421 |
[file b.py] |
| 6422 |
from typing import Protocol |
| 6423 |
class P(Protocol): |
| 6424 |
x: int |
| 6425 |
y: str |
| 6426 |
[file b.py.2] |
| 6427 |
from typing import Protocol |
| 6428 |
class P(Protocol): |
| 6429 |
x: int |
| 6430 |
[out] |
| 6431 |
a.py:8: error: Incompatible types in assignment (expression has type "C", variable has type "P") |
| 6432 |
a.py:8: note: "C" is missing following "P" protocol member: |
| 6433 |
a.py:8: note: y |
| 6434 |
== |
| 6435 |
|
| 6436 |
[case testProtocolConcreteUpdateTypeFunction] |
| 6437 |
import a |
| 6438 |
[file a.py] |
| 6439 |
import b |
| 6440 |
from typing import Protocol |
| 6441 |
class P(Protocol): |
| 6442 |
x: int |
| 6443 |
def f() -> None: |
| 6444 |
def g(x: P) -> None: |
| 6445 |
pass |
| 6446 |
g(b.C()) |
| 6447 |
[file b.py] |
| 6448 |
class C: |
| 6449 |
x: int |
| 6450 |
[file b.py.2] |
| 6451 |
class C: |
| 6452 |
x: str |
| 6453 |
[out] |
| 6454 |
== |
| 6455 |
a.py:8: error: Argument 1 to "g" has incompatible type "C"; expected "P" |
| 6456 |
a.py:8: note: Following member(s) of "C" have conflicts: |
| 6457 |
a.py:8: note: x: expected "int", got "str" |
| 6458 |
|
| 6459 |
[case testProtocolConcreteUpdateTypeMethodGeneric] |
| 6460 |
import a |
| 6461 |
[file a.py] |
| 6462 |
import b |
| 6463 |
from typing import Protocol, TypeVar |
| 6464 |
T = TypeVar('T') |
| 6465 |
class P(Protocol[T]): |
| 6466 |
x: T |
| 6467 |
class C: |
| 6468 |
def g(self, x: P[int]) -> None: |
| 6469 |
pass |
| 6470 |
def do(self) -> None: |
| 6471 |
self.g(b.C()) |
| 6472 |
[file b.py] |
| 6473 |
class C: |
| 6474 |
x: int |
| 6475 |
[file b.py.2] |
| 6476 |
class C: |
| 6477 |
x: str |
| 6478 |
[out] |
| 6479 |
== |
| 6480 |
a.py:10: error: Argument 1 to "g" of "C" has incompatible type "C"; expected "P[int]" |
| 6481 |
a.py:10: note: Following member(s) of "C" have conflicts: |
| 6482 |
a.py:10: note: x: expected "int", got "str" |
| 6483 |
|
| 6484 |
[case testProtocolConcreteRemoveAttrVariable] |
| 6485 |
import a |
| 6486 |
[file a.py] |
| 6487 |
import b, c |
| 6488 |
cc: c.C |
| 6489 |
x: b.P = cc |
| 6490 |
[file b.py] |
| 6491 |
from typing import Protocol |
| 6492 |
class P(Protocol): |
| 6493 |
x: int |
| 6494 |
[file c.py] |
| 6495 |
class C: |
| 6496 |
x: int |
| 6497 |
[file c.py.2] |
| 6498 |
class C: |
| 6499 |
pass |
| 6500 |
[out] |
| 6501 |
== |
| 6502 |
a.py:3: error: Incompatible types in assignment (expression has type "C", variable has type "P") |
| 6503 |
|
| 6504 |
[case testProtocolUpdateBaseGeneric] |
| 6505 |
import a |
| 6506 |
[file a.py] |
| 6507 |
import b, c |
| 6508 |
def g(x: c.P) -> None: |
| 6509 |
pass |
| 6510 |
g(b.C()) |
| 6511 |
[file b.py] |
| 6512 |
class C: |
| 6513 |
x: int |
| 6514 |
[file c.py] |
| 6515 |
from typing import Protocol |
| 6516 |
import d |
| 6517 |
class P(d.PBase[int], Protocol): |
| 6518 |
pass |
| 6519 |
[file c.py.2] |
| 6520 |
from typing import Protocol |
| 6521 |
import d |
| 6522 |
class P(d.PBase[str], Protocol): |
| 6523 |
pass |
| 6524 |
[file d.py] |
| 6525 |
from typing import Protocol, TypeVar |
| 6526 |
T = TypeVar('T') |
| 6527 |
class PBase(Protocol[T]): |
| 6528 |
x: T |
| 6529 |
[out] |
| 6530 |
== |
| 6531 |
a.py:4: error: Argument 1 to "g" has incompatible type "C"; expected "P" |
| 6532 |
a.py:4: note: Following member(s) of "C" have conflicts: |
| 6533 |
a.py:4: note: x: expected "str", got "int" |
| 6534 |
|
| 6535 |
[case testProtocolConcreteUpdateBaseGeneric] |
| 6536 |
import a |
| 6537 |
[file a.py] |
| 6538 |
import b |
| 6539 |
from typing import Protocol |
| 6540 |
class P(Protocol): |
| 6541 |
x: int |
| 6542 |
def f(x: P) -> None: |
| 6543 |
pass |
| 6544 |
f(b.B()) |
| 6545 |
[file b.py] |
| 6546 |
import c |
| 6547 |
class B(c.C[int]): |
| 6548 |
pass |
| 6549 |
[file b.py.2] |
| 6550 |
import c |
| 6551 |
class B(c.C[str]): |
| 6552 |
pass |
| 6553 |
[file c.py] |
| 6554 |
from typing import TypeVar, Generic |
| 6555 |
T = TypeVar('T') |
| 6556 |
class C(Generic[T]): |
| 6557 |
x: T |
| 6558 |
[out] |
| 6559 |
== |
| 6560 |
a.py:7: error: Argument 1 to "f" has incompatible type "B"; expected "P" |
| 6561 |
a.py:7: note: Following member(s) of "B" have conflicts: |
| 6562 |
a.py:7: note: x: expected "int", got "str" |
| 6563 |
|
| 6564 |
[case testProtocolChangeGeneric] |
| 6565 |
import a |
| 6566 |
[file a.py] |
| 6567 |
import b, c |
| 6568 |
x: b.P = c.C() |
| 6569 |
[file b.py] |
| 6570 |
import b2 |
| 6571 |
from typing import Protocol |
| 6572 |
class P(b2.P2[str], Protocol): |
| 6573 |
pass |
| 6574 |
[file b2.py] |
| 6575 |
from typing import Protocol, TypeVar |
| 6576 |
T = TypeVar('T') |
| 6577 |
class P2(Protocol[T]): |
| 6578 |
x: T |
| 6579 |
[file b2.py.2] |
| 6580 |
from typing import Protocol, TypeVar |
| 6581 |
T = TypeVar('T') |
| 6582 |
class P2(Protocol): |
| 6583 |
x: int |
| 6584 |
[file c.py] |
| 6585 |
class C: |
| 6586 |
x: int |
| 6587 |
[out] |
| 6588 |
a.py:2: error: Incompatible types in assignment (expression has type "C", variable has type "P") |
| 6589 |
a.py:2: note: Following member(s) of "C" have conflicts: |
| 6590 |
a.py:2: note: x: expected "str", got "int" |
| 6591 |
== |
| 6592 |
b.py:3: error: "P2" expects no type arguments, but 1 given |
| 6593 |
|
| 6594 |
[case testProtocolToNonProtocol] |
| 6595 |
import a |
| 6596 |
[file a.py] |
| 6597 |
import b, c |
| 6598 |
b.f(c.C()) |
| 6599 |
[file b.py] |
| 6600 |
import d |
| 6601 |
def f(x: d.D) -> None: |
| 6602 |
pass |
| 6603 |
[file c.py] |
| 6604 |
import d |
| 6605 |
class C: |
| 6606 |
x: int |
| 6607 |
[file d.py] |
| 6608 |
from typing import Protocol |
| 6609 |
class D(Protocol): |
| 6610 |
x: int |
| 6611 |
[file d.py.2] |
| 6612 |
class D: |
| 6613 |
x: int |
| 6614 |
[file c.py.3] |
| 6615 |
import d |
| 6616 |
class C(d.D): |
| 6617 |
pass |
| 6618 |
[out] |
| 6619 |
== |
| 6620 |
a.py:2: error: Argument 1 to "f" has incompatible type "C"; expected "D" |
| 6621 |
== |
| 6622 |
|
| 6623 |
[case testNonProtocolToProtocol] |
| 6624 |
import a |
| 6625 |
[file a.py] |
| 6626 |
import b, c |
| 6627 |
b.f(c.C()) |
| 6628 |
[file b.py] |
| 6629 |
import d |
| 6630 |
def f(x: d.D) -> None: |
| 6631 |
pass |
| 6632 |
[file c.py] |
| 6633 |
import d |
| 6634 |
class C(d.D): |
| 6635 |
pass |
| 6636 |
[file d.py] |
| 6637 |
class D: |
| 6638 |
x: int |
| 6639 |
[file d.py.2] |
| 6640 |
from typing import Protocol |
| 6641 |
class D(Protocol): |
| 6642 |
x: int |
| 6643 |
[file c.py.3] |
| 6644 |
import d |
| 6645 |
class C: |
| 6646 |
x: int |
| 6647 |
[out] |
| 6648 |
== |
| 6649 |
a.py:2: error: Cannot instantiate abstract class "C" with abstract attribute "x" |
| 6650 |
== |
| 6651 |
|
| 6652 |
[case testInvalidateProtocolViaSuperClass] |
| 6653 |
import a |
| 6654 |
[file a.py] |
| 6655 |
import b, c |
| 6656 |
def func(x: c.P) -> None: |
| 6657 |
pass |
| 6658 |
func(b.B()) |
| 6659 |
[file b.py] |
| 6660 |
class B: |
| 6661 |
x: int |
| 6662 |
y: str |
| 6663 |
[file c.py] |
| 6664 |
from typing import Protocol |
| 6665 |
import d |
| 6666 |
class P(d.PBase, Protocol): |
| 6667 |
x: int |
| 6668 |
[file d.py] |
| 6669 |
from typing import Protocol |
| 6670 |
class PBase(Protocol): |
| 6671 |
y: str |
| 6672 |
[file d.py.2] |
| 6673 |
from typing import Protocol |
| 6674 |
class PBase(Protocol): |
| 6675 |
y: int |
| 6676 |
[out] |
| 6677 |
== |
| 6678 |
a.py:4: error: Argument 1 to "func" has incompatible type "B"; expected "P" |
| 6679 |
a.py:4: note: Following member(s) of "B" have conflicts: |
| 6680 |
a.py:4: note: y: expected "int", got "str" |
| 6681 |
|
| 6682 |
[case testProtocolInvalidateConcreteViaSuperClassUpdateType] |
| 6683 |
import a |
| 6684 |
[file a.py] |
| 6685 |
import b |
| 6686 |
def func(x: b.P) -> None: |
| 6687 |
pass |
| 6688 |
func(b.B()) |
| 6689 |
[file b.py] |
| 6690 |
from typing import Protocol |
| 6691 |
import c |
| 6692 |
class P(Protocol): |
| 6693 |
x: int |
| 6694 |
class B(c.C): |
| 6695 |
pass |
| 6696 |
[file c.py] |
| 6697 |
class C: |
| 6698 |
x: int |
| 6699 |
[file c.py.2] |
| 6700 |
class C: |
| 6701 |
x: str |
| 6702 |
[out] |
| 6703 |
== |
| 6704 |
a.py:4: error: Argument 1 to "func" has incompatible type "B"; expected "P" |
| 6705 |
a.py:4: note: Following member(s) of "B" have conflicts: |
| 6706 |
a.py:4: note: x: expected "int", got "str" |
| 6707 |
|
| 6708 |
[case testProtocolInvalidateConcreteViaSuperClassAddAttr] |
| 6709 |
import a |
| 6710 |
[file a.py] |
| 6711 |
import b |
| 6712 |
def func(x: b.P) -> None: |
| 6713 |
pass |
| 6714 |
bb: b.B |
| 6715 |
func(bb) |
| 6716 |
[file b.py] |
| 6717 |
from typing import Protocol |
| 6718 |
import c |
| 6719 |
class P(Protocol): |
| 6720 |
x: int |
| 6721 |
class B(c.C): |
| 6722 |
pass |
| 6723 |
[file c.py] |
| 6724 |
class C: |
| 6725 |
pass |
| 6726 |
[file c.py.2] |
| 6727 |
class C: |
| 6728 |
x: int |
| 6729 |
[out] |
| 6730 |
a.py:5: error: Argument 1 to "func" has incompatible type "B"; expected "P" |
| 6731 |
== |
| 6732 |
|
| 6733 |
[case testProtocolInvalidateConcreteViaSuperClassRemoveAttr] |
| 6734 |
import a |
| 6735 |
[file a.py] |
| 6736 |
import b |
| 6737 |
def func(x: b.P) -> None: |
| 6738 |
pass |
| 6739 |
func(b.B()) |
| 6740 |
[file b.py] |
| 6741 |
from typing import Protocol |
| 6742 |
import c |
| 6743 |
class P(Protocol): |
| 6744 |
x: int |
| 6745 |
class B(c.C): |
| 6746 |
pass |
| 6747 |
[file c.py] |
| 6748 |
class C: |
| 6749 |
x: int |
| 6750 |
[file c.py.2] |
| 6751 |
class C: |
| 6752 |
pass |
| 6753 |
[out] |
| 6754 |
== |
| 6755 |
a.py:4: error: Argument 1 to "func" has incompatible type "B"; expected "P" |
| 6756 |
|
| 6757 |
[case testTwoProtocolsTwoFilesCrossedUpdateType-only_when_nocache] |
| 6758 |
# this test and the next one (TwoProtocolsTwoFilesCrossedDeleteAttr) has errors ordered |
| 6759 |
# opposite way with and without cache, therefore skip one of each. |
| 6760 |
import a |
| 6761 |
[file a.py] |
| 6762 |
import b1 |
| 6763 |
import b2 |
| 6764 |
[file b1.py] |
| 6765 |
import b2, d |
| 6766 |
from typing import Protocol |
| 6767 |
class P1(Protocol): |
| 6768 |
x: int |
| 6769 |
def f(x: b2.P2) -> None: |
| 6770 |
pass |
| 6771 |
f(d.D()) |
| 6772 |
[file b2.py] |
| 6773 |
import b1, d |
| 6774 |
from typing import Protocol |
| 6775 |
class P2(Protocol): |
| 6776 |
x: int |
| 6777 |
def f(x: b1.P1) -> None: |
| 6778 |
pass |
| 6779 |
f(d.D()) |
| 6780 |
[file d.py] |
| 6781 |
class D: |
| 6782 |
x: int |
| 6783 |
[file d.py.2] |
| 6784 |
class D: |
| 6785 |
x: str |
| 6786 |
[out] |
| 6787 |
== |
| 6788 |
b1.py:7: error: Argument 1 to "f" has incompatible type "D"; expected "P2" |
| 6789 |
b1.py:7: note: Following member(s) of "D" have conflicts: |
| 6790 |
b1.py:7: note: x: expected "int", got "str" |
| 6791 |
b2.py:7: error: Argument 1 to "f" has incompatible type "D"; expected "P1" |
| 6792 |
b2.py:7: note: Following member(s) of "D" have conflicts: |
| 6793 |
b2.py:7: note: x: expected "int", got "str" |
| 6794 |
|
| 6795 |
[case testTwoProtocolsTwoFilesCrossedDeleteAttr-only_when_cache] |
| 6796 |
import a |
| 6797 |
[file a.py] |
| 6798 |
import b1 |
| 6799 |
import b2 |
| 6800 |
[file b1.py] |
| 6801 |
import b2, d |
| 6802 |
from typing import Protocol |
| 6803 |
class P1(Protocol): |
| 6804 |
x: int |
| 6805 |
def f(x: b2.P2) -> None: |
| 6806 |
pass |
| 6807 |
f(d.D()) |
| 6808 |
[file b2.py] |
| 6809 |
import b1, d |
| 6810 |
from typing import Protocol |
| 6811 |
class P2(Protocol): |
| 6812 |
x: int |
| 6813 |
def f(x: b1.P1) -> None: |
| 6814 |
pass |
| 6815 |
f(d.D()) |
| 6816 |
[file d.py] |
| 6817 |
class D: |
| 6818 |
x: int |
| 6819 |
[file d.py.2] |
| 6820 |
class D: |
| 6821 |
y: int |
| 6822 |
[out] |
| 6823 |
b2.py:7: error: Argument 1 to "f" has incompatible type "D"; expected "P2" |
| 6824 |
b1.py:7: error: Argument 1 to "f" has incompatible type "D"; expected "P1" |
| 6825 |
|
| 6826 |
[case testProtocolsInvalidateByRemovingBase] |
| 6827 |
import a |
| 6828 |
[file a.py] |
| 6829 |
import b |
| 6830 |
def func(x: b.P) -> None: |
| 6831 |
pass |
| 6832 |
func(b.B()) |
| 6833 |
[file b.py] |
| 6834 |
from typing import Protocol |
| 6835 |
import c |
| 6836 |
class P(Protocol): |
| 6837 |
x: int |
| 6838 |
class B(c.C): |
| 6839 |
pass |
| 6840 |
[file c.py] |
| 6841 |
import d |
| 6842 |
class C(d.D): |
| 6843 |
pass |
| 6844 |
[file c.py.2] |
| 6845 |
import d |
| 6846 |
class C: |
| 6847 |
pass |
| 6848 |
[file d.py] |
| 6849 |
class D: |
| 6850 |
x: int |
| 6851 |
[out] |
| 6852 |
== |
| 6853 |
a.py:4: error: Argument 1 to "func" has incompatible type "B"; expected "P" |
| 6854 |
|
| 6855 |
[case testProtocolsInvalidateByRemovingMetaclass] |
| 6856 |
import a |
| 6857 |
[file a.py] |
| 6858 |
import b |
| 6859 |
def func(x: b.P) -> None: |
| 6860 |
pass |
| 6861 |
func(b.B) |
| 6862 |
[file b.py] |
| 6863 |
from typing import Protocol |
| 6864 |
import c |
| 6865 |
class P(Protocol): |
| 6866 |
x: int |
| 6867 |
class B(c.C): |
| 6868 |
pass |
| 6869 |
[file c.py] |
| 6870 |
import d |
| 6871 |
class C(metaclass=d.M): |
| 6872 |
pass |
| 6873 |
[file c.py.2] |
| 6874 |
import d |
| 6875 |
class C: |
| 6876 |
pass |
| 6877 |
[file d.py] |
| 6878 |
class M(type): |
| 6879 |
x: int |
| 6880 |
[out] |
| 6881 |
== |
| 6882 |
a.py:4: error: Argument 1 to "func" has incompatible type "type[B]"; expected "P" |
| 6883 |
|
| 6884 |
[case testProtocolVsProtocolSubUpdated] |
| 6885 |
import a |
| 6886 |
[file a.py] |
| 6887 |
import b, c |
| 6888 |
x: b.SuperP |
| 6889 |
y: c.SubP |
| 6890 |
x = y |
| 6891 |
[file b.py] |
| 6892 |
from typing import Protocol |
| 6893 |
class SuperP(Protocol): |
| 6894 |
x: int |
| 6895 |
[file c.py] |
| 6896 |
from typing import Protocol |
| 6897 |
import d |
| 6898 |
class SubP(d.PBase, Protocol): |
| 6899 |
y: str |
| 6900 |
[file d.py] |
| 6901 |
from typing import Protocol |
| 6902 |
class PBase(Protocol): |
| 6903 |
x: int |
| 6904 |
[file d.py.2] |
| 6905 |
from typing import Protocol |
| 6906 |
class PBase(Protocol): |
| 6907 |
x: str |
| 6908 |
[out] |
| 6909 |
== |
| 6910 |
a.py:4: error: Incompatible types in assignment (expression has type "SubP", variable has type "SuperP") |
| 6911 |
a.py:4: note: Following member(s) of "SubP" have conflicts: |
| 6912 |
a.py:4: note: x: expected "int", got "str" |
| 6913 |
|
| 6914 |
[case testProtocolVsProtocolSuperUpdated] |
| 6915 |
import a |
| 6916 |
[file a.py] |
| 6917 |
import b, c |
| 6918 |
x: b.SuperP |
| 6919 |
y: c.SubP |
| 6920 |
x = y |
| 6921 |
[file b.py] |
| 6922 |
from typing import Protocol |
| 6923 |
import d |
| 6924 |
class SuperP(d.PBase, Protocol): |
| 6925 |
pass |
| 6926 |
[file c.py] |
| 6927 |
from typing import Protocol |
| 6928 |
class SubP(Protocol): |
| 6929 |
x: int |
| 6930 |
[file d.py] |
| 6931 |
from typing import Protocol |
| 6932 |
class PBase(Protocol): |
| 6933 |
x: int |
| 6934 |
[file d.py.2] |
| 6935 |
from typing import Protocol |
| 6936 |
class PBase(Protocol): |
| 6937 |
y: int |
| 6938 |
[out] |
| 6939 |
== |
| 6940 |
a.py:4: error: Incompatible types in assignment (expression has type "SubP", variable has type "SuperP") |
| 6941 |
|
| 6942 |
[case testProtocolVsProtocolSuperUpdated2] |
| 6943 |
import a |
| 6944 |
[file a.py] |
| 6945 |
import b, c |
| 6946 |
x: b.SuperP |
| 6947 |
y: c.SubP |
| 6948 |
x = y |
| 6949 |
[file b.py] |
| 6950 |
from typing import Protocol |
| 6951 |
import d |
| 6952 |
class SuperP(d.PBase, Protocol): |
| 6953 |
x: int |
| 6954 |
[file c.py] |
| 6955 |
from typing import Protocol |
| 6956 |
class SubP(Protocol): |
| 6957 |
x: int |
| 6958 |
y: int |
| 6959 |
[file d.py] |
| 6960 |
from typing import Protocol |
| 6961 |
class PBase(Protocol): |
| 6962 |
y: int |
| 6963 |
[file d.py.2] |
| 6964 |
from typing import Protocol |
| 6965 |
class PBase(Protocol): |
| 6966 |
y: int |
| 6967 |
z: int |
| 6968 |
[out] |
| 6969 |
== |
| 6970 |
a.py:4: error: Incompatible types in assignment (expression has type "SubP", variable has type "SuperP") |
| 6971 |
a.py:4: note: "SubP" is missing following "SuperP" protocol member: |
| 6972 |
a.py:4: note: z |
| 6973 |
|
| 6974 |
[case testProtocolVsProtocolSuperUpdated3] |
| 6975 |
import a |
| 6976 |
[file a.py] |
| 6977 |
import b, c |
| 6978 |
x: b.SuperP |
| 6979 |
y: c.SubP |
| 6980 |
x = y |
| 6981 |
[file b.py] |
| 6982 |
from typing import Protocol |
| 6983 |
import d |
| 6984 |
class SuperP(d.PBase, Protocol): |
| 6985 |
x: int |
| 6986 |
[file c.py] |
| 6987 |
from typing import Protocol |
| 6988 |
class SubP(Protocol): |
| 6989 |
x: int |
| 6990 |
y: int |
| 6991 |
[file d.py] |
| 6992 |
from typing import Protocol |
| 6993 |
import e |
| 6994 |
class PBase(Protocol): |
| 6995 |
y: int |
| 6996 |
[file d.py.2] |
| 6997 |
from typing import Protocol |
| 6998 |
import e |
| 6999 |
class PBase(e.NewP, Protocol): |
| 7000 |
y: int |
| 7001 |
[file e.py] |
| 7002 |
from typing import Protocol |
| 7003 |
class NewP(Protocol): |
| 7004 |
z: int |
| 7005 |
[out] |
| 7006 |
== |
| 7007 |
a.py:4: error: Incompatible types in assignment (expression has type "SubP", variable has type "SuperP") |
| 7008 |
a.py:4: note: "SubP" is missing following "SuperP" protocol member: |
| 7009 |
a.py:4: note: z |
| 7010 |
|
| 7011 |
[case testProtocolMultipleUpdates] |
| 7012 |
import a |
| 7013 |
[file a.py] |
| 7014 |
import b, c |
| 7015 |
x: b.P = c.C() |
| 7016 |
[file b.py] |
| 7017 |
from typing import Protocol |
| 7018 |
import b2 |
| 7019 |
class P(b2.P2, Protocol): |
| 7020 |
x: int |
| 7021 |
[file b2.py] |
| 7022 |
from typing import Protocol |
| 7023 |
class P2(Protocol): |
| 7024 |
y: int |
| 7025 |
[file c.py] |
| 7026 |
import c2 |
| 7027 |
class C(c2.C2): |
| 7028 |
x: int |
| 7029 |
[file c2.py] |
| 7030 |
class C2: |
| 7031 |
y: int |
| 7032 |
[file b2.py.2] |
| 7033 |
from typing import Protocol |
| 7034 |
class P2(Protocol): |
| 7035 |
y: int |
| 7036 |
z: int |
| 7037 |
[file c2.py.3] |
| 7038 |
class C2: |
| 7039 |
y: int |
| 7040 |
z: int |
| 7041 |
[file c2.py.4] |
| 7042 |
class C2: |
| 7043 |
y: int |
| 7044 |
z: str |
| 7045 |
[out] |
| 7046 |
== |
| 7047 |
a.py:2: error: Incompatible types in assignment (expression has type "C", variable has type "P") |
| 7048 |
a.py:2: note: "C" is missing following "P" protocol member: |
| 7049 |
a.py:2: note: z |
| 7050 |
== |
| 7051 |
== |
| 7052 |
a.py:2: error: Incompatible types in assignment (expression has type "C", variable has type "P") |
| 7053 |
a.py:2: note: Following member(s) of "C" have conflicts: |
| 7054 |
a.py:2: note: z: expected "int", got "str" |
| 7055 |
|
| 7056 |
[case testWeAreCarefulWithBuiltinProtocols] |
| 7057 |
import a |
| 7058 |
x: a.A |
| 7059 |
for i in x: |
| 7060 |
pass |
| 7061 |
[file a.py] |
| 7062 |
from typing import Iterator |
| 7063 |
class A: |
| 7064 |
def __iter__(self) -> Iterator[int]: |
| 7065 |
pass |
| 7066 |
[file a.py.2] |
| 7067 |
class A: |
| 7068 |
pass |
| 7069 |
[out] |
| 7070 |
== |
| 7071 |
main:3: error: "A" has no attribute "__iter__" (not iterable) |
| 7072 |
|
| 7073 |
[case testWeAreCarefulWithBuiltinProtocolsBase] |
| 7074 |
import a |
| 7075 |
x: a.A |
| 7076 |
for i in x: |
| 7077 |
pass |
| 7078 |
[file a.py] |
| 7079 |
import b |
| 7080 |
class A(b.B): |
| 7081 |
pass |
| 7082 |
[file a.py.2] |
| 7083 |
class A: |
| 7084 |
pass |
| 7085 |
[file b.py] |
| 7086 |
from typing import Iterator |
| 7087 |
class B: |
| 7088 |
def __iter__(self) -> Iterator[int]: |
| 7089 |
pass |
| 7090 |
[out] |
| 7091 |
== |
| 7092 |
main:3: error: "A" has no attribute "__iter__" (not iterable) |
| 7093 |
|
| 7094 |
[case testOverloadsSimpleFrom] |
| 7095 |
import a |
| 7096 |
[file a.py] |
| 7097 |
import mod |
| 7098 |
def f() -> None: |
| 7099 |
x: str = mod.f(str()) |
| 7100 |
[file mod.py] |
| 7101 |
from typing import overload |
| 7102 |
@overload |
| 7103 |
def f(x: int) -> None: pass |
| 7104 |
@overload |
| 7105 |
def f(x: str) -> str: pass |
| 7106 |
def f(x): |
| 7107 |
pass |
| 7108 |
[file mod.py.2] |
| 7109 |
from typing import overload |
| 7110 |
@overload |
| 7111 |
def f(x: int) -> None: pass |
| 7112 |
@overload |
| 7113 |
def f(x: str) -> int: pass |
| 7114 |
def f(x): |
| 7115 |
pass |
| 7116 |
[out] |
| 7117 |
== |
| 7118 |
a.py:3: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 7119 |
|
| 7120 |
[case testOverloadsSimpleToNested] |
| 7121 |
from typing import overload, Any |
| 7122 |
import mod |
| 7123 |
def outer() -> None: |
| 7124 |
@overload |
| 7125 |
def f(x: int) -> None: pass |
| 7126 |
@overload |
| 7127 |
def f(x: str) -> str: pass |
| 7128 |
def f(x: Any) -> Any: |
| 7129 |
y: int = mod.f() |
| 7130 |
[file mod.py] |
| 7131 |
def f() -> int: |
| 7132 |
pass |
| 7133 |
[file mod.py.2] |
| 7134 |
def f() -> str: |
| 7135 |
pass |
| 7136 |
[out] |
| 7137 |
== |
| 7138 |
main:9: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 7139 |
|
| 7140 |
[case testOverloadsRemovedOverload] |
| 7141 |
import mod |
| 7142 |
def f() -> None: |
| 7143 |
x: str = mod.f(str()) |
| 7144 |
[file mod.py] |
| 7145 |
class C: pass |
| 7146 |
from typing import overload |
| 7147 |
@overload |
| 7148 |
def f(x: int) -> None: pass |
| 7149 |
@overload |
| 7150 |
def f(x: str) -> str: pass |
| 7151 |
@overload |
| 7152 |
def f(x: C) -> int: pass |
| 7153 |
def f(x): |
| 7154 |
pass |
| 7155 |
[file mod.py.2] |
| 7156 |
class C: pass |
| 7157 |
from typing import overload |
| 7158 |
@overload |
| 7159 |
def f(x: int) -> None: pass |
| 7160 |
@overload |
| 7161 |
def f(x: C) -> int: pass |
| 7162 |
def f(x): |
| 7163 |
pass |
| 7164 |
[out] |
| 7165 |
== |
| 7166 |
main:3: error: No overload variant of "f" matches argument type "str" |
| 7167 |
main:3: note: Possible overload variants: |
| 7168 |
main:3: note: def f(x: int) -> None |
| 7169 |
main:3: note: def f(x: C) -> int |
| 7170 |
|
| 7171 |
[case testOverloadsDeleted] |
| 7172 |
import mod |
| 7173 |
def f() -> None: |
| 7174 |
x: str = mod.f(str()) |
| 7175 |
[file mod.py] |
| 7176 |
from typing import overload |
| 7177 |
@overload |
| 7178 |
def f(x: int) -> None: pass |
| 7179 |
@overload |
| 7180 |
def f(x: str) -> str: pass |
| 7181 |
def f(x): |
| 7182 |
pass |
| 7183 |
[file mod.py.2] |
| 7184 |
from typing import overload |
| 7185 |
[builtins fixtures/module.pyi] |
| 7186 |
[out] |
| 7187 |
== |
| 7188 |
main:3: error: Module has no attribute "f" |
| 7189 |
|
| 7190 |
[case testOverloadsUpdatedTypeRecheckImplementation] |
| 7191 |
from typing import overload |
| 7192 |
import mod |
| 7193 |
class Outer: |
| 7194 |
@overload |
| 7195 |
def f(self, x: mod.D) -> mod.D: pass |
| 7196 |
@overload |
| 7197 |
def f(self, x: mod.E) -> mod.E: pass |
| 7198 |
def f(self, x: mod.C) -> mod.C: |
| 7199 |
x.x = int() |
| 7200 |
return x |
| 7201 |
[file mod.py] |
| 7202 |
import submod |
| 7203 |
class C(submod.B): |
| 7204 |
pass |
| 7205 |
class D(C): |
| 7206 |
pass |
| 7207 |
class E(C): |
| 7208 |
pass |
| 7209 |
[file submod.py] |
| 7210 |
import base |
| 7211 |
class B(base.AI): |
| 7212 |
pass |
| 7213 |
[file submod.py.2] |
| 7214 |
import base |
| 7215 |
class B(base.AS): |
| 7216 |
pass |
| 7217 |
[file base.py] |
| 7218 |
class AI: |
| 7219 |
x: int |
| 7220 |
class AS: |
| 7221 |
x: str |
| 7222 |
[out] |
| 7223 |
== |
| 7224 |
main:9: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 7225 |
|
| 7226 |
[case testOverloadsUpdatedTypeRecheckConsistency] |
| 7227 |
from typing import overload |
| 7228 |
import mod |
| 7229 |
class Outer: |
| 7230 |
@overload |
| 7231 |
def f(self, x: mod.D) -> mod.D: pass |
| 7232 |
@overload |
| 7233 |
def f(self, x: mod.E) -> mod.E: pass |
| 7234 |
def f(self, x: mod.C) -> mod.C: |
| 7235 |
pass |
| 7236 |
[file mod.py] |
| 7237 |
class C: |
| 7238 |
pass |
| 7239 |
class D(C): |
| 7240 |
pass |
| 7241 |
class E(C): |
| 7242 |
pass |
| 7243 |
[file mod.py.2] |
| 7244 |
class C: |
| 7245 |
pass |
| 7246 |
class D(C): |
| 7247 |
pass |
| 7248 |
class E: |
| 7249 |
pass |
| 7250 |
[out] |
| 7251 |
== |
| 7252 |
main:8: error: Overloaded function implementation does not accept all possible parameters of signature 2 |
| 7253 |
main:8: error: Overloaded function implementation cannot produce return type of signature 2 |
| 7254 |
|
| 7255 |
[case testOverloadsGenericTypevarUpdated] |
| 7256 |
import a |
| 7257 |
[file a.py] |
| 7258 |
import b |
| 7259 |
b.f(int()) |
| 7260 |
[file b.py] |
| 7261 |
from typing import overload |
| 7262 |
import c |
| 7263 |
class C: pass |
| 7264 |
@overload |
| 7265 |
def f(x: C) -> None: pass |
| 7266 |
@overload |
| 7267 |
def f(x: c.T) -> c.T: pass |
| 7268 |
def f(x): |
| 7269 |
pass |
| 7270 |
[file c.py] |
| 7271 |
from typing import TypeVar |
| 7272 |
T = TypeVar('T', int, str) |
| 7273 |
[file c.py.2] |
| 7274 |
from typing import TypeVar |
| 7275 |
T = TypeVar('T', bound=str) |
| 7276 |
[out] |
| 7277 |
== |
| 7278 |
a.py:2: error: No overload variant of "f" matches argument type "int" |
| 7279 |
a.py:2: note: Possible overload variants: |
| 7280 |
a.py:2: note: def f(x: C) -> None |
| 7281 |
a.py:2: note: def [c.T: str] f(x: c.T) -> c.T |
| 7282 |
|
| 7283 |
[case testOverloadsGenericToNonGeneric] |
| 7284 |
import a |
| 7285 |
[file a.py] |
| 7286 |
import b |
| 7287 |
b.f(int()) |
| 7288 |
[file b.py] |
| 7289 |
from typing import overload |
| 7290 |
import c |
| 7291 |
class C: pass |
| 7292 |
@overload |
| 7293 |
def f(x: C) -> None: pass |
| 7294 |
@overload |
| 7295 |
def f(x: c.T) -> c.T: pass |
| 7296 |
def f(x): |
| 7297 |
pass |
| 7298 |
[file c.py] |
| 7299 |
from typing import TypeVar |
| 7300 |
T = TypeVar('T', bound=int) |
| 7301 |
[file c.py.2] |
| 7302 |
from typing import TypeVar |
| 7303 |
class T: pass |
| 7304 |
[out] |
| 7305 |
== |
| 7306 |
a.py:2: error: No overload variant of "f" matches argument type "int" |
| 7307 |
a.py:2: note: Possible overload variants: |
| 7308 |
a.py:2: note: def f(x: C) -> None |
| 7309 |
a.py:2: note: def f(x: T) -> T |
| 7310 |
|
| 7311 |
[case testOverloadsToNonOverloaded] |
| 7312 |
import a |
| 7313 |
[file a.py] |
| 7314 |
import mod |
| 7315 |
def f() -> None: |
| 7316 |
x: str = mod.f(str()) |
| 7317 |
[file mod.py] |
| 7318 |
from typing import overload |
| 7319 |
@overload |
| 7320 |
def f(x: int) -> None: pass |
| 7321 |
@overload |
| 7322 |
def f(x: str) -> str: pass |
| 7323 |
def f(x): |
| 7324 |
pass |
| 7325 |
[file mod.py.2] |
| 7326 |
from typing import overload |
| 7327 |
def f(x: int) -> int: |
| 7328 |
pass |
| 7329 |
[out] |
| 7330 |
== |
| 7331 |
a.py:3: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 7332 |
a.py:3: error: Argument 1 to "f" has incompatible type "str"; expected "int" |
| 7333 |
|
| 7334 |
[case testOverloadsUpdateFunctionToOverloaded] |
| 7335 |
import a |
| 7336 |
[file a.py] |
| 7337 |
import mod |
| 7338 |
def f() -> None: |
| 7339 |
x: str = mod.f(str()) |
| 7340 |
[file mod.py] |
| 7341 |
from typing import overload |
| 7342 |
def f(x: str) -> str: |
| 7343 |
pass |
| 7344 |
[file mod.py.2] |
| 7345 |
from typing import overload |
| 7346 |
@overload |
| 7347 |
def f(x: int) -> None: pass |
| 7348 |
@overload |
| 7349 |
def f(x: str) -> int: pass |
| 7350 |
def f(x): |
| 7351 |
pass |
| 7352 |
[out] |
| 7353 |
== |
| 7354 |
a.py:3: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 7355 |
|
| 7356 |
[case testOverloadedUpdateToClass] |
| 7357 |
import a |
| 7358 |
[file a.py] |
| 7359 |
import mod |
| 7360 |
def f() -> None: |
| 7361 |
x: str = mod.f(str()) |
| 7362 |
[file mod.py] |
| 7363 |
from typing import overload |
| 7364 |
@overload |
| 7365 |
def f(x: int) -> None: pass |
| 7366 |
@overload |
| 7367 |
def f(x: str) -> str: pass |
| 7368 |
def f(x): |
| 7369 |
pass |
| 7370 |
[file mod.py.2] |
| 7371 |
from typing import overload |
| 7372 |
class f: |
| 7373 |
def __init__(self, x: str) -> None: |
| 7374 |
pass |
| 7375 |
[out] |
| 7376 |
== |
| 7377 |
a.py:3: error: Incompatible types in assignment (expression has type "f", variable has type "str") |
| 7378 |
|
| 7379 |
[case testDepsFromOverloadUpdatedAttrRecheckImpl] |
| 7380 |
import mod |
| 7381 |
x = mod.f |
| 7382 |
[file mod.py] |
| 7383 |
from typing import overload, Any |
| 7384 |
import submod |
| 7385 |
@overload |
| 7386 |
def f(x: int) -> submod.A: pass |
| 7387 |
@overload |
| 7388 |
def f(x: str) -> submod.B: pass |
| 7389 |
def f(x) -> Any: |
| 7390 |
y: submod.C |
| 7391 |
y.x = int() |
| 7392 |
[file submod.py] |
| 7393 |
import other |
| 7394 |
class A: pass |
| 7395 |
class B: pass |
| 7396 |
C = other.C |
| 7397 |
[file other.py] |
| 7398 |
class C: |
| 7399 |
x: int |
| 7400 |
[file other.py.2] |
| 7401 |
class C: |
| 7402 |
x: str |
| 7403 |
[out] |
| 7404 |
== |
| 7405 |
mod.py:9: error: Incompatible types in assignment (expression has type "int", variable has type "str") |
| 7406 |
|
| 7407 |
[case testOverloadedMethodSupertype] |
| 7408 |
from typing import overload, Any |
| 7409 |
import b |
| 7410 |
class Child(b.Parent): |
| 7411 |
@overload # Fail |
| 7412 |
def f(self, arg: int) -> int: ... |
| 7413 |
@overload |
| 7414 |
def f(self, arg: str) -> str: ... |
| 7415 |
def f(self, arg: Any) -> Any: ... |
| 7416 |
[file b.py] |
| 7417 |
from typing import overload, Any |
| 7418 |
class C: pass |
| 7419 |
class Parent: |
| 7420 |
@overload |
| 7421 |
def f(self, arg: int) -> int: ... |
| 7422 |
@overload |
| 7423 |
def f(self, arg: str) -> str: ... |
| 7424 |
def f(self, arg: Any) -> Any: ... |
| 7425 |
[file b.py.2] |
| 7426 |
from typing import overload, Any |
| 7427 |
class C: pass |
| 7428 |
class Parent: |
| 7429 |
@overload |
| 7430 |
def f(self, arg: int) -> int: ... |
| 7431 |
@overload |
| 7432 |
def f(self, arg: str) -> C: ... |
| 7433 |
def f(self, arg: Any) -> Any: ... |
| 7434 |
[out] |
| 7435 |
== |
| 7436 |
main:4: error: Signature of "f" incompatible with supertype "b.Parent" |
| 7437 |
main:4: note: Superclass: |
| 7438 |
main:4: note: @overload |
| 7439 |
main:4: note: def f(self, arg: int) -> int |
| 7440 |
main:4: note: @overload |
| 7441 |
main:4: note: def f(self, arg: str) -> C |
| 7442 |
main:4: note: Subclass: |
| 7443 |
main:4: note: @overload |
| 7444 |
main:4: note: def f(self, arg: int) -> int |
| 7445 |
main:4: note: @overload |
| 7446 |
main:4: note: def f(self, arg: str) -> str |
| 7447 |
|
| 7448 |
[case testOverloadedInitSupertype] |
| 7449 |
import a |
| 7450 |
[file a.py] |
| 7451 |
from b import B |
| 7452 |
B(int()) |
| 7453 |
[file b.py] |
| 7454 |
import c |
| 7455 |
class B(c.C): |
| 7456 |
pass |
| 7457 |
[file c.py] |
| 7458 |
from typing import overload |
| 7459 |
class C: |
| 7460 |
def __init__(self, x: int) -> None: |
| 7461 |
pass |
| 7462 |
[file c.py.2] |
| 7463 |
from typing import overload |
| 7464 |
class C: |
| 7465 |
@overload |
| 7466 |
def __init__(self, x: str) -> None: pass |
| 7467 |
@overload |
| 7468 |
def __init__(self, x: str, y: int) -> None: pass |
| 7469 |
def __init__(self, *args, **kwargs) -> None: |
| 7470 |
pass |
| 7471 |
[builtins fixtures/dict.pyi] |
| 7472 |
[out] |
| 7473 |
== |
| 7474 |
a.py:2: error: No overload variant of "B" matches argument type "int" |
| 7475 |
a.py:2: note: Possible overload variants: |
| 7476 |
a.py:2: note: def B(x: str) -> B |
| 7477 |
a.py:2: note: def B(x: str, y: int) -> B |
| 7478 |
|
| 7479 |
[case testOverloadedToNormalMethodMetaclass] |
| 7480 |
import a |
| 7481 |
[file a.py] |
| 7482 |
import b |
| 7483 |
b.B.f(int()) |
| 7484 |
[file b.py] |
| 7485 |
import c |
| 7486 |
class B(metaclass=c.M): |
| 7487 |
pass |
| 7488 |
[file c.py] |
| 7489 |
from typing import overload |
| 7490 |
class M(type): |
| 7491 |
@overload |
| 7492 |
def f(cls, x: str) -> str: pass |
| 7493 |
@overload |
| 7494 |
def f(cls, x: int) -> None: pass |
| 7495 |
def f(cls, x): |
| 7496 |
pass |
| 7497 |
[file c.py.2] |
| 7498 |
from typing import overload |
| 7499 |
class M(type): |
| 7500 |
def f(cls, x: str) -> str: |
| 7501 |
pass |
| 7502 |
[out] |
| 7503 |
== |
| 7504 |
a.py:2: error: Argument 1 to "f" of "M" has incompatible type "int"; expected "str" |
| 7505 |
|
| 7506 |
[case testYieldFrom] |
| 7507 |
from typing import Iterator |
| 7508 |
from a import f |
| 7509 |
|
| 7510 |
def g() -> Iterator[int]: |
| 7511 |
a = "string" |
| 7512 |
if int(): |
| 7513 |
a = yield from f() |
| 7514 |
|
| 7515 |
[file a.py] |
| 7516 |
from typing import Generator |
| 7517 |
|
| 7518 |
def f() -> Generator[int, None, str]: |
| 7519 |
yield 5 |
| 7520 |
return "ham" |
| 7521 |
|
| 7522 |
[file a.py.2] |
| 7523 |
from typing import Generator |
| 7524 |
|
| 7525 |
class A: pass |
| 7526 |
|
| 7527 |
def f() -> Generator[int, None, A]: |
| 7528 |
yield 5 |
| 7529 |
return A() |
| 7530 |
|
| 7531 |
[out] |
| 7532 |
== |
| 7533 |
main:7: error: Incompatible types in assignment (expression has type "A", variable has type "str") |
| 7534 |
|
| 7535 |
[case testFString] |
| 7536 |
from a import g |
| 7537 |
f'{g(1)}' |
| 7538 |
[file a.py] |
| 7539 |
def g(x: int) -> str: pass |
| 7540 |
[file a.py.2] |
| 7541 |
def g(x: str) -> str: pass |
| 7542 |
[builtins fixtures/f_string.pyi] |
| 7543 |
[out] |
| 7544 |
== |
| 7545 |
main:2: error: Argument 1 to "g" has incompatible type "int"; expected "str" |
| 7546 |
|
| 7547 |
[case testExtendedUnpacking-only_when_nocache] |
| 7548 |
from typing import List |
| 7549 |
from a import g |
| 7550 |
def f() -> List[int]: |
| 7551 |
a, *b = g() |
| 7552 |
return b |
| 7553 |
|
| 7554 |
[file a.py] |
| 7555 |
from typing import Tuple |
| 7556 |
def g() -> Tuple[str, int, int]: pass |
| 7557 |
|
| 7558 |
[file a.py.2] |
| 7559 |
from typing import Tuple |
| 7560 |
def g() -> Tuple[str, str]: pass |
| 7561 |
|
| 7562 |
[builtins fixtures/tuple.pyi] |
| 7563 |
[out] |
| 7564 |
== |
| 7565 |
main:5: error: Incompatible return value type (got "list[str]", expected "list[int]") |
| 7566 |
|
| 7567 |
[case testUnpackInExpression1-only_when_nocache] |
| 7568 |
from typing import Tuple, List |
| 7569 |
from a import t |
| 7570 |
|
| 7571 |
def f() -> Tuple[int, int]: |
| 7572 |
return (1, *t()) |
| 7573 |
|
| 7574 |
def g() -> List[int]: |
| 7575 |
return [1, *t()] |
| 7576 |
|
| 7577 |
[file a.py] |
| 7578 |
from typing import Tuple |
| 7579 |
def t() -> Tuple[int]: ... |
| 7580 |
|
| 7581 |
[file a.py.2] |
| 7582 |
from typing import Tuple |
| 7583 |
def t() -> Tuple[str]: ... |
| 7584 |
|
| 7585 |
[builtins fixtures/list.pyi] |
| 7586 |
[out] |
| 7587 |
== |
| 7588 |
main:5: error: Incompatible return value type (got "tuple[int, str]", expected "tuple[int, int]") |
| 7589 |
main:8: error: List item 1 has incompatible type "tuple[str]"; expected "int" |
| 7590 |
|
| 7591 |
[case testUnpackInExpression2-only_when_nocache] |
| 7592 |
from typing import Set |
| 7593 |
from a import t |
| 7594 |
|
| 7595 |
def f() -> Set[int]: |
| 7596 |
return {1, *t()} |
| 7597 |
|
| 7598 |
[file a.py] |
| 7599 |
from typing import Tuple |
| 7600 |
def t() -> Tuple[int]: pass |
| 7601 |
|
| 7602 |
[file a.py.2] |
| 7603 |
from typing import Tuple |
| 7604 |
def t() -> Tuple[str]: pass |
| 7605 |
|
| 7606 |
[builtins fixtures/set.pyi] |
| 7607 |
[out] |
| 7608 |
== |
| 7609 |
main:5: error: Argument 2 to <set> has incompatible type "*tuple[str]"; expected "int" |
| 7610 |
|
| 7611 |
[case testUnpackInExpression3-only_when_nocache] |
| 7612 |
from typing import Dict |
| 7613 |
from a import d |
| 7614 |
|
| 7615 |
def f() -> Dict[int, str]: |
| 7616 |
return {1: '', **d()} |
| 7617 |
|
| 7618 |
[file a.py] |
| 7619 |
from typing import Dict |
| 7620 |
def d() -> Dict[int, str]: pass |
| 7621 |
|
| 7622 |
[file a.py.2] |
| 7623 |
from typing import Dict |
| 7624 |
def d() -> Dict[int, int]: pass |
| 7625 |
|
| 7626 |
[builtins fixtures/dict.pyi] |
| 7627 |
[out] |
| 7628 |
== |
| 7629 |
main:5: error: Unpacked dict entry 1 has incompatible type "dict[int, int]"; expected "SupportsKeysAndGetItem[int, str]" |
| 7630 |
|
| 7631 |
[case testAwaitAndAsyncDef-only_when_nocache] |
| 7632 |
from a import g |
| 7633 |
|
| 7634 |
async def f() -> int: |
| 7635 |
return await g() |
| 7636 |
|
| 7637 |
[file a.py] |
| 7638 |
async def g() -> int: |
| 7639 |
return 0 |
| 7640 |
|
| 7641 |
[file a.py.2] |
| 7642 |
async def g() -> str: |
| 7643 |
return '' |
| 7644 |
|
| 7645 |
[builtins fixtures/async_await.pyi] |
| 7646 |
[typing fixtures/typing-async.pyi] |
| 7647 |
[out] |
| 7648 |
== |
| 7649 |
main:4: error: Incompatible return value type (got "str", expected "int") |
| 7650 |
|
| 7651 |
[case testAwaitAnd__await__-only_when_nocache] |
| 7652 |
from a import C |
| 7653 |
|
| 7654 |
async def f(c: C) -> int: |
| 7655 |
return await c |
| 7656 |
|
| 7657 |
[file a.py] |
| 7658 |
from typing import Any, Generator |
| 7659 |
class C: |
| 7660 |
def __await__(self) -> Generator[Any, None, int]: |
| 7661 |
yield |
| 7662 |
return 0 |
| 7663 |
|
| 7664 |
[file a.py.2] |
| 7665 |
from typing import Any, Generator |
| 7666 |
class C: |
| 7667 |
def __await__(self) -> Generator[Any, None, str]: |
| 7668 |
yield |
| 7669 |
return '' |
| 7670 |
|
| 7671 |
[builtins fixtures/async_await.pyi] |
| 7672 |
[typing fixtures/typing-async.pyi] |
| 7673 |
[out] |
| 7674 |
== |
| 7675 |
main:4: error: Incompatible return value type (got "str", expected "int") |
| 7676 |
|
| 7677 |
[case test__aiter__and__anext__] |
| 7678 |
from a import C |
| 7679 |
|
| 7680 |
async def f() -> int: |
| 7681 |
async for x in C(): |
| 7682 |
pass |
| 7683 |
return x |
| 7684 |
|
| 7685 |
[file a.py] |
| 7686 |
class C: |
| 7687 |
def __aiter__(self) -> D: pass |
| 7688 |
class D: |
| 7689 |
def __aiter__(self) -> D: pass |
| 7690 |
async def __anext__(self) -> int: return 0 |
| 7691 |
|
| 7692 |
[file a.py.2] |
| 7693 |
class C: |
| 7694 |
def __aiter__(self) -> D: pass |
| 7695 |
class D: |
| 7696 |
def __aiter__(self) -> D: pass |
| 7697 |
async def __anext__(self) -> str: return '' |
| 7698 |
|
| 7699 |
[file a.py.3] |
| 7700 |
class C: |
| 7701 |
def __aiter__(self) -> E: pass |
| 7702 |
class E: |
| 7703 |
def __aiter__(self) -> E: pass |
| 7704 |
async def __anext__(self) -> object: return 0 |
| 7705 |
|
| 7706 |
[builtins fixtures/async_await.pyi] |
| 7707 |
[typing fixtures/typing-async.pyi] |
| 7708 |
[out] |
| 7709 |
== |
| 7710 |
main:6: error: Incompatible return value type (got "str", expected "int") |
| 7711 |
== |
| 7712 |
main:6: error: Incompatible return value type (got "object", expected "int") |
| 7713 |
|
| 7714 |
[case testAsyncWith2-only_when_nocache] |
| 7715 |
from a import C |
| 7716 |
|
| 7717 |
async def f() -> int: |
| 7718 |
async with C() as x: |
| 7719 |
return x |
| 7720 |
|
| 7721 |
async def g() -> None: |
| 7722 |
async with C(): pass |
| 7723 |
|
| 7724 |
[file a.py] |
| 7725 |
class C: |
| 7726 |
async def __aenter__(self) -> int: pass |
| 7727 |
async def __aexit__(self, x, y, z) -> None: pass |
| 7728 |
|
| 7729 |
[file a.py.2] |
| 7730 |
class C: |
| 7731 |
async def __aenter__(self) -> str: pass |
| 7732 |
async def __aexit__(self, x, y, z) -> None: pass |
| 7733 |
|
| 7734 |
[file a.py.3] |
| 7735 |
from typing import Awaitable |
| 7736 |
class C: |
| 7737 |
async def __aenter__(self) -> int: pass |
| 7738 |
async def __aexit__(self, x, y, z) -> None: pass |
| 7739 |
|
| 7740 |
[file a.py.4] |
| 7741 |
from typing import Awaitable |
| 7742 |
class C: |
| 7743 |
async def __aenter__(self) -> int: pass |
| 7744 |
|
| 7745 |
[builtins fixtures/async_await.pyi] |
| 7746 |
[typing fixtures/typing-async.pyi] |
| 7747 |
[out] |
| 7748 |
== |
| 7749 |
main:5: error: Incompatible return value type (got "str", expected "int") |
| 7750 |
== |
| 7751 |
== |
| 7752 |
main:4: error: "C" has no attribute "__aexit__" |
| 7753 |
main:8: error: "C" has no attribute "__aexit__" |
| 7754 |
|
| 7755 |
[case testLiskovFineVariable] |
| 7756 |
import b |
| 7757 |
class A(b.B): |
| 7758 |
x: str |
| 7759 |
def f(x: b.B) -> None: |
| 7760 |
x.x + int() |
| 7761 |
f(A()) |
| 7762 |
[file b.py] |
| 7763 |
class B: |
| 7764 |
x: str |
| 7765 |
[file b.py.2] |
| 7766 |
class B: |
| 7767 |
x: int |
| 7768 |
[builtins fixtures/primitives.pyi] |
| 7769 |
[out] |
| 7770 |
main:5: error: Unsupported operand types for + ("str" and "int") |
| 7771 |
== |
| 7772 |
main:3: error: Incompatible types in assignment (expression has type "str", base class "B" defined the type as "int") |
| 7773 |
|
| 7774 |
[case testLiskovFineVariableInFunction] |
| 7775 |
from b import B |
| 7776 |
def outer() -> None: |
| 7777 |
class A(B): |
| 7778 |
x: str |
| 7779 |
def f(x: B) -> None: |
| 7780 |
x.x + int() |
| 7781 |
[file b.py] |
| 7782 |
class B: |
| 7783 |
x: str |
| 7784 |
[file b.py.2] |
| 7785 |
class B: |
| 7786 |
x: int |
| 7787 |
[builtins fixtures/primitives.pyi] |
| 7788 |
[out] |
| 7789 |
main:6: error: Unsupported operand types for + ("str" and "int") |
| 7790 |
== |
| 7791 |
main:4: error: Incompatible types in assignment (expression has type "str", base class "B" defined the type as "int") |
| 7792 |
|
| 7793 |
[case testLiskovFineDecorator] |
| 7794 |
import b |
| 7795 |
from c import deco |
| 7796 |
class A(b.B): |
| 7797 |
@deco |
| 7798 |
def m(self) -> str: pass |
| 7799 |
def f(x: b.B) -> None: |
| 7800 |
x.m() + int() |
| 7801 |
f(A()) |
| 7802 |
[file b.py] |
| 7803 |
from c import deco |
| 7804 |
class B: |
| 7805 |
@deco |
| 7806 |
def m(self) -> str: pass |
| 7807 |
[file b.py.2] |
| 7808 |
from c import deco |
| 7809 |
class B: |
| 7810 |
@deco |
| 7811 |
def m(self) -> int: pass |
| 7812 |
[file c.py] |
| 7813 |
from typing import Callable, TypeVar |
| 7814 |
F = TypeVar('F', bound=Callable) |
| 7815 |
def deco(f: F) -> F: |
| 7816 |
pass |
| 7817 |
[builtins fixtures/primitives.pyi] |
| 7818 |
[out] |
| 7819 |
main:7: error: Unsupported operand types for + ("str" and "int") |
| 7820 |
== |
| 7821 |
main:5: error: Return type "str" of "m" incompatible with return type "int" in supertype "b.B" |
| 7822 |
|
| 7823 |
[case testLiskovFineVariableClean-only_when_nocache] |
| 7824 |
import b |
| 7825 |
class A(b.B): |
| 7826 |
x: str |
| 7827 |
[file b.py] |
| 7828 |
class B: |
| 7829 |
x: str |
| 7830 |
[file b.py.2] |
| 7831 |
class B: |
| 7832 |
x: int |
| 7833 |
[out] |
| 7834 |
== |
| 7835 |
main:3: error: Incompatible types in assignment (expression has type "str", base class "B" defined the type as "int") |
| 7836 |
|
| 7837 |
[case testLiskovFineVariableCleanDefInMethod-only_when_nocache] |
| 7838 |
import b |
| 7839 |
class A(b.B): |
| 7840 |
def meth(self) -> None: |
| 7841 |
self.x: str |
| 7842 |
[file b.py] |
| 7843 |
class B: |
| 7844 |
x: str |
| 7845 |
[file b.py.2] |
| 7846 |
class B: |
| 7847 |
x: int |
| 7848 |
[out] |
| 7849 |
== |
| 7850 |
main:4: error: Incompatible types in assignment (expression has type "str", base class "B" defined the type as "int") |
| 7851 |
|
| 7852 |
[case testLiskovFineVariableCleanDefInMethodStar-only_when_nocache] |
| 7853 |
from typing import List |
| 7854 |
import b |
| 7855 |
class A(b.B): |
| 7856 |
def meth(self) -> None: |
| 7857 |
self.x: str |
| 7858 |
self.y: List[str] |
| 7859 |
[file b.py] |
| 7860 |
from typing import List |
| 7861 |
class B: |
| 7862 |
y: List[str] |
| 7863 |
[file b.py.2] |
| 7864 |
from typing import List |
| 7865 |
class B: |
| 7866 |
y: List[int] |
| 7867 |
[builtins fixtures/list.pyi] |
| 7868 |
[out] |
| 7869 |
== |
| 7870 |
main:6: error: Incompatible types in assignment (expression has type "list[str]", base class "B" defined the type as "list[int]") |
| 7871 |
|
| 7872 |
[case testLiskovFineVariableCleanDefInMethodNested-only_when_nocache] |
| 7873 |
from b import B |
| 7874 |
def outer() -> None: |
| 7875 |
class A(B): |
| 7876 |
def meth(self) -> None: |
| 7877 |
self.x: str |
| 7878 |
[file b.py] |
| 7879 |
class B: |
| 7880 |
x: str |
| 7881 |
[file b.py.2] |
| 7882 |
class B: |
| 7883 |
x: int |
| 7884 |
[out] |
| 7885 |
== |
| 7886 |
main:5: error: Incompatible types in assignment (expression has type "str", base class "B" defined the type as "int") |
| 7887 |
|
| 7888 |
[case testLiskovFineVariableInFunctionClean-only_when_nocache] |
| 7889 |
from b import B |
| 7890 |
def outer() -> None: |
| 7891 |
class A(B): |
| 7892 |
x: str |
| 7893 |
[file b.py] |
| 7894 |
class B: |
| 7895 |
x: str |
| 7896 |
[file b.py.2] |
| 7897 |
class B: |
| 7898 |
x: int |
| 7899 |
[out] |
| 7900 |
== |
| 7901 |
main:4: error: Incompatible types in assignment (expression has type "str", base class "B" defined the type as "int") |
| 7902 |
|
| 7903 |
[case testLiskovFineDecoratorClean-only_when_nocache] |
| 7904 |
import b |
| 7905 |
from c import deco |
| 7906 |
class A(b.B): |
| 7907 |
@deco |
| 7908 |
def m(self) -> str: pass |
| 7909 |
[file b.py] |
| 7910 |
from c import deco |
| 7911 |
class B: |
| 7912 |
@deco |
| 7913 |
def m(self) -> str: pass |
| 7914 |
[file b.py.2] |
| 7915 |
from c import deco |
| 7916 |
class B: |
| 7917 |
@deco |
| 7918 |
def m(self) -> int: pass |
| 7919 |
[file c.py] |
| 7920 |
from typing import Callable, TypeVar |
| 7921 |
F = TypeVar('F', bound=Callable) |
| 7922 |
def deco(f: F) -> F: |
| 7923 |
pass |
| 7924 |
[out] |
| 7925 |
== |
| 7926 |
main:5: error: Return type "str" of "m" incompatible with return type "int" in supertype "b.B" |
| 7927 |
|
| 7928 |
[case testAddAbstractMethod] |
| 7929 |
from b import D |
| 7930 |
D() |
| 7931 |
[file b.py] |
| 7932 |
from a import C |
| 7933 |
class D(C): |
| 7934 |
def f(self) -> None: pass |
| 7935 |
[file a.py] |
| 7936 |
from abc import abstractmethod |
| 7937 |
class C: |
| 7938 |
@abstractmethod |
| 7939 |
def f(self) -> None: pass |
| 7940 |
[file a.py.2] |
| 7941 |
from abc import abstractmethod |
| 7942 |
class C: |
| 7943 |
@abstractmethod |
| 7944 |
def f(self) -> None: pass |
| 7945 |
@abstractmethod |
| 7946 |
def g(self) -> None: pass |
| 7947 |
[file a.py.3] |
| 7948 |
from abc import abstractmethod |
| 7949 |
class C: |
| 7950 |
@abstractmethod |
| 7951 |
def f(self) -> None: pass |
| 7952 |
def g(self) -> None: pass |
| 7953 |
[out] |
| 7954 |
== |
| 7955 |
main:2: error: Cannot instantiate abstract class "D" with abstract attribute "g" |
| 7956 |
== |
| 7957 |
|
| 7958 |
[case testMakeClassAbstract] |
| 7959 |
from a import C |
| 7960 |
c = C() |
| 7961 |
[file a.py] |
| 7962 |
from abc import abstractmethod |
| 7963 |
class C: pass |
| 7964 |
[file a.py.2] |
| 7965 |
from abc import abstractmethod |
| 7966 |
class C: |
| 7967 |
@abstractmethod |
| 7968 |
def f(self) -> None: pass |
| 7969 |
[out] |
| 7970 |
== |
| 7971 |
main:2: error: Cannot instantiate abstract class "C" with abstract attribute "f" |
| 7972 |
|
| 7973 |
[case testMakeMethodNoLongerAbstract1] |
| 7974 |
[file z.py] |
| 7975 |
from abc import abstractmethod, ABCMeta |
| 7976 |
class I(metaclass=ABCMeta): |
| 7977 |
@abstractmethod |
| 7978 |
def f(self) -> None: pass |
| 7979 |
@abstractmethod |
| 7980 |
def g(self) -> None: pass |
| 7981 |
[file b.py] |
| 7982 |
import z |
| 7983 |
def x() -> Foo: return Foo() |
| 7984 |
class Foo(z.I): |
| 7985 |
def f(self) -> None: pass |
| 7986 |
def g(self) -> None: pass |
| 7987 |
|
| 7988 |
[file z.py.2] |
| 7989 |
from abc import abstractmethod, ABCMeta |
| 7990 |
class I(metaclass=ABCMeta): |
| 7991 |
def f(self) -> None: pass |
| 7992 |
@abstractmethod |
| 7993 |
def g(self) -> None: pass |
| 7994 |
|
| 7995 |
[file b.py.2] |
| 7996 |
import z |
| 7997 |
def x() -> Foo: return Foo() |
| 7998 |
class Foo(z.I): |
| 7999 |
def g(self) -> None: pass |
| 8000 |
[out] |
| 8001 |
== |
| 8002 |
|
| 8003 |
[case testMakeMethodNoLongerAbstract2] |
| 8004 |
-- this version never failed, but it is just a file-renaming |
| 8005 |
-- away from the above test that did |
| 8006 |
[file a.py] |
| 8007 |
from abc import abstractmethod, ABCMeta |
| 8008 |
class I(metaclass=ABCMeta): |
| 8009 |
@abstractmethod |
| 8010 |
def f(self) -> None: pass |
| 8011 |
@abstractmethod |
| 8012 |
def g(self) -> None: pass |
| 8013 |
[file b.py] |
| 8014 |
import a |
| 8015 |
def x() -> Foo: return Foo() |
| 8016 |
class Foo(a.I): |
| 8017 |
def f(self) -> None: pass |
| 8018 |
def g(self) -> None: pass |
| 8019 |
|
| 8020 |
[file a.py.2] |
| 8021 |
from abc import abstractmethod, ABCMeta |
| 8022 |
class I(metaclass=ABCMeta): |
| 8023 |
def f(self) -> None: pass |
| 8024 |
@abstractmethod |
| 8025 |
def g(self) -> None: pass |
| 8026 |
|
| 8027 |
[file b.py.2] |
| 8028 |
import a |
| 8029 |
def x() -> Foo: return Foo() |
| 8030 |
class Foo(a.I): |
| 8031 |
def g(self) -> None: pass |
| 8032 |
[out] |
| 8033 |
== |
| 8034 |
|
| 8035 |
[case testImplicitOptionalRefresh1] |
| 8036 |
# flags: --implicit-optional |
| 8037 |
from x import f |
| 8038 |
def foo(x: int = None) -> None: |
| 8039 |
f() |
| 8040 |
[file x.py] |
| 8041 |
def f() -> int: return 0 |
| 8042 |
[file x.py.2] |
| 8043 |
def f() -> str: return '0' |
| 8044 |
[out] |
| 8045 |
== |
| 8046 |
|
| 8047 |
[case testRefreshIgnoreErrors1] |
| 8048 |
[file mypy.ini] |
| 8049 |
\[mypy] |
| 8050 |
\[mypy-b] |
| 8051 |
ignore_errors = True |
| 8052 |
[file a.py] |
| 8053 |
y = '1' |
| 8054 |
[file a.py.2] |
| 8055 |
y = 1 |
| 8056 |
[file b.py] |
| 8057 |
from a import y |
| 8058 |
def fu() -> None: |
| 8059 |
1+'lurr' |
| 8060 |
y |
| 8061 |
[out] |
| 8062 |
== |
| 8063 |
|
| 8064 |
[case testRefreshIgnoreErrors2] |
| 8065 |
[file mypy.ini] |
| 8066 |
\[mypy] |
| 8067 |
\[mypy-b] |
| 8068 |
ignore_errors = True |
| 8069 |
[file b.py] |
| 8070 |
def fu() -> int: |
| 8071 |
1+'lurr' |
| 8072 |
return 1 |
| 8073 |
[file b.py.2] |
| 8074 |
def fu() -> int: |
| 8075 |
1+'lurr' |
| 8076 |
return 2 |
| 8077 |
[out] |
| 8078 |
== |
| 8079 |
|
| 8080 |
[case testRefreshOptions] |
| 8081 |
[file mypy.ini] |
| 8082 |
\[mypy] |
| 8083 |
disallow_any_generics = True |
| 8084 |
\[mypy-b] |
| 8085 |
disallow_any_generics = False |
| 8086 |
[file a.py] |
| 8087 |
y = '1' |
| 8088 |
[file a.py.2] |
| 8089 |
y = 1 |
| 8090 |
[file b.py] |
| 8091 |
from typing import List |
| 8092 |
from a import y |
| 8093 |
x = [] # type: List |
| 8094 |
[builtins fixtures/list.pyi] |
| 8095 |
[out] |
| 8096 |
== |
| 8097 |
|
| 8098 |
[case testNamedTupleFallbackModule] |
| 8099 |
import b |
| 8100 |
[file b.py] |
| 8101 |
from a import A |
| 8102 |
def f(a: A): |
| 8103 |
pass |
| 8104 |
[file b.py.2] |
| 8105 |
from a import A |
| 8106 |
def f(a: A): |
| 8107 |
reveal_type(a) |
| 8108 |
[file a.py] |
| 8109 |
from typing import NamedTuple |
| 8110 |
|
| 8111 |
F = [('x', int)] |
| 8112 |
A = NamedTuple('A', F) # type: ignore |
| 8113 |
[builtins fixtures/list.pyi] |
| 8114 |
[out] |
| 8115 |
== |
| 8116 |
b.py:3: note: Revealed type is "tuple[(), fallback=a.A]" |
| 8117 |
|
| 8118 |
[case testImportOnTopOfAlias1] |
| 8119 |
from a import A |
| 8120 |
x: A |
| 8121 |
[file a.py] |
| 8122 |
from typing import TypeVar, List |
| 8123 |
T = TypeVar('T') |
| 8124 |
A = List[T] |
| 8125 |
[file a.py.2] |
| 8126 |
from typing import TypeVar, List |
| 8127 |
T = TypeVar('T') |
| 8128 |
A = List[T] |
| 8129 |
from b import A |
| 8130 |
[file b.py] |
| 8131 |
# empty |
| 8132 |
[builtins fixtures/list.pyi] |
| 8133 |
[out] |
| 8134 |
== |
| 8135 |
a.py:4: error: Module "b" has no attribute "A" |
| 8136 |
a.py:4: error: Name "A" already defined on line 3 |
| 8137 |
|
| 8138 |
-- the order of errors is different with cache |
| 8139 |
[case testImportOnTopOfAlias2] |
| 8140 |
from a import A |
| 8141 |
x: A |
| 8142 |
[file a.py] |
| 8143 |
from typing import TypeVar, List |
| 8144 |
T = TypeVar('T') |
| 8145 |
A = List[T] |
| 8146 |
[file a.py.2] |
| 8147 |
from typing import TypeVar, List |
| 8148 |
T = TypeVar('T') |
| 8149 |
A = List[T] |
| 8150 |
from b import A as A |
| 8151 |
[file b.py] |
| 8152 |
def A(x: str) -> str: pass |
| 8153 |
[builtins fixtures/list.pyi] |
| 8154 |
[out] |
| 8155 |
== |
| 8156 |
a.py:4: error: Incompatible import of "A" (imported name has type "Callable[[str], str]", local name has type "type[list[Any]]") |
| 8157 |
|
| 8158 |
[case testFakeOverloadCrash] |
| 8159 |
import b |
| 8160 |
[file a.py] |
| 8161 |
def dec(fun): |
| 8162 |
pass |
| 8163 |
a = 1 |
| 8164 |
[file a.py.2] |
| 8165 |
def dec(fun): |
| 8166 |
pass |
| 8167 |
a = 2 |
| 8168 |
[file b.py] |
| 8169 |
from a import dec |
| 8170 |
@dec |
| 8171 |
def a(): |
| 8172 |
pass |
| 8173 |
@dec |
| 8174 |
def a(): |
| 8175 |
pass |
| 8176 |
[out] |
| 8177 |
b.py:5: error: Name "a" already defined on line 2 |
| 8178 |
== |
| 8179 |
b.py:5: error: Name "a" already defined on line 2 |
| 8180 |
|
| 8181 |
[case testFakeOverloadCrash2] |
| 8182 |
|
| 8183 |
# this test just should not crash |
| 8184 |
import a |
| 8185 |
[file a.py] |
| 8186 |
T = TypeVar("T") |
| 8187 |
|
| 8188 |
def foo(func): |
| 8189 |
return func |
| 8190 |
|
| 8191 |
@foo |
| 8192 |
def bar(x: T) -> T: |
| 8193 |
pass |
| 8194 |
|
| 8195 |
@foo |
| 8196 |
def bar(x: T) -> T: |
| 8197 |
pass |
| 8198 |
[file a.py.2] |
| 8199 |
T = TypeVar("T") |
| 8200 |
|
| 8201 |
def foo(func): |
| 8202 |
return func |
| 8203 |
|
| 8204 |
@foo |
| 8205 |
def bar(x: T) -> T: |
| 8206 |
pass |
| 8207 |
|
| 8208 |
@foo |
| 8209 |
def bar(x: T) -> T: |
| 8210 |
pass |
| 8211 |
x = 1 |
| 8212 |
[out] |
| 8213 |
a.py:1: error: Name "TypeVar" is not defined |
| 8214 |
a.py:1: note: Did you forget to import it from "typing"? (Suggestion: "from typing import TypeVar") |
| 8215 |
a.py:7: error: Variable "a.T" is not valid as a type |
| 8216 |
a.py:7: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases |
| 8217 |
a.py:10: error: Name "bar" already defined on line 6 |
| 8218 |
a.py:11: error: Variable "a.T" is not valid as a type |
| 8219 |
a.py:11: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases |
| 8220 |
== |
| 8221 |
a.py:1: error: Name "TypeVar" is not defined |
| 8222 |
a.py:1: note: Did you forget to import it from "typing"? (Suggestion: "from typing import TypeVar") |
| 8223 |
a.py:7: error: Variable "a.T" is not valid as a type |
| 8224 |
a.py:7: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases |
| 8225 |
a.py:10: error: Name "bar" already defined on line 6 |
| 8226 |
a.py:11: error: Variable "a.T" is not valid as a type |
| 8227 |
a.py:11: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases |
| 8228 |
|
| 8229 |
[case testRefreshForWithTypeComment1] |
| 8230 |
[file a.py] |
| 8231 |
from typing import List |
| 8232 |
import b |
| 8233 |
def foo(l: List[int]) -> None: |
| 8234 |
for x in l: # type: object |
| 8235 |
pass |
| 8236 |
x = object() |
| 8237 |
b.x |
| 8238 |
[file b.py] |
| 8239 |
x = 1 |
| 8240 |
[file b.py.2] |
| 8241 |
x = '1' |
| 8242 |
[builtins fixtures/list.pyi] |
| 8243 |
[out] |
| 8244 |
== |
| 8245 |
|
| 8246 |
[case testRefreshForWithTypeComment2] |
| 8247 |
from typing import List, Any |
| 8248 |
import m |
| 8249 |
def f(x: List[Any]) -> None: |
| 8250 |
for a in x: # type: m.A |
| 8251 |
pass |
| 8252 |
[file m.py] |
| 8253 |
class A: pass |
| 8254 |
[file m.py.2] |
| 8255 |
[builtins fixtures/list.pyi] |
| 8256 |
[out] |
| 8257 |
== |
| 8258 |
main:4: error: Name "m.A" is not defined |
| 8259 |
|
| 8260 |
[case testIdLikeDecoForwardCrash] |
| 8261 |
import b |
| 8262 |
[file b.py] |
| 8263 |
from typing import Callable, Any, TypeVar |
| 8264 |
|
| 8265 |
F = TypeVar('F_BadName', bound=Callable[..., Any]) # type: ignore |
| 8266 |
def deco(func: F) -> F: # type: ignore |
| 8267 |
pass |
| 8268 |
|
| 8269 |
@deco |
| 8270 |
def test(x: int, y: int) -> str: |
| 8271 |
pass |
| 8272 |
[file b.py.2] |
| 8273 |
from typing import Callable, Any, TypeVar |
| 8274 |
|
| 8275 |
F = TypeVar('F_BadName', bound=Callable[..., Any]) # type: ignore |
| 8276 |
def deco(func: F) -> F: # type: ignore |
| 8277 |
pass |
| 8278 |
|
| 8279 |
@deco |
| 8280 |
def test(x: int, y: int) -> str: |
| 8281 |
pass |
| 8282 |
x = 1 |
| 8283 |
[builtins fixtures/tuple.pyi] |
| 8284 |
[out] |
| 8285 |
== |
| 8286 |
|
| 8287 |
[case testIdLikeDecoForwardCrashAlias] |
| 8288 |
# flags: --disable-error-code used-before-def |
| 8289 |
import b |
| 8290 |
[file b.py] |
| 8291 |
from typing import Callable, Any, TypeVar |
| 8292 |
|
| 8293 |
F = TypeVar('F', bound=Func) |
| 8294 |
def deco(func: F) -> F: |
| 8295 |
pass |
| 8296 |
|
| 8297 |
@deco |
| 8298 |
def test(x: int, y: int) -> str: |
| 8299 |
pass |
| 8300 |
Func = Callable[..., Any] |
| 8301 |
[file b.py.2] |
| 8302 |
from typing import Callable, Any, TypeVar |
| 8303 |
|
| 8304 |
F = TypeVar('F', bound=Func) |
| 8305 |
def deco(func: F) -> F: |
| 8306 |
pass |
| 8307 |
|
| 8308 |
@deco |
| 8309 |
def test(x: int, y: int) -> str: |
| 8310 |
pass |
| 8311 |
x = 1 |
| 8312 |
Func = Callable[..., Any] |
| 8313 |
[out] |
| 8314 |
== |
| 8315 |
|
| 8316 |
-- Test cases for final qualifier |
| 8317 |
|
| 8318 |
[case testFinalAddFinalVarAssignFine] |
| 8319 |
import mod |
| 8320 |
from a import D |
| 8321 |
from mod import x |
| 8322 |
|
| 8323 |
x = 2 |
| 8324 |
def outer() -> None: |
| 8325 |
mod.x = 2 |
| 8326 |
x = 2 # This is OK because it creates a local variable |
| 8327 |
d: D |
| 8328 |
d.y = 2 |
| 8329 |
d.z = 2 |
| 8330 |
D.y = 2 |
| 8331 |
[file a.py] |
| 8332 |
import mod |
| 8333 |
|
| 8334 |
class D(mod.C): |
| 8335 |
pass |
| 8336 |
[file mod.py] |
| 8337 |
x = 1 |
| 8338 |
class C: |
| 8339 |
y = 1 |
| 8340 |
def __init__(self) -> None: |
| 8341 |
self.z = 1 |
| 8342 |
|
| 8343 |
[file mod.py.2] |
| 8344 |
from typing import Final |
| 8345 |
|
| 8346 |
x: Final = 1 |
| 8347 |
class C: |
| 8348 |
y: Final = 1 |
| 8349 |
def __init__(self) -> None: |
| 8350 |
self.z: Final = 1 |
| 8351 |
[out] |
| 8352 |
== |
| 8353 |
main:5: error: Cannot assign to final name "x" |
| 8354 |
main:7: error: Cannot assign to final name "x" |
| 8355 |
main:10: error: Cannot assign to final attribute "y" |
| 8356 |
main:11: error: Cannot assign to final attribute "z" |
| 8357 |
main:12: error: Cannot assign to final attribute "y" |
| 8358 |
|
| 8359 |
[case testFinalAddFinalVarOverrideFine] |
| 8360 |
from mod import C |
| 8361 |
|
| 8362 |
class D(C): |
| 8363 |
x = 2 |
| 8364 |
def __init__(self) -> None: |
| 8365 |
self.y = 2 |
| 8366 |
class E(C): |
| 8367 |
y = 2 |
| 8368 |
def __init__(self) -> None: |
| 8369 |
self.x = 2 |
| 8370 |
|
| 8371 |
[file mod.py] |
| 8372 |
class C: |
| 8373 |
x = 1 |
| 8374 |
def __init__(self) -> None: |
| 8375 |
self.y = 1 |
| 8376 |
|
| 8377 |
[file mod.py.2] |
| 8378 |
from typing import Final |
| 8379 |
|
| 8380 |
class C: |
| 8381 |
x: Final = 1 |
| 8382 |
def __init__(self) -> None: |
| 8383 |
self.y: Final = 1 |
| 8384 |
[out] |
| 8385 |
== |
| 8386 |
main:4: error: Cannot assign to final name "x" |
| 8387 |
main:6: error: Cannot assign to final attribute "y" |
| 8388 |
main:8: error: Cannot assign to final name "y" |
| 8389 |
main:10: error: Cannot assign to final attribute "x" |
| 8390 |
|
| 8391 |
[case testFinalAddFinalMethodOverrideFine] |
| 8392 |
from mod import C |
| 8393 |
|
| 8394 |
class D(C): |
| 8395 |
def meth(self) -> int: ... |
| 8396 |
|
| 8397 |
[file mod.py] |
| 8398 |
class C: |
| 8399 |
def meth(self) -> int: ... |
| 8400 |
|
| 8401 |
[file mod.py.2] |
| 8402 |
from typing import final |
| 8403 |
|
| 8404 |
class C: |
| 8405 |
@final |
| 8406 |
def meth(self) -> int: ... |
| 8407 |
[out] |
| 8408 |
== |
| 8409 |
main:4: error: Cannot override final attribute "meth" (previously declared in base class "C") |
| 8410 |
|
| 8411 |
[case testFinalAddFinalMethodOverrideWithVarFine] |
| 8412 |
from mod import C |
| 8413 |
from typing import Any |
| 8414 |
|
| 8415 |
class D(C): |
| 8416 |
meth: Any = 2 |
| 8417 |
def __init__(self) -> None: |
| 8418 |
self.other: Any = 2 |
| 8419 |
|
| 8420 |
[file mod.py] |
| 8421 |
class C: |
| 8422 |
def meth(self) -> int: ... |
| 8423 |
def other(self) -> int: ... |
| 8424 |
|
| 8425 |
[file mod.py.2] |
| 8426 |
from typing import final |
| 8427 |
|
| 8428 |
class C: |
| 8429 |
@final |
| 8430 |
def meth(self) -> int: ... |
| 8431 |
@final |
| 8432 |
def other(self) -> int: ... |
| 8433 |
[out] |
| 8434 |
== |
| 8435 |
main:5: error: Cannot override final attribute "meth" (previously declared in base class "C") |
| 8436 |
main:7: error: Cannot assign to final attribute "other" |
| 8437 |
main:7: error: Cannot override final attribute "other" (previously declared in base class "C") |
| 8438 |
|
| 8439 |
[case testFinalAddFinalMethodOverrideOverloadFine] |
| 8440 |
from typing import overload |
| 8441 |
from mod import C |
| 8442 |
|
| 8443 |
def outer() -> None: |
| 8444 |
class D(C): |
| 8445 |
@overload |
| 8446 |
def meth(self, x: int) -> int: ... |
| 8447 |
@overload |
| 8448 |
def meth(self, x: str) -> str: ... |
| 8449 |
def meth(self, x): |
| 8450 |
pass |
| 8451 |
|
| 8452 |
[file mod.pyi] |
| 8453 |
from typing import overload |
| 8454 |
class C: |
| 8455 |
@overload |
| 8456 |
def meth(self, x: int) -> int: ... |
| 8457 |
@overload |
| 8458 |
def meth(self, x: str) -> str: ... |
| 8459 |
|
| 8460 |
[file mod.pyi.2] |
| 8461 |
from typing import final, overload |
| 8462 |
|
| 8463 |
class C: |
| 8464 |
@final |
| 8465 |
@overload |
| 8466 |
def meth(self, x: int) -> int: ... |
| 8467 |
@overload |
| 8468 |
def meth(self, x: str) -> str: ... |
| 8469 |
[out] |
| 8470 |
== |
| 8471 |
main:6: error: Cannot override final attribute "meth" (previously declared in base class "C") |
| 8472 |
|
| 8473 |
[case testFinalAddFinalPropertyWithVarFine] |
| 8474 |
from mod import C |
| 8475 |
|
| 8476 |
def outer() -> None: |
| 8477 |
class D(C): |
| 8478 |
p = 2 |
| 8479 |
class E(C): |
| 8480 |
def __init__(self) -> None: |
| 8481 |
self.p: int = 2 |
| 8482 |
|
| 8483 |
[file mod.py] |
| 8484 |
class C: |
| 8485 |
@property |
| 8486 |
def p(self) -> int: |
| 8487 |
pass |
| 8488 |
|
| 8489 |
[file mod.py.2] |
| 8490 |
from typing import final |
| 8491 |
|
| 8492 |
class C: |
| 8493 |
@final |
| 8494 |
@property |
| 8495 |
def p(self) -> int: |
| 8496 |
pass |
| 8497 |
[builtins fixtures/property.pyi] |
| 8498 |
[out] |
| 8499 |
== |
| 8500 |
main:5: error: Cannot override final attribute "p" (previously declared in base class "C") |
| 8501 |
main:8: error: Cannot assign to final attribute "p" |
| 8502 |
main:8: error: Cannot override final attribute "p" (previously declared in base class "C") |
| 8503 |
|
| 8504 |
[case testFinalBodyReprocessedAndStillFinal] |
| 8505 |
import a |
| 8506 |
[file a.py] |
| 8507 |
from c import C |
| 8508 |
class A: |
| 8509 |
def meth(self) -> None: ... |
| 8510 |
|
| 8511 |
[file a.py.3] |
| 8512 |
from c import C |
| 8513 |
class A(C): |
| 8514 |
def meth(self) -> None: ... |
| 8515 |
|
| 8516 |
[file c.py] |
| 8517 |
from typing import final |
| 8518 |
from d import D |
| 8519 |
|
| 8520 |
class C: |
| 8521 |
@final |
| 8522 |
def meth(self) -> None: |
| 8523 |
D(int()) |
| 8524 |
[file d.py] |
| 8525 |
class D: |
| 8526 |
def __init__(self, x: int) -> None: ... |
| 8527 |
[file d.py.2] |
| 8528 |
from typing import Optional |
| 8529 |
class D: |
| 8530 |
def __init__(self, x: Optional[int]) -> None: ... |
| 8531 |
[out] |
| 8532 |
== |
| 8533 |
== |
| 8534 |
a.py:3: error: Cannot override final attribute "meth" (previously declared in base class "C") |
| 8535 |
|
| 8536 |
[case testFinalBodyReprocessedAndStillFinalOverloaded] |
| 8537 |
import a |
| 8538 |
[file a.py] |
| 8539 |
from c import C |
| 8540 |
class A: |
| 8541 |
def meth(self) -> None: ... |
| 8542 |
|
| 8543 |
[file a.py.3] |
| 8544 |
from c import C |
| 8545 |
class A(C): |
| 8546 |
def meth(self) -> None: ... |
| 8547 |
|
| 8548 |
[file c.py] |
| 8549 |
from typing import final, overload, Union |
| 8550 |
from d import D |
| 8551 |
|
| 8552 |
class C: |
| 8553 |
@overload |
| 8554 |
def meth(self, x: int) -> int: ... |
| 8555 |
@overload |
| 8556 |
def meth(self, x: str) -> str: ... |
| 8557 |
@final |
| 8558 |
def meth(self, x: Union[int, str]) -> Union[int, str]: |
| 8559 |
D(int()) |
| 8560 |
return x |
| 8561 |
[file d.py] |
| 8562 |
class D: |
| 8563 |
def __init__(self, x: int) -> None: ... |
| 8564 |
[file d.py.2] |
| 8565 |
from typing import Optional |
| 8566 |
class D: |
| 8567 |
def __init__(self, x: Optional[int]) -> None: ... |
| 8568 |
[out] |
| 8569 |
== |
| 8570 |
== |
| 8571 |
a.py:3: error: Cannot override final attribute "meth" (previously declared in base class "C") |
| 8572 |
a.py:3: error: Signature of "meth" incompatible with supertype "c.C" |
| 8573 |
a.py:3: note: Superclass: |
| 8574 |
a.py:3: note: @overload |
| 8575 |
a.py:3: note: def meth(self, x: int) -> int |
| 8576 |
a.py:3: note: @overload |
| 8577 |
a.py:3: note: def meth(self, x: str) -> str |
| 8578 |
a.py:3: note: Subclass: |
| 8579 |
a.py:3: note: def meth(self) -> None |
| 8580 |
|
| 8581 |
[case testIfMypyUnreachableClass] |
| 8582 |
from a import x |
| 8583 |
|
| 8584 |
MYPY = False |
| 8585 |
if MYPY: |
| 8586 |
pass |
| 8587 |
else: |
| 8588 |
class A: |
| 8589 |
pass |
| 8590 |
y: int = x |
| 8591 |
[file a.py] |
| 8592 |
x = 1 |
| 8593 |
[file a.py.2] |
| 8594 |
x = 2 |
| 8595 |
[builtins fixtures/bool.pyi] |
| 8596 |
[out] |
| 8597 |
== |
| 8598 |
|
| 8599 |
[case testIfTypeCheckingUnreachableClass] |
| 8600 |
from a import x |
| 8601 |
from typing import TYPE_CHECKING |
| 8602 |
|
| 8603 |
if not TYPE_CHECKING: |
| 8604 |
class A(int): |
| 8605 |
pass |
| 8606 |
else: |
| 8607 |
A = int |
| 8608 |
|
| 8609 |
y: A = x |
| 8610 |
[file a.py] |
| 8611 |
x = 1 |
| 8612 |
[file a.py.2] |
| 8613 |
x = 2 |
| 8614 |
[file a.py.3] |
| 8615 |
x = 'no way' |
| 8616 |
[builtins fixtures/bool.pyi] |
| 8617 |
[typing fixtures/typing-medium.pyi] |
| 8618 |
[out] |
| 8619 |
== |
| 8620 |
== |
| 8621 |
main:10: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 8622 |
|
| 8623 |
[case testNamedTupleForwardFunctionDirect] |
| 8624 |
# flags: --ignore-missing-imports |
| 8625 |
from typing import NamedTuple |
| 8626 |
from b import B |
| 8627 |
|
| 8628 |
NT = NamedTuple('NT', [('x', B)]) |
| 8629 |
[file b.py.2] |
| 8630 |
def func(x): pass |
| 8631 |
B = func |
| 8632 |
[builtins fixtures/tuple.pyi] |
| 8633 |
[out] |
| 8634 |
== |
| 8635 |
main:5: error: Variable "b.B" is not valid as a type |
| 8636 |
main:5: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases |
| 8637 |
|
| 8638 |
[case testNamedTupleForwardFunctionIndirect] |
| 8639 |
# flags: --ignore-missing-imports |
| 8640 |
from typing import NamedTuple |
| 8641 |
from a import A |
| 8642 |
|
| 8643 |
NT = NamedTuple('NT', [('x', A)]) |
| 8644 |
[file a.py] |
| 8645 |
from b import B |
| 8646 |
A = B |
| 8647 |
[file b.py.2] |
| 8648 |
def func(x): pass |
| 8649 |
B = func |
| 8650 |
[builtins fixtures/tuple.pyi] |
| 8651 |
[out] |
| 8652 |
== |
| 8653 |
main:5: error: Variable "a.A" is not valid as a type |
| 8654 |
main:5: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases |
| 8655 |
|
| 8656 |
[case testNamedTupleForwardFunctionIndirectReveal] |
| 8657 |
# flags: --ignore-missing-imports |
| 8658 |
import m |
| 8659 |
[file m.py] |
| 8660 |
from typing import NamedTuple |
| 8661 |
from a import A |
| 8662 |
|
| 8663 |
NT = NamedTuple('NT', [('x', A)]) |
| 8664 |
[file m.py.3] |
| 8665 |
from typing import NamedTuple |
| 8666 |
from a import A |
| 8667 |
|
| 8668 |
NT = NamedTuple('NT', [('x', A)]) |
| 8669 |
reveal_type(NT.x) |
| 8670 |
x: NT |
| 8671 |
reveal_type(x.x) |
| 8672 |
[file a.py] |
| 8673 |
from b import B |
| 8674 |
A = B |
| 8675 |
[file b.py.2] |
| 8676 |
def func(x): pass |
| 8677 |
B = func |
| 8678 |
[builtins fixtures/tuple.pyi] |
| 8679 |
[out] |
| 8680 |
== |
| 8681 |
m.py:4: error: Variable "a.A" is not valid as a type |
| 8682 |
m.py:4: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases |
| 8683 |
== |
| 8684 |
m.py:4: error: Variable "a.A" is not valid as a type |
| 8685 |
m.py:4: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases |
| 8686 |
m.py:5: note: Revealed type is "Any" |
| 8687 |
m.py:7: note: Revealed type is "Any" |
| 8688 |
|
| 8689 |
[case testAliasForwardFunctionDirect] |
| 8690 |
# flags: --ignore-missing-imports |
| 8691 |
from typing import Optional |
| 8692 |
from b import B |
| 8693 |
|
| 8694 |
Alias = Optional[B] |
| 8695 |
[file b.py.2] |
| 8696 |
def func(x): pass |
| 8697 |
B = int() |
| 8698 |
[out] |
| 8699 |
== |
| 8700 |
main:5: error: Variable "b.B" is not valid as a type |
| 8701 |
main:5: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases |
| 8702 |
|
| 8703 |
[case testAliasForwardFunctionIndirect] |
| 8704 |
# flags: --ignore-missing-imports |
| 8705 |
from typing import Optional |
| 8706 |
from a import A |
| 8707 |
|
| 8708 |
Alias = Optional[A] |
| 8709 |
[file a.py] |
| 8710 |
from b import B |
| 8711 |
A = B |
| 8712 |
[file b.py.2] |
| 8713 |
def func(x): pass |
| 8714 |
B = func |
| 8715 |
[out] |
| 8716 |
== |
| 8717 |
main:5: error: Variable "a.A" is not valid as a type |
| 8718 |
main:5: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases |
| 8719 |
|
| 8720 |
[case testLiteralFineGrainedVarConversion] |
| 8721 |
import mod |
| 8722 |
reveal_type(mod.x) |
| 8723 |
[file mod.py] |
| 8724 |
x = 1 |
| 8725 |
[file mod.py.2] |
| 8726 |
from typing import Literal |
| 8727 |
x: Literal[1] = 1 |
| 8728 |
[file mod.py.3] |
| 8729 |
from typing import Literal |
| 8730 |
x: Literal[1] = 2 |
| 8731 |
[builtins fixtures/tuple.pyi] |
| 8732 |
[out] |
| 8733 |
main:2: note: Revealed type is "builtins.int" |
| 8734 |
== |
| 8735 |
main:2: note: Revealed type is "Literal[1]" |
| 8736 |
== |
| 8737 |
main:2: note: Revealed type is "Literal[1]" |
| 8738 |
mod.py:2: error: Incompatible types in assignment (expression has type "Literal[2]", variable has type "Literal[1]") |
| 8739 |
|
| 8740 |
[case testLiteralFineGrainedFunctionConversion] |
| 8741 |
from mod import foo |
| 8742 |
foo(3) |
| 8743 |
[file mod.py] |
| 8744 |
def foo(x: int) -> None: pass |
| 8745 |
[file mod.py.2] |
| 8746 |
from typing import Literal |
| 8747 |
def foo(x: Literal[3]) -> None: pass |
| 8748 |
[file mod.py.3] |
| 8749 |
from typing import Literal |
| 8750 |
def foo(x: Literal[4]) -> None: pass |
| 8751 |
[builtins fixtures/tuple.pyi] |
| 8752 |
[out] |
| 8753 |
== |
| 8754 |
== |
| 8755 |
main:2: error: Argument 1 to "foo" has incompatible type "Literal[3]"; expected "Literal[4]" |
| 8756 |
|
| 8757 |
[case testLiteralFineGrainedAlias] |
| 8758 |
from mod import Alias |
| 8759 |
a: Alias = 1 |
| 8760 |
[file mod.py] |
| 8761 |
Alias = int |
| 8762 |
[file mod.py.2] |
| 8763 |
from typing import Literal |
| 8764 |
Alias = Literal[1] |
| 8765 |
[file mod.py.3] |
| 8766 |
from typing import Literal |
| 8767 |
Alias = Literal[2] |
| 8768 |
[builtins fixtures/tuple.pyi] |
| 8769 |
[out] |
| 8770 |
== |
| 8771 |
== |
| 8772 |
main:2: error: Incompatible types in assignment (expression has type "Literal[1]", variable has type "Literal[2]") |
| 8773 |
|
| 8774 |
[case testLiteralFineGrainedOverload] |
| 8775 |
from mod import foo |
| 8776 |
reveal_type(foo(4)) |
| 8777 |
[file mod.py] |
| 8778 |
from typing import Literal, overload |
| 8779 |
@overload |
| 8780 |
def foo(x: int) -> str: ... |
| 8781 |
@overload |
| 8782 |
def foo(x: Literal['bar']) -> int: ... |
| 8783 |
def foo(x): pass |
| 8784 |
[file mod.py.2] |
| 8785 |
from typing import Literal, overload |
| 8786 |
@overload |
| 8787 |
def foo(x: Literal[4]) -> Literal['foo']: ... |
| 8788 |
@overload |
| 8789 |
def foo(x: int) -> str: ... |
| 8790 |
@overload |
| 8791 |
def foo(x: Literal['bar']) -> int: ... |
| 8792 |
def foo(x): pass |
| 8793 |
[builtins fixtures/tuple.pyi] |
| 8794 |
[out] |
| 8795 |
main:2: note: Revealed type is "builtins.str" |
| 8796 |
== |
| 8797 |
main:2: note: Revealed type is "Literal['foo']" |
| 8798 |
|
| 8799 |
[case testLiteralFineGrainedChainedDefinitions] |
| 8800 |
from mod1 import foo |
| 8801 |
from typing import Literal |
| 8802 |
def expect_3(x: Literal[3]) -> None: pass |
| 8803 |
expect_3(foo) |
| 8804 |
[file mod1.py] |
| 8805 |
from mod2 import bar |
| 8806 |
foo = bar |
| 8807 |
[file mod2.py] |
| 8808 |
from mod3 import qux as bar |
| 8809 |
[file mod3.py] |
| 8810 |
from typing import Literal |
| 8811 |
qux: Literal[3] |
| 8812 |
[file mod3.py.2] |
| 8813 |
from typing import Literal |
| 8814 |
qux: Literal[4] |
| 8815 |
[builtins fixtures/tuple.pyi] |
| 8816 |
[out] |
| 8817 |
== |
| 8818 |
main:4: error: Argument 1 to "expect_3" has incompatible type "Literal[4]"; expected "Literal[3]" |
| 8819 |
|
| 8820 |
[case testLiteralFineGrainedChainedAliases] |
| 8821 |
from mod1 import Alias1 |
| 8822 |
from typing import Literal |
| 8823 |
x: Alias1 |
| 8824 |
def expect_3(x: Literal[3]) -> None: pass |
| 8825 |
expect_3(x) |
| 8826 |
[file mod1.py] |
| 8827 |
from mod2 import Alias2 |
| 8828 |
Alias1 = Alias2 |
| 8829 |
[file mod2.py] |
| 8830 |
from mod3 import Alias3 |
| 8831 |
Alias2 = Alias3 |
| 8832 |
[file mod3.py] |
| 8833 |
from typing import Literal |
| 8834 |
Alias3 = Literal[3] |
| 8835 |
[file mod3.py.2] |
| 8836 |
from typing import Literal |
| 8837 |
Alias3 = Literal[4] |
| 8838 |
[builtins fixtures/tuple.pyi] |
| 8839 |
[out] |
| 8840 |
== |
| 8841 |
main:5: error: Argument 1 to "expect_3" has incompatible type "Literal[4]"; expected "Literal[3]" |
| 8842 |
|
| 8843 |
[case testLiteralFineGrainedChainedFunctionDefinitions] |
| 8844 |
from mod1 import func1 |
| 8845 |
from typing import Literal |
| 8846 |
def expect_3(x: Literal[3]) -> None: pass |
| 8847 |
expect_3(func1()) |
| 8848 |
[file mod1.py] |
| 8849 |
from mod2 import func2 as func1 |
| 8850 |
[file mod2.py] |
| 8851 |
from mod3 import func3 |
| 8852 |
func2 = func3 |
| 8853 |
[file mod3.py] |
| 8854 |
from typing import Literal |
| 8855 |
def func3() -> Literal[3]: pass |
| 8856 |
[file mod3.py.2] |
| 8857 |
from typing import Literal |
| 8858 |
def func3() -> Literal[4]: pass |
| 8859 |
[builtins fixtures/tuple.pyi] |
| 8860 |
[out] |
| 8861 |
== |
| 8862 |
main:4: error: Argument 1 to "expect_3" has incompatible type "Literal[4]"; expected "Literal[3]" |
| 8863 |
|
| 8864 |
[case testLiteralFineGrainedChainedTypeVarInference] |
| 8865 |
from mod1 import foo |
| 8866 |
reveal_type(foo) |
| 8867 |
[file mod1.py] |
| 8868 |
from typing import TypeVar |
| 8869 |
from mod2 import bar |
| 8870 |
T = TypeVar('T', bound=int) |
| 8871 |
def func(x: T) -> T: return x |
| 8872 |
foo = func(bar) |
| 8873 |
[file mod2.py] |
| 8874 |
bar = 3 |
| 8875 |
[file mod2.py.2] |
| 8876 |
from typing import Literal |
| 8877 |
bar: Literal[3] = 3 |
| 8878 |
[builtins fixtures/tuple.pyi] |
| 8879 |
[out] |
| 8880 |
main:2: note: Revealed type is "builtins.int" |
| 8881 |
== |
| 8882 |
main:2: note: Revealed type is "Literal[3]" |
| 8883 |
|
| 8884 |
[case testLiteralFineGrainedChainedViaFinal] |
| 8885 |
from mod1 import foo |
| 8886 |
from typing import Literal |
| 8887 |
def expect_3(x: Literal[3]) -> None: pass |
| 8888 |
expect_3(foo) |
| 8889 |
[file mod1.py] |
| 8890 |
from typing import Final |
| 8891 |
from mod2 import bar |
| 8892 |
foo: Final = bar |
| 8893 |
[file mod2.py] |
| 8894 |
from mod3 import qux as bar |
| 8895 |
[file mod3.py] |
| 8896 |
from typing import Final |
| 8897 |
qux: Final = 3 |
| 8898 |
[file mod3.py.2] |
| 8899 |
from typing import Final |
| 8900 |
qux: Final = 4 |
| 8901 |
[file mod3.py.3] |
| 8902 |
from typing import Final |
| 8903 |
qux: Final[int] = 4 |
| 8904 |
[builtins fixtures/tuple.pyi] |
| 8905 |
[out] |
| 8906 |
== |
| 8907 |
main:4: error: Argument 1 to "expect_3" has incompatible type "Literal[4]"; expected "Literal[3]" |
| 8908 |
== |
| 8909 |
main:4: error: Argument 1 to "expect_3" has incompatible type "int"; expected "Literal[3]" |
| 8910 |
|
| 8911 |
[case testLiteralFineGrainedStringConversionPython3] |
| 8912 |
from mod1 import foo |
| 8913 |
reveal_type(foo) |
| 8914 |
[file mod1.py] |
| 8915 |
from mod2 import bar |
| 8916 |
foo = bar() |
| 8917 |
[file mod2.py] |
| 8918 |
from typing import Literal |
| 8919 |
def bar() -> Literal["foo"]: pass |
| 8920 |
[file mod2.py.2] |
| 8921 |
from typing import Literal |
| 8922 |
def bar() -> Literal[u"foo"]: pass |
| 8923 |
[file mod2.py.3] |
| 8924 |
from typing import Literal |
| 8925 |
def bar() -> Literal[b"foo"]: pass |
| 8926 |
[builtins fixtures/tuple.pyi] |
| 8927 |
[out] |
| 8928 |
main:2: note: Revealed type is "Literal['foo']" |
| 8929 |
== |
| 8930 |
main:2: note: Revealed type is "Literal['foo']" |
| 8931 |
== |
| 8932 |
main:2: note: Revealed type is "Literal[b'foo']" |
| 8933 |
|
| 8934 |
[case testReprocessModuleTopLevelWhileMethodDefinesAttr] |
| 8935 |
import a |
| 8936 |
[file a.py] |
| 8937 |
from b import B |
| 8938 |
|
| 8939 |
B().x |
| 8940 |
|
| 8941 |
[file a.py.3] |
| 8942 |
from b import B |
| 8943 |
|
| 8944 |
x = B().x |
| 8945 |
|
| 8946 |
[file b.py] |
| 8947 |
from c import f |
| 8948 |
f(int()) |
| 8949 |
|
| 8950 |
class B: |
| 8951 |
def meth(self) -> None: |
| 8952 |
self.x: int |
| 8953 |
|
| 8954 |
[file c.py] |
| 8955 |
def f(x: int) -> None: ... |
| 8956 |
|
| 8957 |
[file c.py.2] |
| 8958 |
from typing import Union |
| 8959 |
def f(x: Union[int, str]) -> None: ... |
| 8960 |
|
| 8961 |
[targets2 c, b] |
| 8962 |
[targets3 a] |
| 8963 |
[builtins fixtures/tuple.pyi] |
| 8964 |
[out] |
| 8965 |
== |
| 8966 |
== |
| 8967 |
|
| 8968 |
[case testCheckReprocessedTargets-only_when_nocache] |
| 8969 |
from b import B |
| 8970 |
|
| 8971 |
class C(B): |
| 8972 |
def meth(self) -> None: |
| 8973 |
from b import f |
| 8974 |
f() |
| 8975 |
|
| 8976 |
[file b.py] |
| 8977 |
class B: ... |
| 8978 |
def f() -> int: ... |
| 8979 |
|
| 8980 |
[file b.py.2] |
| 8981 |
class A: ... |
| 8982 |
class B(A): ... |
| 8983 |
def f() -> int: ... |
| 8984 |
|
| 8985 |
[file b.py.3] |
| 8986 |
class A: ... |
| 8987 |
class B(A): ... |
| 8988 |
def f() -> str: ... |
| 8989 |
|
| 8990 |
[targets2 b, __main__, __main__.C.meth, __main__, __main__.C.meth] |
| 8991 |
[targets3 b, __main__.C.meth] |
| 8992 |
[out] |
| 8993 |
== |
| 8994 |
== |
| 8995 |
|
| 8996 |
[case testReprocessModuleTopLevelWhileMethodDefinesAttrExplicit] |
| 8997 |
import a |
| 8998 |
[file a.py] |
| 8999 |
from b import B |
| 9000 |
|
| 9001 |
B().x |
| 9002 |
|
| 9003 |
[file b.py] |
| 9004 |
from c import f |
| 9005 |
f(int()) |
| 9006 |
|
| 9007 |
class A: |
| 9008 |
x: int |
| 9009 |
|
| 9010 |
class B(A): |
| 9011 |
def meth(self) -> None: |
| 9012 |
self.x: int |
| 9013 |
|
| 9014 |
[file c.py] |
| 9015 |
def f(x: int) -> None: ... |
| 9016 |
|
| 9017 |
[file c.py.2] |
| 9018 |
from typing import Union |
| 9019 |
def f(x: Union[int, str]) -> None: ... |
| 9020 |
|
| 9021 |
[file a.py.3] |
| 9022 |
from b import B |
| 9023 |
|
| 9024 |
# Double-check the variable is still accessible. |
| 9025 |
B().x |
| 9026 |
|
| 9027 |
[targets2 c, b] |
| 9028 |
[targets3 a] |
| 9029 |
[builtins fixtures/tuple.pyi] |
| 9030 |
[out] |
| 9031 |
== |
| 9032 |
== |
| 9033 |
|
| 9034 |
[case testReprocessModuleTopLevelWhileMethodDefinesAttrBothExplicitAndInClass] |
| 9035 |
import a |
| 9036 |
[file a.py] |
| 9037 |
from b import B |
| 9038 |
|
| 9039 |
B().x |
| 9040 |
|
| 9041 |
[file b.py] |
| 9042 |
from c import f |
| 9043 |
f(int()) |
| 9044 |
|
| 9045 |
class A: |
| 9046 |
x: int |
| 9047 |
|
| 9048 |
class B(A): |
| 9049 |
x: int |
| 9050 |
def meth(self) -> None: |
| 9051 |
self.x: int |
| 9052 |
|
| 9053 |
[file c.py] |
| 9054 |
def f(x: int) -> None: ... |
| 9055 |
|
| 9056 |
[file c.py.2] |
| 9057 |
from typing import Union |
| 9058 |
def f(x: Union[int, str]) -> None: ... |
| 9059 |
|
| 9060 |
[file a.py.3] |
| 9061 |
from b import B |
| 9062 |
|
| 9063 |
# Double-check the variable is still accessible. |
| 9064 |
B().x |
| 9065 |
|
| 9066 |
[targets2 c, b] |
| 9067 |
[targets3 a] |
| 9068 |
[builtins fixtures/tuple.pyi] |
| 9069 |
[out] |
| 9070 |
== |
| 9071 |
== |
| 9072 |
|
| 9073 |
[case testReprocessModuleTopLevelWhileMethodDefinesAttrProtocol] |
| 9074 |
import a |
| 9075 |
[file a.py] |
| 9076 |
from b import B |
| 9077 |
|
| 9078 |
B().x |
| 9079 |
|
| 9080 |
[file b.py] |
| 9081 |
from typing import Protocol |
| 9082 |
from c import f |
| 9083 |
f(int()) |
| 9084 |
|
| 9085 |
class A(Protocol): |
| 9086 |
x: int |
| 9087 |
|
| 9088 |
class B(A): |
| 9089 |
def meth(self) -> None: |
| 9090 |
self.x = 42 |
| 9091 |
|
| 9092 |
[file c.py] |
| 9093 |
def f(x: int) -> None: ... |
| 9094 |
|
| 9095 |
[file c.py.2] |
| 9096 |
from typing import Union |
| 9097 |
def f(x: Union[int, str]) -> None: ... |
| 9098 |
|
| 9099 |
[file a.py.3] |
| 9100 |
from b import B |
| 9101 |
|
| 9102 |
# Double-check the variable is still accessible. |
| 9103 |
B().x |
| 9104 |
|
| 9105 |
[targets2 c, b] |
| 9106 |
[targets3 a] |
| 9107 |
[out] |
| 9108 |
== |
| 9109 |
== |
| 9110 |
|
| 9111 |
[case testNewSemanticAnalyzerUpdateMethodAndClass] |
| 9112 |
|
| 9113 |
import m |
| 9114 |
|
| 9115 |
m.x |
| 9116 |
|
| 9117 |
class A: |
| 9118 |
def f(self) -> None: |
| 9119 |
self.x = 0 |
| 9120 |
m.y |
| 9121 |
|
| 9122 |
def g(self) -> None: |
| 9123 |
m.x |
| 9124 |
|
| 9125 |
[file m.py] |
| 9126 |
x = 0 |
| 9127 |
y = 0 |
| 9128 |
|
| 9129 |
[file m.py.2] |
| 9130 |
x = '' |
| 9131 |
y = 0 |
| 9132 |
|
| 9133 |
[file m.py.3] |
| 9134 |
x = '' |
| 9135 |
y = '' |
| 9136 |
|
| 9137 |
[out] |
| 9138 |
== |
| 9139 |
== |
| 9140 |
|
| 9141 |
[case testInlineConfigFineGrained1] |
| 9142 |
|
| 9143 |
import a |
| 9144 |
[file a.py] |
| 9145 |
# mypy: no-warn-no-return |
| 9146 |
|
| 9147 |
from typing import List, Optional |
| 9148 |
def foo() -> Optional[List]: |
| 9149 |
20 |
| 9150 |
|
| 9151 |
[file a.py.2] |
| 9152 |
# mypy: disallow-any-generics, no-warn-no-return |
| 9153 |
|
| 9154 |
from typing import List, Optional |
| 9155 |
def foo() -> Optional[List]: |
| 9156 |
20 |
| 9157 |
|
| 9158 |
[file a.py.3] |
| 9159 |
# mypy: no-warn-no-return |
| 9160 |
|
| 9161 |
from typing import List, Optional |
| 9162 |
def foo() -> Optional[List]: |
| 9163 |
20 |
| 9164 |
|
| 9165 |
[file a.py.4] |
| 9166 |
from typing import List, Optional |
| 9167 |
def foo() -> Optional[List]: |
| 9168 |
20 |
| 9169 |
[out] |
| 9170 |
== |
| 9171 |
a.py:4: error: Missing type arguments for generic type "List" |
| 9172 |
== |
| 9173 |
== |
| 9174 |
a.py:2: error: Missing return statement |
| 9175 |
|
| 9176 |
[builtins fixtures/list.pyi] |
| 9177 |
|
| 9178 |
[case testInlineConfigFineGrained2] |
| 9179 |
import a |
| 9180 |
[file a.py] |
| 9181 |
# mypy: bogus-flag |
| 9182 |
|
| 9183 |
[file b.py.2] |
| 9184 |
|
| 9185 |
[out] |
| 9186 |
a.py:1: error: Unrecognized option: bogus_flag = True |
| 9187 |
== |
| 9188 |
a.py:1: error: Unrecognized option: bogus_flag = True |
| 9189 |
|
| 9190 |
[case testWrongNumberOfArguments] |
| 9191 |
|
| 9192 |
[file a.py] |
| 9193 |
def bar(x): |
| 9194 |
# type: () -> None |
| 9195 |
pass |
| 9196 |
|
| 9197 |
def baz(x): |
| 9198 |
# type: () -> None |
| 9199 |
pass |
| 9200 |
|
| 9201 |
def f(): |
| 9202 |
# type: () -> None |
| 9203 |
def g(x): |
| 9204 |
# type: () -> None |
| 9205 |
pass |
| 9206 |
|
| 9207 |
[file c.py] |
| 9208 |
def bar(x): |
| 9209 |
# type: () -> None |
| 9210 |
pass |
| 9211 |
|
| 9212 |
[file b.py] |
| 9213 |
x = '' |
| 9214 |
|
| 9215 |
[file b.py.2] |
| 9216 |
x = 1 |
| 9217 |
|
| 9218 |
[out] |
| 9219 |
c.py:1: error: Type signature has too few parameters |
| 9220 |
a.py:1: error: Type signature has too few parameters |
| 9221 |
a.py:5: error: Type signature has too few parameters |
| 9222 |
a.py:11: error: Type signature has too few parameters |
| 9223 |
== |
| 9224 |
c.py:1: error: Type signature has too few parameters |
| 9225 |
a.py:1: error: Type signature has too few parameters |
| 9226 |
a.py:5: error: Type signature has too few parameters |
| 9227 |
a.py:11: error: Type signature has too few parameters |
| 9228 |
|
| 9229 |
[case testErrorReportingNewAnalyzer] |
| 9230 |
# flags: --disallow-any-generics |
| 9231 |
from a import A |
| 9232 |
|
| 9233 |
def f() -> None: |
| 9234 |
x: A |
| 9235 |
[file a.py] |
| 9236 |
class A: ... |
| 9237 |
|
| 9238 |
[file a.py.2] |
| 9239 |
from typing import TypeVar, Generic |
| 9240 |
T = TypeVar('T') |
| 9241 |
class A(Generic[T]): ... |
| 9242 |
[out] |
| 9243 |
== |
| 9244 |
main:5: error: Missing type arguments for generic type "A" |
| 9245 |
|
| 9246 |
[case testStripNewAnalyzer] |
| 9247 |
# flags: --ignore-missing-imports |
| 9248 |
import a |
| 9249 |
[file a.py] |
| 9250 |
from typing import List |
| 9251 |
from b import B |
| 9252 |
|
| 9253 |
class A: |
| 9254 |
def __init__(self) -> None: |
| 9255 |
self.x: List[int] = [] |
| 9256 |
|
| 9257 |
def method(self) -> None: |
| 9258 |
B() |
| 9259 |
self.x = [] |
| 9260 |
|
| 9261 |
[file b.py] |
| 9262 |
class B: ... |
| 9263 |
[delete b.py.2] |
| 9264 |
|
| 9265 |
[builtins fixtures/list.pyi] |
| 9266 |
[out] |
| 9267 |
== |
| 9268 |
|
| 9269 |
[case testClassVariableOrderingRefresh] |
| 9270 |
|
| 9271 |
from b import bar |
| 9272 |
|
| 9273 |
def foo(x: str) -> None: pass |
| 9274 |
|
| 9275 |
class Something: |
| 9276 |
def run(self) -> None: |
| 9277 |
bar() |
| 9278 |
foo(self.IDS[0]) |
| 9279 |
|
| 9280 |
IDS = [87] |
| 9281 |
|
| 9282 |
[file b.py] |
| 9283 |
def bar() -> int: return 0 |
| 9284 |
[file b.py.2] |
| 9285 |
def bar() -> str: return '0' |
| 9286 |
[builtins fixtures/list.pyi] |
| 9287 |
[out] |
| 9288 |
main:9: error: Argument 1 to "foo" has incompatible type "int"; expected "str" |
| 9289 |
== |
| 9290 |
main:9: error: Argument 1 to "foo" has incompatible type "int"; expected "str" |
| 9291 |
|
| 9292 |
[case testInfiniteLoop] |
| 9293 |
|
| 9294 |
[file a.py] |
| 9295 |
from b import f |
| 9296 |
from typing import Callable, TypeVar |
| 9297 |
|
| 9298 |
F = TypeVar('F', bound=Callable) |
| 9299 |
def dec(x: F) -> F: return x |
| 9300 |
|
| 9301 |
@dec |
| 9302 |
def foo(self): |
| 9303 |
class A: |
| 9304 |
@classmethod |
| 9305 |
def asdf(cls, x: 'A') -> None: pass |
| 9306 |
|
| 9307 |
@dec |
| 9308 |
def bar(self): |
| 9309 |
class B: |
| 9310 |
@classmethod |
| 9311 |
def asdf(cls, x: 'B') -> None: pass |
| 9312 |
f() |
| 9313 |
|
| 9314 |
[file b.py] |
| 9315 |
def f() -> int: pass |
| 9316 |
[file b.py.2] |
| 9317 |
def f() -> str: pass |
| 9318 |
[builtins fixtures/classmethod.pyi] |
| 9319 |
[out] |
| 9320 |
== |
| 9321 |
|
| 9322 |
[case testInfiniteLoop2] |
| 9323 |
|
| 9324 |
[file a.py] |
| 9325 |
from b import f |
| 9326 |
from typing import Callable, TypeVar, NamedTuple |
| 9327 |
|
| 9328 |
F = TypeVar('F', bound=Callable) |
| 9329 |
def dec(x: F) -> F: return x |
| 9330 |
|
| 9331 |
@dec |
| 9332 |
def foo(self): |
| 9333 |
N = NamedTuple('N', [('x', int)]) |
| 9334 |
def g(x: N) -> None: pass |
| 9335 |
|
| 9336 |
@dec |
| 9337 |
def bar(self): |
| 9338 |
N = NamedTuple('N', [('x', int)]) |
| 9339 |
def g(x: N) -> None: pass |
| 9340 |
f() |
| 9341 |
|
| 9342 |
[file b.py] |
| 9343 |
def f() -> int: pass |
| 9344 |
[file b.py.2] |
| 9345 |
def f() -> str: pass |
| 9346 |
[builtins fixtures/classmethod.pyi] |
| 9347 |
[out] |
| 9348 |
== |
| 9349 |
|
| 9350 |
[case testFileAddedAndImported] |
| 9351 |
# flags: --ignore-missing-imports --follow-imports=skip |
| 9352 |
# cmd: mypy a.py |
| 9353 |
# cmd2: mypy a.py b.py |
| 9354 |
|
| 9355 |
[file a.py] |
| 9356 |
from b import bad |
| 9357 |
x = 42 |
| 9358 |
|
| 9359 |
[file b.py.2] |
| 9360 |
def good() -> None: ... |
| 9361 |
[out] |
| 9362 |
== |
| 9363 |
a.py:1: error: Module "b" has no attribute "bad" |
| 9364 |
|
| 9365 |
[case testFileAddedAndImported2] |
| 9366 |
# flags: --ignore-missing-imports --follow-imports=skip |
| 9367 |
# cmd: mypy -m a |
| 9368 |
# cmd2: mypy -m a b |
| 9369 |
[file a.py] |
| 9370 |
x = 42 |
| 9371 |
|
| 9372 |
[file a.py.2] |
| 9373 |
from b import bad |
| 9374 |
x = 42 |
| 9375 |
|
| 9376 |
[file b.py.2] |
| 9377 |
def good() -> None: ... |
| 9378 |
[out] |
| 9379 |
== |
| 9380 |
a.py:1: error: Module "b" has no attribute "bad" |
| 9381 |
|
| 9382 |
[case testTypedDictCrashFallbackAfterDeletedMeet] |
| 9383 |
# flags: --ignore-missing-imports |
| 9384 |
|
| 9385 |
from z import get_data |
| 9386 |
from a import Data |
| 9387 |
|
| 9388 |
for it in get_data()['things']: |
| 9389 |
it['id'] |
| 9390 |
|
| 9391 |
[file z.py] |
| 9392 |
from a import Data |
| 9393 |
|
| 9394 |
def get_data() -> Data: ... |
| 9395 |
|
| 9396 |
[file a.py] |
| 9397 |
from typing import TypedDict, List, Union |
| 9398 |
|
| 9399 |
class File(TypedDict): |
| 9400 |
id: int |
| 9401 |
name: str |
| 9402 |
|
| 9403 |
class User(TypedDict): |
| 9404 |
id: int |
| 9405 |
path: str |
| 9406 |
|
| 9407 |
class Data(TypedDict): |
| 9408 |
things: List[Union[File, User]] |
| 9409 |
|
| 9410 |
[delete a.py.2] |
| 9411 |
[builtins fixtures/dict.pyi] |
| 9412 |
[typing fixtures/typing-typeddict.pyi] |
| 9413 |
[out] |
| 9414 |
== |
| 9415 |
|
| 9416 |
[case testTypedDictCrashFallbackAfterDeletedJoin] |
| 9417 |
# flags: --ignore-missing-imports |
| 9418 |
|
| 9419 |
from z import get_data |
| 9420 |
from a import Data |
| 9421 |
|
| 9422 |
x = [get_data()[0], get_data()[1]] |
| 9423 |
|
| 9424 |
[file z.py] |
| 9425 |
from a import Data |
| 9426 |
|
| 9427 |
def get_data() -> Data: ... |
| 9428 |
|
| 9429 |
[file a.py] |
| 9430 |
from typing import TypedDict, Tuple |
| 9431 |
|
| 9432 |
class File(TypedDict): |
| 9433 |
id: int |
| 9434 |
name: str |
| 9435 |
|
| 9436 |
class User(TypedDict): |
| 9437 |
id: int |
| 9438 |
path: str |
| 9439 |
|
| 9440 |
Data = Tuple[User, File] |
| 9441 |
|
| 9442 |
[delete a.py.2] |
| 9443 |
[builtins fixtures/dict.pyi] |
| 9444 |
[typing fixtures/typing-typeddict.pyi] |
| 9445 |
[out] |
| 9446 |
== |
| 9447 |
|
| 9448 |
[case testClassRedef] |
| 9449 |
# An issue involved serializing these caused crashes in the past |
| 9450 |
|
| 9451 |
[file a.py] |
| 9452 |
class A: |
| 9453 |
pass |
| 9454 |
|
| 9455 |
x = 0 |
| 9456 |
|
| 9457 |
[file a.py.2] |
| 9458 |
class A: |
| 9459 |
a = A() |
| 9460 |
|
| 9461 |
x = '0' |
| 9462 |
|
| 9463 |
[file b.py] |
| 9464 |
from a import A, x |
| 9465 |
|
| 9466 |
class A: # type: ignore |
| 9467 |
pass |
| 9468 |
|
| 9469 |
[out] |
| 9470 |
== |
| 9471 |
|
| 9472 |
[case testAddAttributeThroughNewBaseClass] |
| 9473 |
import a |
| 9474 |
|
| 9475 |
[file a.py] |
| 9476 |
class C: |
| 9477 |
def __init__(self) -> None: |
| 9478 |
self.x = 0 |
| 9479 |
|
| 9480 |
[file a.py.2] |
| 9481 |
from b import B |
| 9482 |
|
| 9483 |
class C(B): |
| 9484 |
def __init__(self) -> None: |
| 9485 |
self.x = 0 |
| 9486 |
|
| 9487 |
[file b.py.2] |
| 9488 |
class B: |
| 9489 |
def __init__(self) -> None: |
| 9490 |
self.x = 0 |
| 9491 |
[out] |
| 9492 |
== |
| 9493 |
|
| 9494 |
[case testGenericChange1] |
| 9495 |
import a |
| 9496 |
[file a.py] |
| 9497 |
import b |
| 9498 |
def f() -> b.C: pass |
| 9499 |
[file b.py] |
| 9500 |
import a |
| 9501 |
class C: pass |
| 9502 |
[file b.py.2] |
| 9503 |
from typing import TypeVar, Generic, List |
| 9504 |
import a |
| 9505 |
|
| 9506 |
T = TypeVar('T') |
| 9507 |
class C(Generic[T]): pass |
| 9508 |
|
| 9509 |
reveal_type(a.f) |
| 9510 |
c: C[int] |
| 9511 |
l = a.f() if True else c |
| 9512 |
d = a.f() |
| 9513 |
d = c |
| 9514 |
c = d |
| 9515 |
|
| 9516 |
x: List[C] = [a.f(), a.f()] |
| 9517 |
|
| 9518 |
[out] |
| 9519 |
== |
| 9520 |
b.py:7: note: Revealed type is "def () -> b.C[Any]" |
| 9521 |
[builtins fixtures/list.pyi] |
| 9522 |
|
| 9523 |
[case testGenericChange2] |
| 9524 |
import a |
| 9525 |
[file a.py] |
| 9526 |
import b |
| 9527 |
def f() -> b.C[int]: pass |
| 9528 |
[file b.py] |
| 9529 |
from typing import TypeVar, Generic |
| 9530 |
import a |
| 9531 |
T = TypeVar('T') |
| 9532 |
class C(Generic[T]): pass |
| 9533 |
[file b.py.2] |
| 9534 |
from typing import List |
| 9535 |
import a |
| 9536 |
|
| 9537 |
class C(): pass |
| 9538 |
|
| 9539 |
c: C |
| 9540 |
l = a.f() if True else c |
| 9541 |
d = a.f() |
| 9542 |
d = c |
| 9543 |
c = d |
| 9544 |
|
| 9545 |
x: List[C] = [a.f(), a.f()] |
| 9546 |
|
| 9547 |
[builtins fixtures/list.pyi] |
| 9548 |
[out] |
| 9549 |
== |
| 9550 |
a.py:2: error: "C" expects no type arguments, but 1 given |
| 9551 |
|
| 9552 |
[case testGenericChange3] |
| 9553 |
import a |
| 9554 |
[file a.py] |
| 9555 |
import b |
| 9556 |
def f() -> b.C[int]: pass |
| 9557 |
[file b.py] |
| 9558 |
from typing import TypeVar, Generic |
| 9559 |
import a |
| 9560 |
T = TypeVar('T') |
| 9561 |
class C(Generic[T]): pass |
| 9562 |
[file b.py.2] |
| 9563 |
from typing import TypeVar, Generic, List |
| 9564 |
import a |
| 9565 |
|
| 9566 |
T = TypeVar('T') |
| 9567 |
S = TypeVar('S') |
| 9568 |
class C(Generic[S, T]): pass |
| 9569 |
|
| 9570 |
c: C[int, str] |
| 9571 |
l = a.f() if True else c |
| 9572 |
d = a.f() |
| 9573 |
d = c |
| 9574 |
c = d |
| 9575 |
|
| 9576 |
x: List[C] = [a.f(), a.f()] |
| 9577 |
|
| 9578 |
[out] |
| 9579 |
== |
| 9580 |
a.py:2: error: "C" expects 2 type arguments, but 1 given |
| 9581 |
[builtins fixtures/list.pyi] |
| 9582 |
|
| 9583 |
[case testIsInstanceAdHocIntersectionFineGrainedIncrementalNoChange] |
| 9584 |
import b |
| 9585 |
[file a.py] |
| 9586 |
class A: pass |
| 9587 |
class B: pass |
| 9588 |
|
| 9589 |
class Foo: |
| 9590 |
def __init__(self) -> None: |
| 9591 |
x: A |
| 9592 |
assert isinstance(x, B) |
| 9593 |
self.x = x |
| 9594 |
[file b.py] |
| 9595 |
from a import Foo |
| 9596 |
[file b.py.2] |
| 9597 |
from a import Foo |
| 9598 |
reveal_type(Foo().x) |
| 9599 |
[builtins fixtures/isinstance.pyi] |
| 9600 |
[out] |
| 9601 |
== |
| 9602 |
b.py:2: note: Revealed type is "a.<subclass of "a.A" and "a.B">" |
| 9603 |
|
| 9604 |
[case testIsInstanceAdHocIntersectionFineGrainedIncrementalIsInstanceChange] |
| 9605 |
import c |
| 9606 |
[file a.py] |
| 9607 |
class A: pass |
| 9608 |
class B: pass |
| 9609 |
class C: pass |
| 9610 |
|
| 9611 |
class Foo: |
| 9612 |
def __init__(self) -> None: |
| 9613 |
x: A |
| 9614 |
assert isinstance(x, B) |
| 9615 |
self.x = x |
| 9616 |
[file a.py.2] |
| 9617 |
class A: pass |
| 9618 |
class B: pass |
| 9619 |
class C: pass |
| 9620 |
|
| 9621 |
class Foo: |
| 9622 |
def __init__(self) -> None: |
| 9623 |
x: A |
| 9624 |
assert isinstance(x, C) |
| 9625 |
self.x = x |
| 9626 |
|
| 9627 |
[file b.py] |
| 9628 |
from a import Foo |
| 9629 |
y = Foo().x |
| 9630 |
|
| 9631 |
[file c.py] |
| 9632 |
from b import y |
| 9633 |
reveal_type(y) |
| 9634 |
[builtins fixtures/isinstance.pyi] |
| 9635 |
[out] |
| 9636 |
c.py:2: note: Revealed type is "a.<subclass of "a.A" and "a.B">" |
| 9637 |
== |
| 9638 |
c.py:2: note: Revealed type is "a.<subclass of "a.A" and "a.C">" |
| 9639 |
|
| 9640 |
[case testIsInstanceAdHocIntersectionFineGrainedIncrementalUnderlyingObjChang] |
| 9641 |
import c |
| 9642 |
[file a.py] |
| 9643 |
class A: pass |
| 9644 |
class B: pass |
| 9645 |
class C: pass |
| 9646 |
Extra = B |
| 9647 |
[file a.py.2] |
| 9648 |
class A: pass |
| 9649 |
class B: pass |
| 9650 |
class C: pass |
| 9651 |
Extra = C |
| 9652 |
|
| 9653 |
[file b.py] |
| 9654 |
from a import A, Extra |
| 9655 |
x: A |
| 9656 |
if isinstance(x, Extra): |
| 9657 |
y = x |
| 9658 |
|
| 9659 |
[file c.py] |
| 9660 |
from b import y |
| 9661 |
reveal_type(y) |
| 9662 |
[builtins fixtures/isinstance.pyi] |
| 9663 |
[out] |
| 9664 |
c.py:2: note: Revealed type is "b.<subclass of "a.A" and "a.B">" |
| 9665 |
== |
| 9666 |
c.py:2: note: Revealed type is "b.<subclass of "a.A" and "a.C">" |
| 9667 |
|
| 9668 |
[case testIsInstanceAdHocIntersectionFineGrainedIncrementalIntersectionToUnreachable] |
| 9669 |
import c |
| 9670 |
[file a.py] |
| 9671 |
class A: |
| 9672 |
x: int |
| 9673 |
class B: |
| 9674 |
x: int |
| 9675 |
x: A |
| 9676 |
assert isinstance(x, B) |
| 9677 |
y = x |
| 9678 |
|
| 9679 |
[file a.py.2] |
| 9680 |
class A: |
| 9681 |
x: int |
| 9682 |
class B: |
| 9683 |
x: str |
| 9684 |
x: A |
| 9685 |
assert isinstance(x, B) |
| 9686 |
y = x |
| 9687 |
|
| 9688 |
[file b.py] |
| 9689 |
from a import y |
| 9690 |
z = y |
| 9691 |
|
| 9692 |
[file c.py] |
| 9693 |
from b import z |
| 9694 |
reveal_type(z) |
| 9695 |
[builtins fixtures/isinstance.pyi] |
| 9696 |
[out] |
| 9697 |
c.py:2: note: Revealed type is "a.<subclass of "a.A" and "a.B">" |
| 9698 |
== |
| 9699 |
c.py:2: note: Revealed type is "Any" |
| 9700 |
b.py:2: error: Cannot determine type of "y" |
| 9701 |
|
| 9702 |
[case testIsInstanceAdHocIntersectionFineGrainedIncrementalUnreachaableToIntersection] |
| 9703 |
import c |
| 9704 |
[file a.py] |
| 9705 |
class A: |
| 9706 |
x: int |
| 9707 |
class B: |
| 9708 |
x: str |
| 9709 |
x: A |
| 9710 |
assert isinstance(x, B) |
| 9711 |
y = x |
| 9712 |
|
| 9713 |
[file a.py.2] |
| 9714 |
class A: |
| 9715 |
x: int |
| 9716 |
class B: |
| 9717 |
x: int |
| 9718 |
x: A |
| 9719 |
assert isinstance(x, B) |
| 9720 |
y = x |
| 9721 |
|
| 9722 |
[file b.py] |
| 9723 |
from a import y |
| 9724 |
z = y |
| 9725 |
|
| 9726 |
[file c.py] |
| 9727 |
from b import z |
| 9728 |
reveal_type(z) |
| 9729 |
[builtins fixtures/isinstance.pyi] |
| 9730 |
[out] |
| 9731 |
b.py:2: error: Cannot determine type of "y" |
| 9732 |
c.py:2: note: Revealed type is "Any" |
| 9733 |
== |
| 9734 |
c.py:2: note: Revealed type is "a.<subclass of "a.A" and "a.B">" |
| 9735 |
|
| 9736 |
[case testStubFixupIssues] |
| 9737 |
[file a.py] |
| 9738 |
import p |
| 9739 |
[file a.py.2] |
| 9740 |
import p |
| 9741 |
# a change |
| 9742 |
|
| 9743 |
[file p/__init__.pyi] |
| 9744 |
from p.util import * |
| 9745 |
|
| 9746 |
[file p/util.pyi] |
| 9747 |
from p.params import N |
| 9748 |
class Test: ... |
| 9749 |
|
| 9750 |
[file p/params.pyi] |
| 9751 |
import p.util |
| 9752 |
class N(p.util.Test): |
| 9753 |
... |
| 9754 |
|
| 9755 |
[builtins fixtures/list.pyi] |
| 9756 |
[out] |
| 9757 |
== |
| 9758 |
|
| 9759 |
[case testDunderCall1] |
| 9760 |
from a import C |
| 9761 |
|
| 9762 |
c = C() |
| 9763 |
c(1) |
| 9764 |
|
| 9765 |
[file a.py] |
| 9766 |
class C: |
| 9767 |
def __call__(self, x: int) -> None: ... |
| 9768 |
|
| 9769 |
[file a.py.2] |
| 9770 |
class C: |
| 9771 |
def __call__(self, x: str) -> None: ... |
| 9772 |
|
| 9773 |
[out] |
| 9774 |
== |
| 9775 |
main:4: error: Argument 1 to "__call__" of "C" has incompatible type "int"; expected "str" |
| 9776 |
|
| 9777 |
[case testDunderCall2] |
| 9778 |
from a import C |
| 9779 |
|
| 9780 |
C()(1) |
| 9781 |
|
| 9782 |
[file a.py] |
| 9783 |
class C: |
| 9784 |
def __call__(self, x: int) -> None: ... |
| 9785 |
|
| 9786 |
[file a.py.2] |
| 9787 |
class C: |
| 9788 |
def __call__(self, x: str) -> None: ... |
| 9789 |
|
| 9790 |
[out] |
| 9791 |
== |
| 9792 |
main:3: error: Argument 1 to "__call__" of "C" has incompatible type "int"; expected "str" |
| 9793 |
|
| 9794 |
[case testDunderCallAddition] |
| 9795 |
from a import C |
| 9796 |
|
| 9797 |
c = C() |
| 9798 |
x = c() # type: ignore |
| 9799 |
x + 42 |
| 9800 |
|
| 9801 |
[file a.py] |
| 9802 |
class C: ... |
| 9803 |
|
| 9804 |
[file a.py.2] |
| 9805 |
class C: |
| 9806 |
def __call__(self) -> str: ... |
| 9807 |
|
| 9808 |
[out] |
| 9809 |
== |
| 9810 |
main:5: error: Unsupported left operand type for + ("str") |
| 9811 |
|
| 9812 |
[case testNoneAttribute] |
| 9813 |
from typing import Generic, TypeVar |
| 9814 |
|
| 9815 |
T = TypeVar('T', int, str) |
| 9816 |
|
| 9817 |
class ExampleClass(Generic[T]): |
| 9818 |
def __init__( |
| 9819 |
self |
| 9820 |
) -> None: |
| 9821 |
self.example_attribute = None |
| 9822 |
[out] |
| 9823 |
== |
| 9824 |
[case testStrictNoneAttribute] |
| 9825 |
from typing import Generic, TypeVar |
| 9826 |
|
| 9827 |
T = TypeVar('T', int, str) |
| 9828 |
|
| 9829 |
class ExampleClass(Generic[T]): |
| 9830 |
def __init__( |
| 9831 |
self |
| 9832 |
) -> None: |
| 9833 |
self.example_attribute = None |
| 9834 |
[out] |
| 9835 |
== |
| 9836 |
|
| 9837 |
[case testDataclassCheckTypeVarBoundsInReprocess] |
| 9838 |
from dataclasses import dataclass |
| 9839 |
from typing import ClassVar, Protocol, Dict, TypeVar, Generic |
| 9840 |
from m import x |
| 9841 |
|
| 9842 |
class DataclassProtocol(Protocol): |
| 9843 |
__dataclass_fields__: ClassVar[Dict] |
| 9844 |
|
| 9845 |
T = TypeVar("T", bound=DataclassProtocol) |
| 9846 |
|
| 9847 |
@dataclass |
| 9848 |
class MyDataclass: |
| 9849 |
x: int = 1 |
| 9850 |
|
| 9851 |
class MyGeneric(Generic[T]): ... |
| 9852 |
class MyClass(MyGeneric[MyDataclass]): ... |
| 9853 |
|
| 9854 |
[file m.py] |
| 9855 |
x: int |
| 9856 |
[file m.py.2] |
| 9857 |
x: str |
| 9858 |
|
| 9859 |
[builtins fixtures/dataclasses.pyi] |
| 9860 |
[out] |
| 9861 |
== |
| 9862 |
|
| 9863 |
[case testParamSpecCached] |
| 9864 |
import a |
| 9865 |
|
| 9866 |
[file a.py] |
| 9867 |
import b |
| 9868 |
|
| 9869 |
def f(x: int) -> str: return 'x' |
| 9870 |
|
| 9871 |
b.foo(f) |
| 9872 |
|
| 9873 |
[file a.py.2] |
| 9874 |
import b |
| 9875 |
|
| 9876 |
def f(x: int) -> str: return 'x' |
| 9877 |
|
| 9878 |
reveal_type(b.foo(f)) |
| 9879 |
|
| 9880 |
[file b.py] |
| 9881 |
from typing import TypeVar, Callable, Union |
| 9882 |
from typing_extensions import ParamSpec |
| 9883 |
|
| 9884 |
P = ParamSpec("P") |
| 9885 |
T = TypeVar("T") |
| 9886 |
|
| 9887 |
def foo(f: Callable[P, T]) -> Callable[P, Union[T, None]]: |
| 9888 |
return f |
| 9889 |
|
| 9890 |
[file b.py.2] |
| 9891 |
from typing import TypeVar, Callable, Union |
| 9892 |
from typing_extensions import ParamSpec |
| 9893 |
|
| 9894 |
P = ParamSpec("P") |
| 9895 |
T = TypeVar("T") |
| 9896 |
|
| 9897 |
def foo(f: Callable[P, T]) -> Callable[P, Union[T, None]]: |
| 9898 |
return f |
| 9899 |
|
| 9900 |
x = 0 # Arbitrary change to trigger reprocessing |
| 9901 |
|
| 9902 |
[builtins fixtures/dict.pyi] |
| 9903 |
[out] |
| 9904 |
== |
| 9905 |
a.py:5: note: Revealed type is "def (x: builtins.int) -> builtins.str | None" |
| 9906 |
|
| 9907 |
[case testTypeVarTupleCached] |
| 9908 |
import a |
| 9909 |
|
| 9910 |
[file a.py] |
| 9911 |
import b |
| 9912 |
|
| 9913 |
def f(x: int) -> str: return 'x' |
| 9914 |
|
| 9915 |
b.foo((1, 'x')) |
| 9916 |
|
| 9917 |
[file a.py.2] |
| 9918 |
import b |
| 9919 |
|
| 9920 |
reveal_type(b.foo((1, 'x'))) |
| 9921 |
|
| 9922 |
[file b.py] |
| 9923 |
from typing import Tuple |
| 9924 |
from typing_extensions import TypeVarTuple, Unpack |
| 9925 |
|
| 9926 |
Ts = TypeVarTuple("Ts") |
| 9927 |
|
| 9928 |
def foo(t: Tuple[Unpack[Ts]]) -> Tuple[Unpack[Ts]]: |
| 9929 |
return t |
| 9930 |
|
| 9931 |
[file b.py.2] |
| 9932 |
from typing import Tuple |
| 9933 |
from typing_extensions import TypeVarTuple, Unpack |
| 9934 |
|
| 9935 |
Ts = TypeVarTuple("Ts") |
| 9936 |
|
| 9937 |
def foo(t: Tuple[Unpack[Ts]]) -> Tuple[Unpack[Ts]]: |
| 9938 |
return t |
| 9939 |
|
| 9940 |
x = 0 # Arbitrary change to trigger reprocessing |
| 9941 |
[builtins fixtures/dict.pyi] |
| 9942 |
[out] |
| 9943 |
== |
| 9944 |
a.py:3: note: Revealed type is "tuple[Literal[1]?, Literal['x']?]" |
| 9945 |
|
| 9946 |
[case testVariadicClassFineUpdateRegularToVariadic] |
| 9947 |
from typing import Any |
| 9948 |
from lib import C |
| 9949 |
|
| 9950 |
x: C[int, str] |
| 9951 |
|
| 9952 |
[file lib.py] |
| 9953 |
from typing import Generic, TypeVar |
| 9954 |
|
| 9955 |
T = TypeVar("T") |
| 9956 |
S = TypeVar("S") |
| 9957 |
class C(Generic[T, S]): ... |
| 9958 |
|
| 9959 |
[file lib.py.2] |
| 9960 |
from typing import Generic |
| 9961 |
from typing_extensions import TypeVarTuple, Unpack |
| 9962 |
|
| 9963 |
Ts = TypeVarTuple("Ts") |
| 9964 |
class C(Generic[Unpack[Ts]]): ... |
| 9965 |
[builtins fixtures/tuple.pyi] |
| 9966 |
[out] |
| 9967 |
== |
| 9968 |
|
| 9969 |
[case testVariadicClassFineUpdateVariadicToRegular] |
| 9970 |
from typing import Any |
| 9971 |
from lib import C |
| 9972 |
|
| 9973 |
x: C[int, str, int] |
| 9974 |
|
| 9975 |
[file lib.py] |
| 9976 |
from typing import Generic |
| 9977 |
from typing_extensions import TypeVarTuple, Unpack |
| 9978 |
|
| 9979 |
Ts = TypeVarTuple("Ts") |
| 9980 |
class C(Generic[Unpack[Ts]]): ... |
| 9981 |
[file lib.py.2] |
| 9982 |
from typing import Generic, TypeVar |
| 9983 |
|
| 9984 |
T = TypeVar("T") |
| 9985 |
S = TypeVar("S") |
| 9986 |
class C(Generic[T, S]): ... |
| 9987 |
[builtins fixtures/tuple.pyi] |
| 9988 |
[out] |
| 9989 |
== |
| 9990 |
main:4: error: "C" expects 2 type arguments, but 3 given |
| 9991 |
|
| 9992 |
-- Order of error messages is different, so we repeat the test twice. |
| 9993 |
[case testVariadicClassFineUpdateValidToInvalidCached-only_when_cache] |
| 9994 |
from typing import Any |
| 9995 |
from lib import C |
| 9996 |
|
| 9997 |
x: C[int, str] |
| 9998 |
|
| 9999 |
[file lib.py] |
| 10000 |
from typing import Generic |
| 10001 |
from typing_extensions import TypeVarTuple, Unpack |
| 10002 |
|
| 10003 |
Ts = TypeVarTuple("Ts") |
| 10004 |
class C(Generic[Unpack[Ts]]): ... |
| 10005 |
|
| 10006 |
[file lib.py.2] |
| 10007 |
from typing import Generic |
| 10008 |
from typing_extensions import TypeVarTuple, Unpack |
| 10009 |
|
| 10010 |
Ts = TypeVarTuple("Ts") |
| 10011 |
class C(Generic[Ts]): ... |
| 10012 |
[builtins fixtures/tuple.pyi] |
| 10013 |
[out] |
| 10014 |
== |
| 10015 |
main:4: error: "C" expects no type arguments, but 2 given |
| 10016 |
lib.py:5: error: Free type variable expected in Generic[...] |
| 10017 |
|
| 10018 |
[case testVariadicClassFineUpdateValidToInvalid-only_when_nocache] |
| 10019 |
from typing import Any |
| 10020 |
from lib import C |
| 10021 |
|
| 10022 |
x: C[int, str] |
| 10023 |
|
| 10024 |
[file lib.py] |
| 10025 |
from typing import Generic |
| 10026 |
from typing_extensions import TypeVarTuple, Unpack |
| 10027 |
|
| 10028 |
Ts = TypeVarTuple("Ts") |
| 10029 |
class C(Generic[Unpack[Ts]]): ... |
| 10030 |
|
| 10031 |
[file lib.py.2] |
| 10032 |
from typing import Generic |
| 10033 |
from typing_extensions import TypeVarTuple, Unpack |
| 10034 |
|
| 10035 |
Ts = TypeVarTuple("Ts") |
| 10036 |
class C(Generic[Ts]): ... |
| 10037 |
[builtins fixtures/tuple.pyi] |
| 10038 |
[out] |
| 10039 |
== |
| 10040 |
lib.py:5: error: Free type variable expected in Generic[...] |
| 10041 |
main:4: error: "C" expects no type arguments, but 2 given |
| 10042 |
|
| 10043 |
[case testVariadicClassFineUpdateInvalidToValid] |
| 10044 |
from typing import Any |
| 10045 |
from lib import C |
| 10046 |
|
| 10047 |
x: C[int, str] |
| 10048 |
|
| 10049 |
[file lib.py] |
| 10050 |
from typing import Generic |
| 10051 |
from typing_extensions import TypeVarTuple, Unpack |
| 10052 |
|
| 10053 |
Ts = TypeVarTuple("Ts") |
| 10054 |
class C(Generic[Ts]): ... |
| 10055 |
|
| 10056 |
[file lib.py.2] |
| 10057 |
from typing import Generic |
| 10058 |
from typing_extensions import TypeVarTuple, Unpack |
| 10059 |
|
| 10060 |
Ts = TypeVarTuple("Ts") |
| 10061 |
class C(Generic[Unpack[Ts]]): ... |
| 10062 |
[builtins fixtures/tuple.pyi] |
| 10063 |
[out] |
| 10064 |
lib.py:5: error: Free type variable expected in Generic[...] |
| 10065 |
main:4: error: "C" expects no type arguments, but 2 given |
| 10066 |
== |
| 10067 |
|
| 10068 |
[case testUnpackKwargsUpdateFine] |
| 10069 |
import m |
| 10070 |
[file shared.py] |
| 10071 |
from typing import TypedDict |
| 10072 |
|
| 10073 |
class Person(TypedDict): |
| 10074 |
name: str |
| 10075 |
age: int |
| 10076 |
|
| 10077 |
[file shared.py.2] |
| 10078 |
from typing import TypedDict |
| 10079 |
|
| 10080 |
class Person(TypedDict): |
| 10081 |
name: str |
| 10082 |
age: str |
| 10083 |
|
| 10084 |
[file lib.py] |
| 10085 |
from typing_extensions import Unpack |
| 10086 |
from shared import Person |
| 10087 |
|
| 10088 |
def foo(**kwargs: Unpack[Person]): |
| 10089 |
... |
| 10090 |
[file m.py] |
| 10091 |
from lib import foo |
| 10092 |
foo(name='Jennifer', age=38) |
| 10093 |
|
| 10094 |
[builtins fixtures/dict.pyi] |
| 10095 |
[typing fixtures/typing-typeddict.pyi] |
| 10096 |
[out] |
| 10097 |
== |
| 10098 |
m.py:2: error: Argument "age" to "foo" has incompatible type "int"; expected "str" |
| 10099 |
|
| 10100 |
[case testModuleAsProtocolImplementationFine] |
| 10101 |
import m |
| 10102 |
[file m.py] |
| 10103 |
from typing import Protocol |
| 10104 |
from lib import C |
| 10105 |
|
| 10106 |
class Options(Protocol): |
| 10107 |
timeout: int |
| 10108 |
def update(self) -> bool: ... |
| 10109 |
|
| 10110 |
def setup(options: Options) -> None: ... |
| 10111 |
setup(C().config) |
| 10112 |
|
| 10113 |
[file lib.py] |
| 10114 |
import default_config |
| 10115 |
|
| 10116 |
class C: |
| 10117 |
config = default_config |
| 10118 |
|
| 10119 |
[file default_config.py] |
| 10120 |
timeout = 100 |
| 10121 |
def update() -> bool: ... |
| 10122 |
|
| 10123 |
[file default_config.py.2] |
| 10124 |
timeout = 100 |
| 10125 |
def update() -> str: ... |
| 10126 |
[builtins fixtures/module.pyi] |
| 10127 |
[out] |
| 10128 |
== |
| 10129 |
m.py:9: error: Argument 1 to "setup" has incompatible type Module; expected "Options" |
| 10130 |
m.py:9: note: Following member(s) of Module "default_config" have conflicts: |
| 10131 |
m.py:9: note: Expected: |
| 10132 |
m.py:9: note: def update() -> bool |
| 10133 |
m.py:9: note: Got: |
| 10134 |
m.py:9: note: def update() -> str |
| 10135 |
|
| 10136 |
[case testBoundGenericMethodFine] |
| 10137 |
import main |
| 10138 |
[file main.py] |
| 10139 |
import lib |
| 10140 |
[file main.py.3] |
| 10141 |
import lib |
| 10142 |
reveal_type(lib.foo(42)) |
| 10143 |
[file lib/__init__.pyi] |
| 10144 |
from lib import context |
| 10145 |
foo = context.test.foo |
| 10146 |
[file lib/context.pyi] |
| 10147 |
from typing import TypeVar |
| 10148 |
import lib.other |
| 10149 |
|
| 10150 |
T = TypeVar("T") |
| 10151 |
class Test: |
| 10152 |
def foo(self, x: T, n: lib.other.C = ...) -> T: ... |
| 10153 |
test: Test |
| 10154 |
|
| 10155 |
[file lib/other.pyi] |
| 10156 |
class C: ... |
| 10157 |
[file lib/other.pyi.2] |
| 10158 |
class B: ... |
| 10159 |
class C(B): ... |
| 10160 |
[out] |
| 10161 |
== |
| 10162 |
== |
| 10163 |
main.py:2: note: Revealed type is "builtins.int" |
| 10164 |
|
| 10165 |
[case testBoundGenericMethodParamSpecFine] |
| 10166 |
import main |
| 10167 |
[file main.py] |
| 10168 |
import lib |
| 10169 |
[file main.py.3] |
| 10170 |
from typing import Callable |
| 10171 |
import lib |
| 10172 |
f: Callable[[], int] |
| 10173 |
reveal_type(lib.foo(f)) |
| 10174 |
[file lib/__init__.pyi] |
| 10175 |
from lib import context |
| 10176 |
foo = context.test.foo |
| 10177 |
[file lib/context.pyi] |
| 10178 |
from typing_extensions import ParamSpec |
| 10179 |
from typing import Callable |
| 10180 |
import lib.other |
| 10181 |
|
| 10182 |
P = ParamSpec("P") |
| 10183 |
class Test: |
| 10184 |
def foo(self, x: Callable[P, int], n: lib.other.C = ...) -> Callable[P, str]: ... |
| 10185 |
test: Test |
| 10186 |
|
| 10187 |
[file lib/other.pyi] |
| 10188 |
class C: ... |
| 10189 |
[file lib/other.pyi.2] |
| 10190 |
class B: ... |
| 10191 |
class C(B): ... |
| 10192 |
[builtins fixtures/dict.pyi] |
| 10193 |
[out] |
| 10194 |
== |
| 10195 |
== |
| 10196 |
main.py:4: note: Revealed type is "def () -> builtins.str" |
| 10197 |
|
| 10198 |
[case testAbstractBodyTurnsEmpty] |
| 10199 |
from b import Base |
| 10200 |
|
| 10201 |
class Sub(Base): |
| 10202 |
def meth(self) -> int: |
| 10203 |
return super().meth() |
| 10204 |
|
| 10205 |
[file b.py] |
| 10206 |
from abc import abstractmethod |
| 10207 |
class Base: |
| 10208 |
@abstractmethod |
| 10209 |
def meth(self) -> int: return 0 |
| 10210 |
|
| 10211 |
[file b.py.2] |
| 10212 |
from abc import abstractmethod |
| 10213 |
class Base: |
| 10214 |
@abstractmethod |
| 10215 |
def meth(self) -> int: ... |
| 10216 |
[out] |
| 10217 |
== |
| 10218 |
main:5: error: Call to abstract method "meth" of "Base" with trivial body via super() is unsafe |
| 10219 |
|
| 10220 |
[case testAbstractBodyTurnsEmptyProtocol] |
| 10221 |
from b import Base |
| 10222 |
|
| 10223 |
class Sub(Base): |
| 10224 |
def meth(self) -> int: |
| 10225 |
return super().meth() |
| 10226 |
|
| 10227 |
[file b.py] |
| 10228 |
from typing import Protocol |
| 10229 |
class Base(Protocol): |
| 10230 |
def meth(self) -> int: return 0 |
| 10231 |
[file b.py.2] |
| 10232 |
from typing import Protocol |
| 10233 |
class Base(Protocol): |
| 10234 |
def meth(self) -> int: ... |
| 10235 |
[out] |
| 10236 |
== |
| 10237 |
main:5: error: Call to abstract method "meth" of "Base" with trivial body via super() is unsafe |
| 10238 |
|
| 10239 |
[case testPrettyMessageSorting] |
| 10240 |
# flags: --pretty |
| 10241 |
import a |
| 10242 |
|
| 10243 |
[file a.py] |
| 10244 |
1 + '' |
| 10245 |
import b |
| 10246 |
|
| 10247 |
[file b.py] |
| 10248 |
object + 1 |
| 10249 |
|
| 10250 |
[file b.py.2] |
| 10251 |
object + 1 |
| 10252 |
1() |
| 10253 |
|
| 10254 |
[out] |
| 10255 |
b.py:1: error: Unsupported left operand type for + ("type[object]") |
| 10256 |
object + 1 |
| 10257 |
^~~~~~~~~~ |
| 10258 |
a.py:1: error: Unsupported operand types for + ("int" and "str") |
| 10259 |
1 + '' |
| 10260 |
^~ |
| 10261 |
== |
| 10262 |
b.py:1: error: Unsupported left operand type for + ("type[object]") |
| 10263 |
object + 1 |
| 10264 |
^~~~~~~~~~ |
| 10265 |
b.py:2: error: "int" not callable |
| 10266 |
1() |
| 10267 |
^~~ |
| 10268 |
a.py:1: error: Unsupported operand types for + ("int" and "str") |
| 10269 |
1 + '' |
| 10270 |
^~ |
| 10271 |
|
| 10272 |
[case testTypingSelfFine] |
| 10273 |
import m |
| 10274 |
[file lib.py] |
| 10275 |
from typing import Any |
| 10276 |
|
| 10277 |
class C: |
| 10278 |
def meth(self, other: Any) -> C: ... |
| 10279 |
[file lib.py.2] |
| 10280 |
from typing import Self |
| 10281 |
|
| 10282 |
class C: |
| 10283 |
def meth(self, other: Self) -> Self: ... |
| 10284 |
|
| 10285 |
[file n.py] |
| 10286 |
import lib |
| 10287 |
class D(lib.C): ... |
| 10288 |
[file m.py] |
| 10289 |
from n import D |
| 10290 |
d = D() |
| 10291 |
def test() -> None: |
| 10292 |
d.meth(42) |
| 10293 |
[out] |
| 10294 |
== |
| 10295 |
m.py:4: error: Argument 1 to "meth" of "C" has incompatible type "int"; expected "D" |
| 10296 |
|
| 10297 |
[case testNoNestedDefinitionCrash] |
| 10298 |
import m |
| 10299 |
[file m.py] |
| 10300 |
from typing import Any, TYPE_CHECKING |
| 10301 |
|
| 10302 |
class C: |
| 10303 |
if TYPE_CHECKING: |
| 10304 |
def __init__(self, **kw: Any): ... |
| 10305 |
|
| 10306 |
C |
| 10307 |
[file m.py.2] |
| 10308 |
from typing import Any, TYPE_CHECKING |
| 10309 |
|
| 10310 |
class C: |
| 10311 |
if TYPE_CHECKING: |
| 10312 |
def __init__(self, **kw: Any): ... |
| 10313 |
|
| 10314 |
C |
| 10315 |
# change |
| 10316 |
[builtins fixtures/dict.pyi] |
| 10317 |
[out] |
| 10318 |
== |
| 10319 |
|
| 10320 |
[case testNoNestedDefinitionCrash2] |
| 10321 |
import m |
| 10322 |
[file m.py] |
| 10323 |
from typing import Any |
| 10324 |
|
| 10325 |
class C: |
| 10326 |
try: |
| 10327 |
def __init__(self, **kw: Any): ... |
| 10328 |
except: |
| 10329 |
pass |
| 10330 |
|
| 10331 |
C |
| 10332 |
[file m.py.2] |
| 10333 |
from typing import Any |
| 10334 |
|
| 10335 |
class C: |
| 10336 |
try: |
| 10337 |
def __init__(self, **kw: Any): ... |
| 10338 |
except: |
| 10339 |
pass |
| 10340 |
|
| 10341 |
C |
| 10342 |
# change |
| 10343 |
[builtins fixtures/dict.pyi] |
| 10344 |
[out] |
| 10345 |
== |
| 10346 |
|
| 10347 |
[case testNamedTupleNestedCrash] |
| 10348 |
import m |
| 10349 |
[file m.py] |
| 10350 |
from typing import NamedTuple |
| 10351 |
|
| 10352 |
class NT(NamedTuple): |
| 10353 |
class C: ... |
| 10354 |
x: int |
| 10355 |
y: int |
| 10356 |
|
| 10357 |
[file m.py.2] |
| 10358 |
from typing import NamedTuple |
| 10359 |
|
| 10360 |
class NT(NamedTuple): |
| 10361 |
class C: ... |
| 10362 |
x: int |
| 10363 |
y: int |
| 10364 |
# change |
| 10365 |
[builtins fixtures/tuple.pyi] |
| 10366 |
[out] |
| 10367 |
m.py:4: error: Invalid statement in NamedTuple definition; expected "field_name: field_type [= default]" |
| 10368 |
== |
| 10369 |
m.py:4: error: Invalid statement in NamedTuple definition; expected "field_name: field_type [= default]" |
| 10370 |
|
| 10371 |
[case testNamedTupleNestedClassRecheck] |
| 10372 |
import n |
| 10373 |
[file n.py] |
| 10374 |
import m |
| 10375 |
x: m.NT |
| 10376 |
[file m.py] |
| 10377 |
from typing import NamedTuple |
| 10378 |
from f import A |
| 10379 |
|
| 10380 |
class NT(NamedTuple): |
| 10381 |
class C: ... |
| 10382 |
x: int |
| 10383 |
y: A |
| 10384 |
|
| 10385 |
[file f.py] |
| 10386 |
A = int |
| 10387 |
[file f.py.2] |
| 10388 |
A = str |
| 10389 |
[builtins fixtures/tuple.pyi] |
| 10390 |
[out] |
| 10391 |
m.py:5: error: Invalid statement in NamedTuple definition; expected "field_name: field_type [= default]" |
| 10392 |
== |
| 10393 |
m.py:5: error: Invalid statement in NamedTuple definition; expected "field_name: field_type [= default]" |
| 10394 |
|
| 10395 |
[case testTypedDictNestedClassRecheck] |
| 10396 |
import n |
| 10397 |
[file n.py] |
| 10398 |
import m |
| 10399 |
x: m.TD |
| 10400 |
[file m.py] |
| 10401 |
from typing import TypedDict |
| 10402 |
from f import A |
| 10403 |
|
| 10404 |
class TD(TypedDict): |
| 10405 |
class C: ... |
| 10406 |
x: int |
| 10407 |
y: A |
| 10408 |
|
| 10409 |
[file f.py] |
| 10410 |
A = int |
| 10411 |
[file f.py.2] |
| 10412 |
A = str |
| 10413 |
[builtins fixtures/dict.pyi] |
| 10414 |
[typing fixtures/typing-typeddict.pyi] |
| 10415 |
[out] |
| 10416 |
m.py:5: error: Invalid statement in TypedDict definition; expected "field_name: field_type" |
| 10417 |
== |
| 10418 |
m.py:5: error: Invalid statement in TypedDict definition; expected "field_name: field_type" |
| 10419 |
|
| 10420 |
[case testTypeAliasWithNewStyleUnionChangedToVariable] |
| 10421 |
import a |
| 10422 |
|
| 10423 |
[file a.py] |
| 10424 |
from b import C, D |
| 10425 |
A = C | D |
| 10426 |
a: A |
| 10427 |
reveal_type(a) |
| 10428 |
[builtins fixtures/type.pyi] |
| 10429 |
|
| 10430 |
[file b.py] |
| 10431 |
C = int |
| 10432 |
D = str |
| 10433 |
|
| 10434 |
[file b.py.2] |
| 10435 |
C = "x" |
| 10436 |
D = "y" |
| 10437 |
|
| 10438 |
[file b.py.3] |
| 10439 |
C = str |
| 10440 |
D = int |
| 10441 |
[out] |
| 10442 |
a.py:4: note: Revealed type is "builtins.int | builtins.str" |
| 10443 |
== |
| 10444 |
a.py:2: error: Unsupported left operand type for | ("str") |
| 10445 |
a.py:3: error: Variable "a.A" is not valid as a type |
| 10446 |
a.py:3: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases |
| 10447 |
a.py:4: note: Revealed type is "A?" |
| 10448 |
== |
| 10449 |
a.py:4: note: Revealed type is "builtins.str | builtins.int" |
| 10450 |
|
| 10451 |
[case testUnionOfSimilarCallablesCrash] |
| 10452 |
import b |
| 10453 |
|
| 10454 |
[file b.py] |
| 10455 |
from a import x |
| 10456 |
|
| 10457 |
[file m.py] |
| 10458 |
from typing import Union, TypeVar |
| 10459 |
|
| 10460 |
T = TypeVar("T") |
| 10461 |
S = TypeVar("S") |
| 10462 |
def foo(x: T, y: S) -> Union[T, S]: ... |
| 10463 |
def f(x: int) -> int: ... |
| 10464 |
def g(*x: int) -> int: ... |
| 10465 |
|
| 10466 |
[file a.py] |
| 10467 |
from m import f, g, foo |
| 10468 |
x = foo(f, g) |
| 10469 |
|
| 10470 |
[file a.py.2] |
| 10471 |
from m import f, g, foo |
| 10472 |
x = foo(f, g) |
| 10473 |
reveal_type(x) |
| 10474 |
[builtins fixtures/tuple.pyi] |
| 10475 |
[out] |
| 10476 |
== |
| 10477 |
a.py:3: note: Revealed type is "(def (x: builtins.int) -> builtins.int) | (def (*x: builtins.int) -> builtins.int)" |
| 10478 |
|
| 10479 |
[case testErrorInReAddedModule] |
| 10480 |
# flags: --disallow-untyped-defs --follow-imports=error |
| 10481 |
# cmd: mypy a.py |
| 10482 |
# cmd2: mypy b.py |
| 10483 |
# cmd3: mypy a.py |
| 10484 |
|
| 10485 |
[file a.py] |
| 10486 |
def f(): pass |
| 10487 |
[file b.py] |
| 10488 |
def f(): pass |
| 10489 |
[file unrelated.txt.3] |
| 10490 |
[out] |
| 10491 |
a.py:1: error: Function is missing a return type annotation |
| 10492 |
a.py:1: note: Use "-> None" if function does not return a value |
| 10493 |
== |
| 10494 |
b.py:1: error: Function is missing a return type annotation |
| 10495 |
b.py:1: note: Use "-> None" if function does not return a value |
| 10496 |
== |
| 10497 |
a.py:1: error: Function is missing a return type annotation |
| 10498 |
a.py:1: note: Use "-> None" if function does not return a value |
| 10499 |
|
| 10500 |
[case testModuleLevelGetAttrInStub] |
| 10501 |
import stub |
| 10502 |
import a |
| 10503 |
import b |
| 10504 |
|
| 10505 |
[file stub/__init__.pyi] |
| 10506 |
s: str |
| 10507 |
def __getattr__(self): pass |
| 10508 |
|
| 10509 |
[file a.py] |
| 10510 |
|
| 10511 |
[file a.py.2] |
| 10512 |
from stub import x |
| 10513 |
from stub.pkg import y |
| 10514 |
from stub.pkg.sub import z |
| 10515 |
|
| 10516 |
[file b.py] |
| 10517 |
|
| 10518 |
[file b.py.3] |
| 10519 |
from stub import s |
| 10520 |
reveal_type(s) |
| 10521 |
|
| 10522 |
[out] |
| 10523 |
== |
| 10524 |
== |
| 10525 |
b.py:2: note: Revealed type is "builtins.str" |
| 10526 |
|
| 10527 |
[case testRenameSubModule] |
| 10528 |
import a |
| 10529 |
|
| 10530 |
[file a.py] |
| 10531 |
import pkg.sub |
| 10532 |
|
| 10533 |
[file pkg/__init__.py] |
| 10534 |
[file pkg/sub/__init__.py] |
| 10535 |
from pkg.sub import mod |
| 10536 |
[file pkg/sub/mod.py] |
| 10537 |
|
| 10538 |
[file pkg/sub/__init__.py.2] |
| 10539 |
from pkg.sub import modb |
| 10540 |
[delete pkg/sub/mod.py.2] |
| 10541 |
[file pkg/sub/modb.py.2] |
| 10542 |
|
| 10543 |
[out] |
| 10544 |
== |
| 10545 |
|
| 10546 |
[case testUnusedTypeIgnorePreservedAfterChange] |
| 10547 |
# flags: --warn-unused-ignores --no-error-summary |
| 10548 |
[file main.py] |
| 10549 |
a = 1 # type: ignore |
| 10550 |
[file main.py.2] |
| 10551 |
a = 1 # type: ignore |
| 10552 |
# Comment to trigger reload. |
| 10553 |
[out] |
| 10554 |
main.py:1: error: Unused "type: ignore" comment |
| 10555 |
== |
| 10556 |
main.py:1: error: Unused "type: ignore" comment |
| 10557 |
|
| 10558 |
[case testTypeIgnoreWithoutCodePreservedAfterChange] |
| 10559 |
# flags: --enable-error-code ignore-without-code --no-error-summary |
| 10560 |
[file main.py] |
| 10561 |
a = 1 # type: ignore |
| 10562 |
[file main.py.2] |
| 10563 |
a = 1 # type: ignore |
| 10564 |
# Comment to trigger reload. |
| 10565 |
[out] |
| 10566 |
main.py:1: error: "type: ignore" comment without error code |
| 10567 |
== |
| 10568 |
main.py:1: error: "type: ignore" comment without error code |
| 10569 |
|
| 10570 |
[case testFineGrainedFunctoolsPartial] |
| 10571 |
import m |
| 10572 |
|
| 10573 |
[file m.py] |
| 10574 |
from typing import Callable |
| 10575 |
from partial import p1 |
| 10576 |
|
| 10577 |
reveal_type(p1) |
| 10578 |
p1("a") |
| 10579 |
p1("a", 3) |
| 10580 |
p1("a", c=3) |
| 10581 |
p1(1, 3) |
| 10582 |
p1(1, "a", 3) |
| 10583 |
p1(a=1, b="a", c=3) |
| 10584 |
[builtins fixtures/dict.pyi] |
| 10585 |
|
| 10586 |
[file partial.py] |
| 10587 |
from typing import Callable |
| 10588 |
import functools |
| 10589 |
|
| 10590 |
def foo(a: int, b: str, c: int = 5) -> int: ... |
| 10591 |
p1 = foo |
| 10592 |
|
| 10593 |
[file partial.py.2] |
| 10594 |
from typing import Callable |
| 10595 |
import functools |
| 10596 |
|
| 10597 |
def foo(a: int, b: str, c: int = 5) -> int: ... |
| 10598 |
p1 = functools.partial(foo, 1) |
| 10599 |
|
| 10600 |
[out] |
| 10601 |
m.py:4: note: Revealed type is "def (a: builtins.int, b: builtins.str, c: builtins.int =) -> builtins.int" |
| 10602 |
m.py:5: error: Too few arguments |
| 10603 |
m.py:5: error: Argument 1 has incompatible type "str"; expected "int" |
| 10604 |
m.py:6: error: Argument 1 has incompatible type "str"; expected "int" |
| 10605 |
m.py:6: error: Argument 2 has incompatible type "int"; expected "str" |
| 10606 |
m.py:7: error: Too few arguments |
| 10607 |
m.py:7: error: Argument 1 has incompatible type "str"; expected "int" |
| 10608 |
m.py:8: error: Argument 2 has incompatible type "int"; expected "str" |
| 10609 |
== |
| 10610 |
m.py:4: note: Revealed type is "functools.partial[builtins.int]" |
| 10611 |
m.py:8: error: Argument 1 to "foo" has incompatible type "int"; expected "str" |
| 10612 |
m.py:9: error: Too many arguments for "foo" |
| 10613 |
m.py:9: error: Argument 1 to "foo" has incompatible type "int"; expected "str" |
| 10614 |
m.py:9: error: Argument 2 to "foo" has incompatible type "str"; expected "int" |
| 10615 |
m.py:10: error: Unexpected keyword argument "a" for "foo" |
| 10616 |
m.py:10: note: "foo" defined in "partial" |
| 10617 |
|
| 10618 |
[case testReplaceFunctionWithDecoratedFunctionIndirect] |
| 10619 |
from b import f |
| 10620 |
x: int = f() |
| 10621 |
import b |
| 10622 |
y: int = b.f() |
| 10623 |
|
| 10624 |
[file b.py] |
| 10625 |
from a import f |
| 10626 |
|
| 10627 |
[file a.py] |
| 10628 |
def f() -> int: ... |
| 10629 |
|
| 10630 |
[file a.py.2] |
| 10631 |
from typing import Callable |
| 10632 |
def d(t: Callable[[], str]) -> Callable[[], str]: ... |
| 10633 |
|
| 10634 |
@d |
| 10635 |
def f() -> str: ... |
| 10636 |
|
| 10637 |
[builtins fixtures/tuple.pyi] |
| 10638 |
[out] |
| 10639 |
== |
| 10640 |
main:2: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 10641 |
main:4: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 10642 |
|
| 10643 |
[case testReplaceFunctionWithDecoratedFunctionIndirect2] |
| 10644 |
from c import f |
| 10645 |
x: int = f() |
| 10646 |
import c |
| 10647 |
y: int = c.f() |
| 10648 |
|
| 10649 |
[file c.py] |
| 10650 |
from b import f |
| 10651 |
|
| 10652 |
[file b.py] |
| 10653 |
from a import f |
| 10654 |
|
| 10655 |
[file a.py] |
| 10656 |
def f() -> int: ... |
| 10657 |
|
| 10658 |
[file a.py.2] |
| 10659 |
from typing import Callable |
| 10660 |
def d(t: Callable[[], str]) -> Callable[[], str]: ... |
| 10661 |
|
| 10662 |
@d |
| 10663 |
def f() -> str: ... |
| 10664 |
|
| 10665 |
[builtins fixtures/tuple.pyi] |
| 10666 |
[out] |
| 10667 |
== |
| 10668 |
main:2: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 10669 |
main:4: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 10670 |
|
| 10671 |
[case testReplaceFunctionWithClassIndirect] |
| 10672 |
from b import f |
| 10673 |
x: int = f() |
| 10674 |
import b |
| 10675 |
y: int = b.f() |
| 10676 |
|
| 10677 |
[file b.py] |
| 10678 |
from a import f |
| 10679 |
|
| 10680 |
[file a.py] |
| 10681 |
def f() -> int: ... |
| 10682 |
|
| 10683 |
[file a.py.2] |
| 10684 |
class f: ... |
| 10685 |
|
| 10686 |
[builtins fixtures/tuple.pyi] |
| 10687 |
[out] |
| 10688 |
== |
| 10689 |
main:2: error: Incompatible types in assignment (expression has type "f", variable has type "int") |
| 10690 |
main:4: error: Incompatible types in assignment (expression has type "f", variable has type "int") |
| 10691 |
|
| 10692 |
[case testReplaceFunctionWithClassIndirect2] |
| 10693 |
from c import f |
| 10694 |
x: int = f() |
| 10695 |
import c |
| 10696 |
y: int = c.f() |
| 10697 |
|
| 10698 |
[file c.py] |
| 10699 |
from b import f |
| 10700 |
|
| 10701 |
[file b.py] |
| 10702 |
from a import f |
| 10703 |
|
| 10704 |
[file a.py] |
| 10705 |
def f() -> int: ... |
| 10706 |
|
| 10707 |
[file a.py.2] |
| 10708 |
class f: ... |
| 10709 |
|
| 10710 |
[builtins fixtures/tuple.pyi] |
| 10711 |
[out] |
| 10712 |
== |
| 10713 |
main:2: error: Incompatible types in assignment (expression has type "f", variable has type "int") |
| 10714 |
main:4: error: Incompatible types in assignment (expression has type "f", variable has type "int") |
| 10715 |
|
| 10716 |
|
| 10717 |
[case testDeprecatedAddKeepChangeAndRemoveFunctionDeprecation] |
| 10718 |
# flags: --enable-error-code=deprecated |
| 10719 |
|
| 10720 |
from a import f |
| 10721 |
f() |
| 10722 |
import a |
| 10723 |
a.f() |
| 10724 |
|
| 10725 |
[file a.py] |
| 10726 |
def f() -> None: ... |
| 10727 |
|
| 10728 |
[file a.py.2] |
| 10729 |
from typing_extensions import deprecated |
| 10730 |
@deprecated("use f2 instead") |
| 10731 |
def f() -> None: ... |
| 10732 |
|
| 10733 |
[file a.py.3] |
| 10734 |
from typing_extensions import deprecated |
| 10735 |
@deprecated("use f2 instead") |
| 10736 |
def f() -> None: ... |
| 10737 |
|
| 10738 |
[file a.py.4] |
| 10739 |
from typing_extensions import deprecated |
| 10740 |
@deprecated("use f3 instead") |
| 10741 |
def f() -> None: ... |
| 10742 |
|
| 10743 |
[file a.py.5] |
| 10744 |
def f() -> None: ... |
| 10745 |
|
| 10746 |
[builtins fixtures/tuple.pyi] |
| 10747 |
[out] |
| 10748 |
== |
| 10749 |
main:3: error: function a.f is deprecated: use f2 instead |
| 10750 |
main:6: error: function a.f is deprecated: use f2 instead |
| 10751 |
== |
| 10752 |
main:3: error: function a.f is deprecated: use f2 instead |
| 10753 |
main:6: error: function a.f is deprecated: use f2 instead |
| 10754 |
== |
| 10755 |
main:3: error: function a.f is deprecated: use f3 instead |
| 10756 |
main:6: error: function a.f is deprecated: use f3 instead |
| 10757 |
== |
| 10758 |
|
| 10759 |
|
| 10760 |
[case testDeprecatedRemoveFunctionDeprecation] |
| 10761 |
# flags: --enable-error-code=deprecated |
| 10762 |
from a import f |
| 10763 |
f() |
| 10764 |
import a |
| 10765 |
a.f() |
| 10766 |
|
| 10767 |
[file a.py] |
| 10768 |
from typing_extensions import deprecated |
| 10769 |
@deprecated("use f2 instead") |
| 10770 |
def f() -> None: ... |
| 10771 |
|
| 10772 |
[file a.py.2] |
| 10773 |
def f() -> None: ... |
| 10774 |
|
| 10775 |
[builtins fixtures/tuple.pyi] |
| 10776 |
[out] |
| 10777 |
main:2: error: function a.f is deprecated: use f2 instead |
| 10778 |
main:5: error: function a.f is deprecated: use f2 instead |
| 10779 |
== |
| 10780 |
|
| 10781 |
[case testDeprecatedKeepFunctionDeprecation] |
| 10782 |
# flags: --enable-error-code=deprecated |
| 10783 |
from a import f |
| 10784 |
f() |
| 10785 |
import a |
| 10786 |
a.f() |
| 10787 |
|
| 10788 |
[file a.py] |
| 10789 |
from typing_extensions import deprecated |
| 10790 |
@deprecated("use f2 instead") |
| 10791 |
def f() -> None: ... |
| 10792 |
|
| 10793 |
[file a.py.2] |
| 10794 |
from typing_extensions import deprecated |
| 10795 |
@deprecated("use f2 instead") |
| 10796 |
def f() -> None: ... |
| 10797 |
|
| 10798 |
[builtins fixtures/tuple.pyi] |
| 10799 |
[out] |
| 10800 |
main:2: error: function a.f is deprecated: use f2 instead |
| 10801 |
main:5: error: function a.f is deprecated: use f2 instead |
| 10802 |
== |
| 10803 |
main:2: error: function a.f is deprecated: use f2 instead |
| 10804 |
main:5: error: function a.f is deprecated: use f2 instead |
| 10805 |
|
| 10806 |
|
| 10807 |
[case testDeprecatedAddFunctionDeprecationIndirectImport] |
| 10808 |
# flags: --enable-error-code=deprecated |
| 10809 |
from b import f |
| 10810 |
f() |
| 10811 |
import b |
| 10812 |
b.f() |
| 10813 |
|
| 10814 |
[file b.py] |
| 10815 |
from a import f |
| 10816 |
|
| 10817 |
[file a.py] |
| 10818 |
def f() -> int: ... |
| 10819 |
|
| 10820 |
[file a.py.2] |
| 10821 |
from typing_extensions import deprecated |
| 10822 |
@deprecated("use f2 instead") |
| 10823 |
def f() -> int: ... |
| 10824 |
|
| 10825 |
[builtins fixtures/tuple.pyi] |
| 10826 |
[out] |
| 10827 |
== |
| 10828 |
b.py:1: error: function a.f is deprecated: use f2 instead |
| 10829 |
main:2: error: function a.f is deprecated: use f2 instead |
| 10830 |
main:5: error: function a.f is deprecated: use f2 instead |
| 10831 |
|
| 10832 |
|
| 10833 |
[case testDeprecatedChangeFunctionDeprecationIndirectImport] |
| 10834 |
# flags: --enable-error-code=deprecated |
| 10835 |
from b import f |
| 10836 |
f() |
| 10837 |
import b |
| 10838 |
b.f() |
| 10839 |
|
| 10840 |
[file b.py] |
| 10841 |
from a import f |
| 10842 |
|
| 10843 |
[file a.py] |
| 10844 |
from typing_extensions import deprecated |
| 10845 |
@deprecated("use f1 instead") |
| 10846 |
def f() -> int: ... |
| 10847 |
|
| 10848 |
[file a.py.2] |
| 10849 |
from typing_extensions import deprecated |
| 10850 |
@deprecated("use f2 instead") |
| 10851 |
def f() -> int: ... |
| 10852 |
|
| 10853 |
[builtins fixtures/tuple.pyi] |
| 10854 |
[out] |
| 10855 |
b.py:1: error: function a.f is deprecated: use f1 instead |
| 10856 |
main:2: error: function a.f is deprecated: use f1 instead |
| 10857 |
main:5: error: function a.f is deprecated: use f1 instead |
| 10858 |
== |
| 10859 |
b.py:1: error: function a.f is deprecated: use f2 instead |
| 10860 |
main:2: error: function a.f is deprecated: use f2 instead |
| 10861 |
main:5: error: function a.f is deprecated: use f2 instead |
| 10862 |
|
| 10863 |
[case testDeprecatedRemoveFunctionDeprecationIndirectImport] |
| 10864 |
# flags: --enable-error-code=deprecated |
| 10865 |
from b import f |
| 10866 |
f() |
| 10867 |
import b |
| 10868 |
b.f() |
| 10869 |
|
| 10870 |
[file b.py] |
| 10871 |
from a import f |
| 10872 |
|
| 10873 |
[file a.py] |
| 10874 |
from typing_extensions import deprecated |
| 10875 |
@deprecated("use f1 instead") |
| 10876 |
def f() -> int: ... |
| 10877 |
|
| 10878 |
[file a.py.2] |
| 10879 |
def f() -> int: ... |
| 10880 |
|
| 10881 |
[builtins fixtures/tuple.pyi] |
| 10882 |
[out] |
| 10883 |
b.py:1: error: function a.f is deprecated: use f1 instead |
| 10884 |
main:2: error: function a.f is deprecated: use f1 instead |
| 10885 |
main:5: error: function a.f is deprecated: use f1 instead |
| 10886 |
== |
| 10887 |
|
| 10888 |
|
| 10889 |
[case testDeprecatedFunctionAlreadyDecorated1-only_when_cache] |
| 10890 |
# flags: --enable-error-code=deprecated |
| 10891 |
from b import f |
| 10892 |
x: str = f() |
| 10893 |
import b |
| 10894 |
y: str = b.f() |
| 10895 |
|
| 10896 |
[file b.py] |
| 10897 |
from a import f |
| 10898 |
|
| 10899 |
[file a.py] |
| 10900 |
from typing import Callable |
| 10901 |
|
| 10902 |
def d(t: Callable[[], str]) -> Callable[[], str]: ... |
| 10903 |
|
| 10904 |
@d |
| 10905 |
def f() -> str: ... |
| 10906 |
|
| 10907 |
[file a.py.2] |
| 10908 |
from typing import Callable |
| 10909 |
from typing_extensions import deprecated |
| 10910 |
|
| 10911 |
def d(t: Callable[[], str]) -> Callable[[], str]: ... |
| 10912 |
|
| 10913 |
@deprecated("deprecated decorated function") |
| 10914 |
@d |
| 10915 |
def f() -> str: ... |
| 10916 |
|
| 10917 |
[builtins fixtures/tuple.pyi] |
| 10918 |
[out] |
| 10919 |
== |
| 10920 |
b.py:1: error: function a.f is deprecated: deprecated decorated function |
| 10921 |
main:2: error: function a.f is deprecated: deprecated decorated function |
| 10922 |
main:5: error: function a.f is deprecated: deprecated decorated function |
| 10923 |
|
| 10924 |
|
| 10925 |
[case testDeprecatedFunctionAlreadyDecorated2-only_when_nocache] |
| 10926 |
# flags: --enable-error-code=deprecated |
| 10927 |
from b import f |
| 10928 |
x: str = f() |
| 10929 |
import b |
| 10930 |
y: str = b.f() |
| 10931 |
|
| 10932 |
[file b.py] |
| 10933 |
from a import f |
| 10934 |
|
| 10935 |
[file a.py] |
| 10936 |
from typing import Callable |
| 10937 |
|
| 10938 |
def d(t: Callable[[], str]) -> Callable[[], str]: ... |
| 10939 |
|
| 10940 |
@d |
| 10941 |
def f() -> str: ... |
| 10942 |
|
| 10943 |
[file a.py.2] |
| 10944 |
from typing import Callable |
| 10945 |
from typing_extensions import deprecated |
| 10946 |
|
| 10947 |
def d(t: Callable[[], str]) -> Callable[[], str]: ... |
| 10948 |
|
| 10949 |
@deprecated("deprecated decorated function") |
| 10950 |
@d |
| 10951 |
def f() -> str: ... |
| 10952 |
|
| 10953 |
[builtins fixtures/tuple.pyi] |
| 10954 |
[out] |
| 10955 |
== |
| 10956 |
main:2: error: function a.f is deprecated: deprecated decorated function |
| 10957 |
main:5: error: function a.f is deprecated: deprecated decorated function |
| 10958 |
b.py:1: error: function a.f is deprecated: deprecated decorated function |
| 10959 |
|
| 10960 |
|
| 10961 |
[case testDeprecatedAddClassDeprecationIndirectImport1-only_when_cache] |
| 10962 |
# flags: --enable-error-code=deprecated |
| 10963 |
from b import C |
| 10964 |
x: C |
| 10965 |
C() |
| 10966 |
import b |
| 10967 |
y: b.D |
| 10968 |
b.D() |
| 10969 |
|
| 10970 |
[file b.py] |
| 10971 |
from a import C |
| 10972 |
from a import D |
| 10973 |
|
| 10974 |
[file a.py] |
| 10975 |
class C: ... |
| 10976 |
class D: ... |
| 10977 |
|
| 10978 |
[file a.py.2] |
| 10979 |
from typing_extensions import deprecated |
| 10980 |
|
| 10981 |
@deprecated("use C2 instead") |
| 10982 |
class C: ... |
| 10983 |
|
| 10984 |
@deprecated("use D2 instead") |
| 10985 |
class D: ... |
| 10986 |
|
| 10987 |
[builtins fixtures/tuple.pyi] |
| 10988 |
[out] |
| 10989 |
== |
| 10990 |
b.py:1: error: class a.C is deprecated: use C2 instead |
| 10991 |
b.py:2: error: class a.D is deprecated: use D2 instead |
| 10992 |
main:2: error: class a.C is deprecated: use C2 instead |
| 10993 |
main:6: error: class a.D is deprecated: use D2 instead |
| 10994 |
main:7: error: class a.D is deprecated: use D2 instead |
| 10995 |
|
| 10996 |
|
| 10997 |
[case testDeprecatedAddClassDeprecationIndirectImport2-only_when_nocache] |
| 10998 |
# flags: --enable-error-code=deprecated |
| 10999 |
from b import C |
| 11000 |
x: C |
| 11001 |
C() |
| 11002 |
import b |
| 11003 |
y: b.D |
| 11004 |
b.D() |
| 11005 |
|
| 11006 |
[file b.py] |
| 11007 |
from a import C |
| 11008 |
from a import D |
| 11009 |
|
| 11010 |
[file a.py] |
| 11011 |
class C: ... |
| 11012 |
class D: ... |
| 11013 |
|
| 11014 |
[file a.py.2] |
| 11015 |
from typing_extensions import deprecated |
| 11016 |
|
| 11017 |
@deprecated("use C2 instead") |
| 11018 |
class C: ... |
| 11019 |
|
| 11020 |
@deprecated("use D2 instead") |
| 11021 |
class D: ... |
| 11022 |
|
| 11023 |
[builtins fixtures/tuple.pyi] |
| 11024 |
[out] |
| 11025 |
== |
| 11026 |
main:2: error: class a.C is deprecated: use C2 instead |
| 11027 |
main:6: error: class a.D is deprecated: use D2 instead |
| 11028 |
main:7: error: class a.D is deprecated: use D2 instead |
| 11029 |
b.py:1: error: class a.C is deprecated: use C2 instead |
| 11030 |
b.py:2: error: class a.D is deprecated: use D2 instead |
| 11031 |
|
| 11032 |
|
| 11033 |
[case testDeprecatedAddKeepChangeAndRemoveOverloadedFunctionDeprecation] |
| 11034 |
# flags: --enable-error-code=deprecated |
| 11035 |
|
| 11036 |
from a import f |
| 11037 |
f(1) |
| 11038 |
f("y") |
| 11039 |
import a |
| 11040 |
a.f(1) |
| 11041 |
a.f("y") |
| 11042 |
|
| 11043 |
[file a.py] |
| 11044 |
from typing import overload, Union |
| 11045 |
@overload |
| 11046 |
def f(x: int) -> int: ... |
| 11047 |
@overload |
| 11048 |
def f(x: str) -> str: ... |
| 11049 |
def f(x: Union[int, str]) -> Union[int, str]: ... |
| 11050 |
|
| 11051 |
[file a.py.2] |
| 11052 |
from typing import overload, Union |
| 11053 |
from typing_extensions import deprecated |
| 11054 |
@overload |
| 11055 |
def f(x: int) -> int: ... |
| 11056 |
@overload |
| 11057 |
@deprecated("pass int") |
| 11058 |
def f(x: str) -> str: ... |
| 11059 |
def f(x: Union[int, str]) -> Union[int, str]: ... |
| 11060 |
|
| 11061 |
[file a.py.3] |
| 11062 |
from typing import overload, Union |
| 11063 |
from typing_extensions import deprecated |
| 11064 |
@overload |
| 11065 |
def f(x: int) -> int: ... |
| 11066 |
@overload |
| 11067 |
@deprecated("pass int") |
| 11068 |
def f(x: str) -> str: ... |
| 11069 |
def f(x: Union[int, str]) -> Union[int, str]: ... |
| 11070 |
|
| 11071 |
[file a.py.4] |
| 11072 |
from typing import overload, Union |
| 11073 |
from typing_extensions import deprecated |
| 11074 |
@overload |
| 11075 |
def f(x: int) -> int: ... |
| 11076 |
@overload |
| 11077 |
@deprecated("pass int, please") |
| 11078 |
def f(x: str) -> str: ... |
| 11079 |
def f(x: Union[int, str]) -> Union[int, str]: ... |
| 11080 |
|
| 11081 |
[file a.py.5] |
| 11082 |
from typing import overload, Union |
| 11083 |
@overload |
| 11084 |
def f(x: int) -> int: ... |
| 11085 |
@overload |
| 11086 |
def f(x: str) -> str: ... |
| 11087 |
def f(x: Union[int, str]) -> Union[int, str]: ... |
| 11088 |
|
| 11089 |
[builtins fixtures/tuple.pyi] |
| 11090 |
[out] |
| 11091 |
== |
| 11092 |
main:5: error: overload def (x: builtins.str) -> builtins.str of function a.f is deprecated: pass int |
| 11093 |
main:8: error: overload def (x: builtins.str) -> builtins.str of function a.f is deprecated: pass int |
| 11094 |
== |
| 11095 |
main:5: error: overload def (x: builtins.str) -> builtins.str of function a.f is deprecated: pass int |
| 11096 |
main:8: error: overload def (x: builtins.str) -> builtins.str of function a.f is deprecated: pass int |
| 11097 |
== |
| 11098 |
main:5: error: overload def (x: builtins.str) -> builtins.str of function a.f is deprecated: pass int, please |
| 11099 |
main:8: error: overload def (x: builtins.str) -> builtins.str of function a.f is deprecated: pass int, please |
| 11100 |
== |
| 11101 |
|
| 11102 |
|
| 11103 |
[case testDeprecatedRemoveOverloadedFunctionDeprecation] |
| 11104 |
# flags: --enable-error-code=deprecated |
| 11105 |
|
| 11106 |
from a import f |
| 11107 |
f(1) |
| 11108 |
f("y") |
| 11109 |
import a |
| 11110 |
a.f(1) |
| 11111 |
a.f("y") |
| 11112 |
|
| 11113 |
[file a.py] |
| 11114 |
from typing import overload, Union |
| 11115 |
from typing_extensions import deprecated |
| 11116 |
@overload |
| 11117 |
def f(x: int) -> int: ... |
| 11118 |
@overload |
| 11119 |
@deprecated("pass int") |
| 11120 |
def f(x: str) -> str: ... |
| 11121 |
def f(x: Union[int, str]) -> Union[int, str]: ... |
| 11122 |
|
| 11123 |
[file a.py.2] |
| 11124 |
from typing import overload, Union |
| 11125 |
@overload |
| 11126 |
def f(x: int) -> int: ... |
| 11127 |
@overload |
| 11128 |
def f(x: str) -> str: ... |
| 11129 |
def f(x: Union[int, str]) -> Union[int, str]: ... |
| 11130 |
|
| 11131 |
[builtins fixtures/tuple.pyi] |
| 11132 |
[out] |
| 11133 |
main:5: error: overload def (x: builtins.str) -> builtins.str of function a.f is deprecated: pass int |
| 11134 |
main:8: error: overload def (x: builtins.str) -> builtins.str of function a.f is deprecated: pass int |
| 11135 |
== |
| 11136 |
|
| 11137 |
|
| 11138 |
[case testDeprecatedKeepOverloadedFunctionDeprecation] |
| 11139 |
# flags: --enable-error-code=deprecated |
| 11140 |
|
| 11141 |
from a import f |
| 11142 |
f(1) |
| 11143 |
f("y") |
| 11144 |
import a |
| 11145 |
a.f(1) |
| 11146 |
a.f("y") |
| 11147 |
|
| 11148 |
[file a.py] |
| 11149 |
from typing import overload, Union |
| 11150 |
from typing_extensions import deprecated |
| 11151 |
@overload |
| 11152 |
def f(x: int) -> int: ... |
| 11153 |
@overload |
| 11154 |
@deprecated("pass int") |
| 11155 |
def f(x: str) -> str: ... |
| 11156 |
def f(x: Union[int, str]) -> Union[int, str]: ... |
| 11157 |
|
| 11158 |
[file a.py.2] |
| 11159 |
from typing import overload, Union |
| 11160 |
from typing_extensions import deprecated |
| 11161 |
@overload |
| 11162 |
def f(x: int) -> int: ... |
| 11163 |
@overload |
| 11164 |
@deprecated("pass int") |
| 11165 |
def f(x: str) -> str: ... |
| 11166 |
def f(x: Union[int, str]) -> Union[int, str]: ... |
| 11167 |
|
| 11168 |
[builtins fixtures/tuple.pyi] |
| 11169 |
[out] |
| 11170 |
main:5: error: overload def (x: builtins.str) -> builtins.str of function a.f is deprecated: pass int |
| 11171 |
main:8: error: overload def (x: builtins.str) -> builtins.str of function a.f is deprecated: pass int |
| 11172 |
== |
| 11173 |
main:5: error: overload def (x: builtins.str) -> builtins.str of function a.f is deprecated: pass int |
| 11174 |
main:8: error: overload def (x: builtins.str) -> builtins.str of function a.f is deprecated: pass int |
| 11175 |
|
| 11176 |
|
| 11177 |
[case testDeprecatedAddOverloadedFunctionDeprecationIndirectImport] |
| 11178 |
# flags: --enable-error-code=deprecated |
| 11179 |
|
| 11180 |
from b import f |
| 11181 |
f(1) |
| 11182 |
f("y") |
| 11183 |
import b |
| 11184 |
b.f(1) |
| 11185 |
b.f("y") |
| 11186 |
|
| 11187 |
[file b.py] |
| 11188 |
from a import f |
| 11189 |
|
| 11190 |
[file a.py] |
| 11191 |
from typing import overload, Union |
| 11192 |
@overload |
| 11193 |
def f(x: int) -> int: ... |
| 11194 |
@overload |
| 11195 |
def f(x: str) -> str: ... |
| 11196 |
def f(x: Union[int, str]) -> Union[int, str]: ... |
| 11197 |
|
| 11198 |
[file a.py.2] |
| 11199 |
from typing import overload, Union |
| 11200 |
from typing_extensions import deprecated |
| 11201 |
@overload |
| 11202 |
def f(x: int) -> int: ... |
| 11203 |
@overload |
| 11204 |
@deprecated("pass int") |
| 11205 |
def f(x: str) -> str: ... |
| 11206 |
def f(x: Union[int, str]) -> Union[int, str]: ... |
| 11207 |
|
| 11208 |
[builtins fixtures/tuple.pyi] |
| 11209 |
[out] |
| 11210 |
== |
| 11211 |
main:5: error: overload def (x: builtins.str) -> builtins.str of function a.f is deprecated: pass int |
| 11212 |
main:8: error: overload def (x: builtins.str) -> builtins.str of function a.f is deprecated: pass int |
| 11213 |
|
| 11214 |
|
| 11215 |
[case testDeprecatedChangeOverloadedFunctionDeprecationIndirectImport] |
| 11216 |
# flags: --enable-error-code=deprecated |
| 11217 |
|
| 11218 |
from b import f |
| 11219 |
f(1) |
| 11220 |
f("y") |
| 11221 |
import b |
| 11222 |
b.f(1) |
| 11223 |
b.f("y") |
| 11224 |
|
| 11225 |
[file b.py] |
| 11226 |
from a import f |
| 11227 |
|
| 11228 |
[file a.py] |
| 11229 |
from typing import overload, Union |
| 11230 |
from typing_extensions import deprecated |
| 11231 |
@overload |
| 11232 |
def f(x: int) -> int: ... |
| 11233 |
@overload |
| 11234 |
@deprecated("pass int") |
| 11235 |
def f(x: str) -> str: ... |
| 11236 |
def f(x: Union[int, str]) -> Union[int, str]: ... |
| 11237 |
|
| 11238 |
[file a.py.2] |
| 11239 |
from typing import overload, Union |
| 11240 |
from typing_extensions import deprecated |
| 11241 |
@overload |
| 11242 |
def f(x: int) -> int: ... |
| 11243 |
@overload |
| 11244 |
@deprecated("pass int, please") |
| 11245 |
def f(x: str) -> str: ... |
| 11246 |
def f(x: Union[int, str]) -> Union[int, str]: ... |
| 11247 |
|
| 11248 |
[builtins fixtures/tuple.pyi] |
| 11249 |
[out] |
| 11250 |
main:5: error: overload def (x: builtins.str) -> builtins.str of function a.f is deprecated: pass int |
| 11251 |
main:8: error: overload def (x: builtins.str) -> builtins.str of function a.f is deprecated: pass int |
| 11252 |
== |
| 11253 |
main:5: error: overload def (x: builtins.str) -> builtins.str of function a.f is deprecated: pass int, please |
| 11254 |
main:8: error: overload def (x: builtins.str) -> builtins.str of function a.f is deprecated: pass int, please |
| 11255 |
|
| 11256 |
|
| 11257 |
[case testDeprecatedRemoveOverloadedFunctionDeprecationIndirectImport] |
| 11258 |
# flags: --enable-error-code=deprecated |
| 11259 |
|
| 11260 |
from b import f |
| 11261 |
f(1) |
| 11262 |
f("y") |
| 11263 |
import b |
| 11264 |
b.f(1) |
| 11265 |
b.f("y") |
| 11266 |
|
| 11267 |
[file b.py] |
| 11268 |
from a import f |
| 11269 |
|
| 11270 |
[file a.py] |
| 11271 |
from typing import overload, Union |
| 11272 |
from typing_extensions import deprecated |
| 11273 |
@overload |
| 11274 |
def f(x: int) -> int: ... |
| 11275 |
@overload |
| 11276 |
@deprecated("pass int") |
| 11277 |
def f(x: str) -> str: ... |
| 11278 |
def f(x: Union[int, str]) -> Union[int, str]: ... |
| 11279 |
|
| 11280 |
[file a.py.2] |
| 11281 |
from typing import overload, Union |
| 11282 |
@overload |
| 11283 |
def f(x: int) -> int: ... |
| 11284 |
@overload |
| 11285 |
def f(x: str) -> str: ... |
| 11286 |
def f(x: Union[int, str]) -> Union[int, str]: ... |
| 11287 |
|
| 11288 |
[builtins fixtures/tuple.pyi] |
| 11289 |
[out] |
| 11290 |
main:5: error: overload def (x: builtins.str) -> builtins.str of function a.f is deprecated: pass int |
| 11291 |
main:8: error: overload def (x: builtins.str) -> builtins.str of function a.f is deprecated: pass int |
| 11292 |
== |
| 11293 |
|
| 11294 |
|
| 11295 |
[case testDeprecatedOverloadedFunctionAlreadyDecorated] |
| 11296 |
# flags: --enable-error-code=deprecated |
| 11297 |
|
| 11298 |
from b import f |
| 11299 |
f(1) |
| 11300 |
f("y") |
| 11301 |
import b |
| 11302 |
b.f(1) |
| 11303 |
b.f("y") |
| 11304 |
|
| 11305 |
[file b.py] |
| 11306 |
from a import f |
| 11307 |
|
| 11308 |
[file a.py] |
| 11309 |
from typing import Callable, overload, Union |
| 11310 |
|
| 11311 |
def d(t: Callable[[str], str]) -> Callable[[str], str]: ... |
| 11312 |
|
| 11313 |
@overload |
| 11314 |
def f(x: int) -> int: ... |
| 11315 |
@overload |
| 11316 |
@d |
| 11317 |
def f(x: str) -> str: ... |
| 11318 |
def f(x: Union[int, str]) -> Union[int, str]: ... |
| 11319 |
|
| 11320 |
[file a.py.2] |
| 11321 |
from typing import Callable, overload, Union |
| 11322 |
from typing_extensions import deprecated |
| 11323 |
|
| 11324 |
def d(t: Callable[[str], str]) -> Callable[[str], str]: ... |
| 11325 |
|
| 11326 |
@overload |
| 11327 |
def f(x: int) -> int: ... |
| 11328 |
@overload |
| 11329 |
@deprecated("deprecated decorated overload") |
| 11330 |
@d |
| 11331 |
def f(x: str) -> str: ... |
| 11332 |
def f(x: Union[int, str]) -> Union[int, str]: ... |
| 11333 |
|
| 11334 |
[builtins fixtures/tuple.pyi] |
| 11335 |
[out] |
| 11336 |
== |
| 11337 |
main:5: error: overload def (x: builtins.str) -> builtins.str of function a.f is deprecated: deprecated decorated overload |
| 11338 |
main:8: error: overload def (x: builtins.str) -> builtins.str of function a.f is deprecated: deprecated decorated overload |
| 11339 |
|
| 11340 |
|
| 11341 |
[case testDeprecatedChangeClassDeprecationIndirectImport] |
| 11342 |
# flags: --enable-error-code=deprecated |
| 11343 |
from b import C |
| 11344 |
x: C |
| 11345 |
C() |
| 11346 |
import b |
| 11347 |
y: b.D |
| 11348 |
b.D() |
| 11349 |
|
| 11350 |
[file b.py] |
| 11351 |
from a import C |
| 11352 |
from a import D |
| 11353 |
|
| 11354 |
[file a.py] |
| 11355 |
from typing_extensions import deprecated |
| 11356 |
|
| 11357 |
@deprecated("use C1 instead") |
| 11358 |
class C: ... |
| 11359 |
@deprecated("use D1 instead") |
| 11360 |
class D: ... |
| 11361 |
|
| 11362 |
[file a.py.2] |
| 11363 |
from typing_extensions import deprecated |
| 11364 |
|
| 11365 |
@deprecated("use C2 instead") |
| 11366 |
class C: ... |
| 11367 |
|
| 11368 |
@deprecated("use D2 instead") |
| 11369 |
class D: ... |
| 11370 |
|
| 11371 |
[builtins fixtures/tuple.pyi] |
| 11372 |
[out] |
| 11373 |
b.py:1: error: class a.C is deprecated: use C1 instead |
| 11374 |
b.py:2: error: class a.D is deprecated: use D1 instead |
| 11375 |
main:2: error: class a.C is deprecated: use C1 instead |
| 11376 |
main:6: error: class a.D is deprecated: use D1 instead |
| 11377 |
main:7: error: class a.D is deprecated: use D1 instead |
| 11378 |
== |
| 11379 |
b.py:1: error: class a.C is deprecated: use C2 instead |
| 11380 |
b.py:2: error: class a.D is deprecated: use D2 instead |
| 11381 |
main:2: error: class a.C is deprecated: use C2 instead |
| 11382 |
main:6: error: class a.D is deprecated: use D2 instead |
| 11383 |
main:7: error: class a.D is deprecated: use D2 instead |
| 11384 |
|
| 11385 |
|
| 11386 |
[case testDeprecatedRemoveClassDeprecationIndirectImport] |
| 11387 |
# flags: --enable-error-code=deprecated |
| 11388 |
from b import C |
| 11389 |
x: C |
| 11390 |
C() |
| 11391 |
import b |
| 11392 |
y: b.D |
| 11393 |
b.D() |
| 11394 |
|
| 11395 |
[file b.py] |
| 11396 |
from a import C |
| 11397 |
from a import D |
| 11398 |
|
| 11399 |
[file a.py] |
| 11400 |
from typing_extensions import deprecated |
| 11401 |
|
| 11402 |
@deprecated("use C1 instead") |
| 11403 |
class C: ... |
| 11404 |
@deprecated("use D1 instead") |
| 11405 |
class D: ... |
| 11406 |
|
| 11407 |
[file a.py.2] |
| 11408 |
class C: ... |
| 11409 |
class D: ... |
| 11410 |
|
| 11411 |
[builtins fixtures/tuple.pyi] |
| 11412 |
[out] |
| 11413 |
b.py:1: error: class a.C is deprecated: use C1 instead |
| 11414 |
b.py:2: error: class a.D is deprecated: use D1 instead |
| 11415 |
main:2: error: class a.C is deprecated: use C1 instead |
| 11416 |
main:6: error: class a.D is deprecated: use D1 instead |
| 11417 |
main:7: error: class a.D is deprecated: use D1 instead |
| 11418 |
== |
| 11419 |
|
| 11420 |
|
| 11421 |
[case testDeprecatedAddClassDeprecationIndirectImportAlreadyDecorated1-only_when_cache] |
| 11422 |
# flags: --enable-error-code=deprecated |
| 11423 |
from b import C |
| 11424 |
x: C |
| 11425 |
C() |
| 11426 |
import b |
| 11427 |
y: b.D |
| 11428 |
b.D() |
| 11429 |
|
| 11430 |
[file b.py] |
| 11431 |
from a import C |
| 11432 |
from a import D |
| 11433 |
|
| 11434 |
[file a.py] |
| 11435 |
from typing import TypeVar |
| 11436 |
|
| 11437 |
T = TypeVar("T") |
| 11438 |
def dec(x: T) -> T: ... |
| 11439 |
|
| 11440 |
@dec |
| 11441 |
class C: ... |
| 11442 |
@dec |
| 11443 |
class D: ... |
| 11444 |
|
| 11445 |
[file a.py.2] |
| 11446 |
from typing_extensions import deprecated |
| 11447 |
|
| 11448 |
@deprecated("use C2 instead") |
| 11449 |
class C: ... |
| 11450 |
|
| 11451 |
@deprecated("use D2 instead") |
| 11452 |
class D: ... |
| 11453 |
|
| 11454 |
[builtins fixtures/tuple.pyi] |
| 11455 |
[out] |
| 11456 |
== |
| 11457 |
b.py:1: error: class a.C is deprecated: use C2 instead |
| 11458 |
b.py:2: error: class a.D is deprecated: use D2 instead |
| 11459 |
main:2: error: class a.C is deprecated: use C2 instead |
| 11460 |
main:6: error: class a.D is deprecated: use D2 instead |
| 11461 |
main:7: error: class a.D is deprecated: use D2 instead |
| 11462 |
|
| 11463 |
|
| 11464 |
[case testDeprecatedAddClassDeprecationIndirectImportAlreadyDecorated2-only_when_nocache] |
| 11465 |
# flags: --enable-error-code=deprecated |
| 11466 |
from b import C |
| 11467 |
x: C |
| 11468 |
C() |
| 11469 |
import b |
| 11470 |
y: b.D |
| 11471 |
b.D() |
| 11472 |
|
| 11473 |
[file b.py] |
| 11474 |
from a import C |
| 11475 |
from a import D |
| 11476 |
|
| 11477 |
[file a.py] |
| 11478 |
from typing import TypeVar |
| 11479 |
|
| 11480 |
T = TypeVar("T") |
| 11481 |
def dec(x: T) -> T: ... |
| 11482 |
|
| 11483 |
@dec |
| 11484 |
class C: ... |
| 11485 |
@dec |
| 11486 |
class D: ... |
| 11487 |
|
| 11488 |
[file a.py.2] |
| 11489 |
from typing_extensions import deprecated |
| 11490 |
|
| 11491 |
@deprecated("use C2 instead") |
| 11492 |
class C: ... |
| 11493 |
|
| 11494 |
@deprecated("use D2 instead") |
| 11495 |
class D: ... |
| 11496 |
|
| 11497 |
[builtins fixtures/tuple.pyi] |
| 11498 |
[out] |
| 11499 |
== |
| 11500 |
main:2: error: class a.C is deprecated: use C2 instead |
| 11501 |
main:6: error: class a.D is deprecated: use D2 instead |
| 11502 |
main:7: error: class a.D is deprecated: use D2 instead |
| 11503 |
b.py:1: error: class a.C is deprecated: use C2 instead |
| 11504 |
b.py:2: error: class a.D is deprecated: use D2 instead |
| 11505 |
|
| 11506 |
[case testPropertySetterTypeFineGrained] |
| 11507 |
from a import A |
| 11508 |
a = A() |
| 11509 |
a.f = '' |
| 11510 |
[file a.py] |
| 11511 |
class A: |
| 11512 |
@property |
| 11513 |
def f(self) -> int: |
| 11514 |
return 1 |
| 11515 |
@f.setter |
| 11516 |
def f(self, x: str) -> None: |
| 11517 |
pass |
| 11518 |
[file a.py.2] |
| 11519 |
class A: |
| 11520 |
@property |
| 11521 |
def f(self) -> int: |
| 11522 |
return 1 |
| 11523 |
@f.setter |
| 11524 |
def f(self, x: int) -> None: |
| 11525 |
pass |
| 11526 |
[builtins fixtures/property.pyi] |
| 11527 |
[out] |
| 11528 |
== |
| 11529 |
main:3: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| 11530 |
|
| 11531 |
[case testPropertyDeleteSetterFineGrained] |
| 11532 |
from a import A |
| 11533 |
a = A() |
| 11534 |
a.f = 1 |
| 11535 |
[file a.py] |
| 11536 |
class A: |
| 11537 |
@property |
| 11538 |
def f(self) -> int: |
| 11539 |
return 1 |
| 11540 |
@f.setter |
| 11541 |
def f(self, x: int) -> None: |
| 11542 |
pass |
| 11543 |
[file a.py.2] |
| 11544 |
class A: |
| 11545 |
@property |
| 11546 |
def f(self) -> int: |
| 11547 |
return 1 |
| 11548 |
@f.deleter |
| 11549 |
def f(self) -> None: |
| 11550 |
pass |
| 11551 |
[builtins fixtures/property.pyi] |
| 11552 |
[out] |
| 11553 |
== |
| 11554 |
main:3: error: Property "f" defined in "A" is read-only |
| 11555 |
|
| 11556 |
[case testMethodMakeBoundFineGrained] |
| 11557 |
from a import A |
| 11558 |
a = A() |
| 11559 |
a.f() |
| 11560 |
[file a.py] |
| 11561 |
class B: |
| 11562 |
def f(self, s: A) -> int: ... |
| 11563 |
|
| 11564 |
def f(s: A) -> int: ... |
| 11565 |
|
| 11566 |
class A: |
| 11567 |
f = f |
| 11568 |
[file a.py.2] |
| 11569 |
class B: |
| 11570 |
def f(self, s: A) -> int: ... |
| 11571 |
|
| 11572 |
def f(s: A) -> int: ... |
| 11573 |
|
| 11574 |
class A: |
| 11575 |
f = B().f |
| 11576 |
[out] |
| 11577 |
== |
| 11578 |
main:3: error: Too few arguments |
| 11579 |
|
| 11580 |
[case testFineGrainedParamSpecPrefixUpdateMethod] |
| 11581 |
import impl |
| 11582 |
[file impl.py] |
| 11583 |
from typing_extensions import ParamSpec |
| 11584 |
from lib import Sub |
| 11585 |
|
| 11586 |
P = ParamSpec("P") |
| 11587 |
class Impl(Sub[P]): |
| 11588 |
def test(self, *args: P.args, **kwargs: P.kwargs) -> None: |
| 11589 |
self.meth(1, *args, **kwargs) |
| 11590 |
|
| 11591 |
[file lib.py] |
| 11592 |
from typing import Generic |
| 11593 |
from typing_extensions import ParamSpec, Concatenate |
| 11594 |
|
| 11595 |
P = ParamSpec("P") |
| 11596 |
class Base(Generic[P]): |
| 11597 |
def meth(self, *args: P.args, **kwargs: P.kwargs) -> None: ... |
| 11598 |
class Sub(Base[Concatenate[int, P]]): ... |
| 11599 |
|
| 11600 |
[file lib.py.2] |
| 11601 |
from typing import Generic |
| 11602 |
from typing_extensions import ParamSpec, Concatenate |
| 11603 |
|
| 11604 |
P = ParamSpec("P") |
| 11605 |
class Base(Generic[P]): |
| 11606 |
def meth(self, *args: P.args, **kwargs: P.kwargs) -> None: ... |
| 11607 |
class Sub(Base[Concatenate[str, P]]): ... |
| 11608 |
[builtins fixtures/paramspec.pyi] |
| 11609 |
[out] |
| 11610 |
== |
| 11611 |
impl.py:7: error: Argument 1 to "meth" of "Base" has incompatible type "int"; expected "str" |
| 11612 |
|
| 11613 |
[case testFineGrainedUnexpectedKeywordArgument] |
| 11614 |
import a |
| 11615 |
[file a.py] |
| 11616 |
import b |
| 11617 |
[file a.py.2] |
| 11618 |
import b |
| 11619 |
b.lol(uhhhh=12) |
| 11620 |
[file b.py] |
| 11621 |
def lol() -> None: pass |
| 11622 |
[out] |
| 11623 |
== |
| 11624 |
a.py:2: error: Unexpected keyword argument "uhhhh" for "lol" |
| 11625 |
a.py:2: note: "lol" defined in "b" |
| 11626 |
|
| 11627 |
[case testPartialNoneTypeFineInClass] |
| 11628 |
from typing import Optional |
| 11629 |
from m import C |
| 11630 |
def foo(x: C) -> Optional[int]: |
| 11631 |
return x.x |
| 11632 |
[file m.py] |
| 11633 |
from n import f |
| 11634 |
class C: |
| 11635 |
x = None |
| 11636 |
def foo(self) -> None: |
| 11637 |
self.x = f() |
| 11638 |
[file n.py] |
| 11639 |
def f() -> int: ... |
| 11640 |
[file n.py.2] |
| 11641 |
def f() -> str: ... |
| 11642 |
[out] |
| 11643 |
== |
| 11644 |
main:4: error: Incompatible return value type (got "str | None", expected "int | None") |
| 11645 |
|
| 11646 |
[case testPartialNoneTypeFineInClassDecorated] |
| 11647 |
from typing import Optional |
| 11648 |
from m import C |
| 11649 |
def foo(x: C) -> Optional[int]: |
| 11650 |
return x.x |
| 11651 |
[file m.py] |
| 11652 |
from typing import TypeVar |
| 11653 |
from n import f |
| 11654 |
|
| 11655 |
F = TypeVar("F") |
| 11656 |
def dec(fn: F) -> F: ... |
| 11657 |
|
| 11658 |
class C: |
| 11659 |
x = None |
| 11660 |
@dec |
| 11661 |
def foo(self) -> None: |
| 11662 |
self.x = f() |
| 11663 |
[file n.py] |
| 11664 |
def f() -> int: ... |
| 11665 |
[file n.py.2] |
| 11666 |
def f() -> str: ... |
| 11667 |
[out] |
| 11668 |
== |
| 11669 |
main:4: error: Incompatible return value type (got "str | None", expected "int | None") |
| 11670 |
|
| 11671 |
[case testPartialNoneTypeFineInClassOverload] |
| 11672 |
from typing import Optional |
| 11673 |
from m import C |
| 11674 |
def foo(x: C) -> Optional[int]: |
| 11675 |
return x.x |
| 11676 |
[file m.py] |
| 11677 |
from typing import overload |
| 11678 |
from n import f |
| 11679 |
|
| 11680 |
class C: |
| 11681 |
x = None |
| 11682 |
@overload |
| 11683 |
def foo(self) -> None: ... |
| 11684 |
@overload |
| 11685 |
def foo(self, x: int) -> None: ... |
| 11686 |
def foo(self, x: int = 0) -> None: |
| 11687 |
self.x = f() |
| 11688 |
[file n.py] |
| 11689 |
def f() -> int: ... |
| 11690 |
[file n.py.2] |
| 11691 |
def f() -> str: ... |
| 11692 |
[out] |
| 11693 |
== |
| 11694 |
main:4: error: Incompatible return value type (got "str | None", expected "int | None") |
| 11695 |
|
| 11696 |
[case testPartialNoneTypeFineInClassNested] |
| 11697 |
from typing import Optional |
| 11698 |
from m import C |
| 11699 |
def foo(x: C) -> Optional[int]: |
| 11700 |
return x.x |
| 11701 |
[file m.py] |
| 11702 |
from typing import TypeVar |
| 11703 |
from n import f |
| 11704 |
|
| 11705 |
F = TypeVar("F") |
| 11706 |
def dec(fn: F) -> F: ... |
| 11707 |
|
| 11708 |
class C: |
| 11709 |
x = None |
| 11710 |
def foo(self) -> None: |
| 11711 |
@dec |
| 11712 |
def setup() -> None: |
| 11713 |
self.x = f() |
| 11714 |
[file n.py] |
| 11715 |
def f() -> int: ... |
| 11716 |
[file n.py.2] |
| 11717 |
def f() -> str: ... |
| 11718 |
[out] |
| 11719 |
== |
| 11720 |
main:4: error: Incompatible return value type (got "str | None", expected "int | None") |
| 11721 |
|
| 11722 |
[case testPartialNoneTypeFineModuleGlobal] |
| 11723 |
from typing import Optional |
| 11724 |
import m |
| 11725 |
def foo() -> Optional[int]: |
| 11726 |
return m.x |
| 11727 |
[file m.py] |
| 11728 |
from n import f |
| 11729 |
|
| 11730 |
x = None |
| 11731 |
def foo() -> None: |
| 11732 |
global x |
| 11733 |
x = f() |
| 11734 |
[file n.py] |
| 11735 |
def f() -> int: ... |
| 11736 |
[file n.py.2] |
| 11737 |
def f() -> str: ... |
| 11738 |
[out] |
| 11739 |
== |
| 11740 |
main:4: error: Incompatible return value type (got "str | None", expected "int | None") |
| 11741 |
|
| 11742 |
[case testPartialNoneTypeFineModuleGlobalNested] |
| 11743 |
from typing import Optional |
| 11744 |
import m |
| 11745 |
def foo() -> Optional[int]: |
| 11746 |
return m.x |
| 11747 |
[file m.py] |
| 11748 |
from n import f |
| 11749 |
|
| 11750 |
x = None |
| 11751 |
def foo() -> None: |
| 11752 |
def bar() -> None: |
| 11753 |
global x |
| 11754 |
x = f() |
| 11755 |
[file n.py] |
| 11756 |
def f() -> int: ... |
| 11757 |
[file n.py.2] |
| 11758 |
def f() -> str: ... |
| 11759 |
[out] |
| 11760 |
== |
| 11761 |
main:4: error: Incompatible return value type (got "str | None", expected "int | None") |
| 11762 |
|
| 11763 |
[case testGlobalNoneWidenedInFuncWithRedefinition1] |
| 11764 |
import m |
| 11765 |
reveal_type(m.x) |
| 11766 |
|
| 11767 |
[file m.py] |
| 11768 |
# mypy: allow-redefinition |
| 11769 |
import m2 |
| 11770 |
|
| 11771 |
x = None |
| 11772 |
|
| 11773 |
def foo() -> None: |
| 11774 |
global x |
| 11775 |
x = m2.bar() |
| 11776 |
|
| 11777 |
[file m2.py] |
| 11778 |
def bar() -> int: return 0 |
| 11779 |
|
| 11780 |
[file m2.py.2] |
| 11781 |
def bar() -> str: return "a" |
| 11782 |
|
| 11783 |
[out] |
| 11784 |
main:2: note: Revealed type is "None | builtins.int" |
| 11785 |
== |
| 11786 |
main:2: note: Revealed type is "None | builtins.str" |
| 11787 |
|
| 11788 |
[case testGlobalNoneWidenedInFuncWithRedefinition2] |
| 11789 |
import m |
| 11790 |
reveal_type(m.x) |
| 11791 |
|
| 11792 |
[file m.py] |
| 11793 |
# mypy: allow-redefinition |
| 11794 |
import m2 |
| 11795 |
|
| 11796 |
x = None |
| 11797 |
|
| 11798 |
def deco(f): return f |
| 11799 |
|
| 11800 |
class C: |
| 11801 |
@deco |
| 11802 |
def foo(self) -> None: |
| 11803 |
global x |
| 11804 |
x = m2.bar() |
| 11805 |
|
| 11806 |
[file m2.py] |
| 11807 |
def bar() -> int: return 0 |
| 11808 |
|
| 11809 |
[file m2.py.2] |
| 11810 |
def bar() -> str: return "a" |
| 11811 |
|
| 11812 |
[out] |
| 11813 |
main:2: note: Revealed type is "None | builtins.int" |
| 11814 |
== |
| 11815 |
main:2: note: Revealed type is "None | builtins.str" |
| 11816 |
|
| 11817 |
[case testGlobalNoneWidenedInFuncWithRedefinition3] |
| 11818 |
import m |
| 11819 |
reveal_type(m.x) |
| 11820 |
|
| 11821 |
[file m.py] |
| 11822 |
# mypy: allow-redefinition |
| 11823 |
import m2 |
| 11824 |
|
| 11825 |
x = None |
| 11826 |
|
| 11827 |
def foo() -> None: |
| 11828 |
def nested(self) -> None: |
| 11829 |
global x |
| 11830 |
x = m2.bar() |
| 11831 |
|
| 11832 |
[file m2.py] |
| 11833 |
def bar() -> int: return 0 |
| 11834 |
|
| 11835 |
[file m2.py.2] |
| 11836 |
def bar() -> str: return "a" |
| 11837 |
|
| 11838 |
[out] |
| 11839 |
main:2: note: Revealed type is "None | builtins.int" |
| 11840 |
== |
| 11841 |
main:2: note: Revealed type is "None | builtins.str" |