@@ -388,17 +388,54 @@ class A: pass
388
388
389
389
[case testDefaultArgumentExpressions2]
390
390
import typing
391
- def f(x: 'A' = B()) -> None: # E: Incompatible types in assignment (expression has type "B", variable has type "A")
391
+ def f(x: 'A' = B()) -> None: # E: Incompatible default for argument "x" (default has type "B", argument has type "A")
392
392
b = x # type: B # E: Incompatible types in assignment (expression has type "A", variable has type "B")
393
393
a = x # type: A
394
394
395
395
class B: pass
396
396
class A: pass
397
- [out]
397
+
398
+ [case testDefaultArgumentExpressionsGeneric]
399
+ from typing import TypeVar
400
+ T = TypeVar('T', bound='A')
401
+ def f(x: T = B()) -> None: # E: Incompatible default for argument "x" (default has type "B", argument has type "T")
402
+ b = x # type: B # E: Incompatible types in assignment (expression has type "T", variable has type "B")
403
+ a = x # type: A
404
+
405
+ class B: pass
406
+ class A: pass
407
+
408
+ [case testDefaultArgumentExpressionsPython2]
409
+ # flags: --python-version 2.7
410
+ from typing import Tuple
411
+ def f(x = B()): # E: Incompatible default for argument "x" (default has type "B", argument has type "A")
412
+ # type: (A) -> None
413
+ b = x # type: B # E: Incompatible types in assignment (expression has type "A", variable has type "B")
414
+ a = x # type: A
415
+
416
+ class B: pass
417
+ class A: pass
418
+
419
+ [case testDefaultTupleArgumentExpressionsPython2]
420
+ # flags: --python-version 2.7
421
+ from typing import Tuple
422
+ def f((x, y) = (A(), B())): # E: Incompatible default for tuple argument 1 (default has type "Tuple[A, B]", argument has type "Tuple[B, B]")
423
+ # type: (Tuple[B, B]) -> None
424
+ b = x # type: B
425
+ a = x # type: A # E: Incompatible types in assignment (expression has type "B", variable has type "A")
426
+ def g(a, (x, y) = (A(),)): # E: Incompatible default for tuple argument 2 (default has type "Tuple[A]", argument has type "Tuple[B, B]")
427
+ # type: (int, Tuple[B, B]) -> None
428
+ pass
429
+ def h((x, y) = (A(), B(), A())): # E: Incompatible default for tuple argument 1 (default has type "Tuple[A, B, A]", argument has type "Tuple[B, B]")
430
+ # type: (Tuple[B, B]) -> None
431
+ pass
432
+
433
+ class B: pass
434
+ class A: pass
398
435
399
436
[case testDefaultArgumentsWithSubtypes]
400
437
import typing
401
- def f(x: 'B' = A()) -> None: # E: Incompatible types in assignment (expression has type "A", variable has type "B")
438
+ def f(x: 'B' = A()) -> None: # E: Incompatible default for argument "x" (default has type "A", argument has type "B")
402
439
pass
403
440
def g(x: 'A' = B()) -> None:
404
441
pass
@@ -409,7 +446,7 @@ class B(A): pass
409
446
410
447
[case testMultipleDefaultArgumentExpressions]
411
448
import typing
412
- def f(x: 'A' = B(), y: 'B' = B()) -> None: # E: Incompatible types in assignment (expression has type "B", variable has type "A")
449
+ def f(x: 'A' = B(), y: 'B' = B()) -> None: # E: Incompatible default for argument "x" (default has type "B", argument has type "A")
413
450
pass
414
451
def h(x: 'A' = A(), y: 'B' = B()) -> None:
415
452
pass
@@ -420,7 +457,7 @@ class B: pass
420
457
421
458
[case testMultipleDefaultArgumentExpressions2]
422
459
import typing
423
- def g(x: 'A' = A(), y: 'B' = A()) -> None: # E: Incompatible types in assignment (expression has type "A", variable has type "B")
460
+ def g(x: 'A' = A(), y: 'B' = A()) -> None: # E: Incompatible default for argument "y" (default has type "A", argument has type "B")
424
461
pass
425
462
426
463
class A: pass
0 commit comments