@@ -1427,38 +1427,47 @@ C(arg=0)
1427
1427
from typing import Type
1428
1428
class User: pass
1429
1429
class ProUser(User): pass
1430
- class BasicUser(User): pass
1431
1430
def new_user(user_class: Type[User]) -> User:
1432
1431
return user_class()
1433
- reveal_type(new_user(User))
1434
- reveal_type(new_user(ProUser))
1432
+ reveal_type(new_user(User)) # E: Revealed type is '__main__.User'
1433
+ reveal_type(new_user(ProUser)) # E: Revealed type is '__main__.User'
1435
1434
[out]
1436
- main:7: error: Revealed type is '__main__.User'
1437
- main:8: error: Revealed type is '__main__.User'
1438
1435
1439
1436
[case testTypeUsingTypeCTypeVar]
1440
1437
from typing import Type, TypeVar
1441
1438
class User: pass
1442
1439
class ProUser(User): pass
1443
- class BasicUser(User): pass
1444
1440
U = TypeVar('U', bound=User)
1445
1441
def new_user(user_class: Type[U]) -> U:
1446
1442
user = user_class()
1447
1443
reveal_type(user)
1448
1444
return user
1449
1445
pro_user = new_user(ProUser)
1450
- reveal_type(pro_user) # XXX Why is this ProUser*?
1446
+ reveal_type(pro_user)
1451
1447
[out]
1452
1448
main: note: In function "new_user":
1453
- main:8 : error: Revealed type is 'U`-1'
1449
+ main:7 : error: Revealed type is 'U`-1'
1454
1450
main: note: At top level:
1455
- main:11: error: Revealed type is '__main__.ProUser*'
1451
+ main:10: error: Revealed type is '__main__.ProUser*'
1452
+
1453
+ [case testTypeUsingTypeCTwoTypeVars]
1454
+ from typing import Type, TypeVar
1455
+ class User: pass
1456
+ class ProUser(User): pass
1457
+ class WizUser(ProUser): pass
1458
+ U = TypeVar('U', bound=User)
1459
+ def new_user(u_c: Type[U]) -> U: pass
1460
+ P = TypeVar('P', bound=ProUser)
1461
+ def new_pro(pro_c: Type[P]) -> P:
1462
+ return new_user(pro_c)
1463
+ wiz = new_pro(WizUser)
1464
+ reveal_type(wiz) # E: Revealed type is '__main__.WizUser*'
1465
+ [out]
1456
1466
1457
1467
[case testTypeUsingTypeCCovariance]
1458
1468
from typing import Type, TypeVar
1459
1469
class User: pass
1460
1470
class ProUser(User): pass
1461
- class BasicUser(User): pass
1462
1471
def new_user(user_class: Type[User]) -> User:
1463
1472
return user_class()
1464
1473
def new_pro_user(user_class: Type[ProUser]):
@@ -1471,10 +1480,9 @@ class User: pass
1471
1480
def new_user(user_class: Type[User]):
1472
1481
return user_class()
1473
1482
def foo(arg: Type[int]):
1474
- new_user(arg)
1483
+ new_user(arg) # E: Argument 1 to "new_user" has incompatible type Type[int]; expected Type[User]
1475
1484
[out]
1476
1485
main: note: In function "foo":
1477
- main:6: error: Argument 1 to "new_user" has incompatible type Type[int]; expected Type[User]
1478
1486
1479
1487
[case testTypeUsingTypeCUnionOverload]
1480
1488
from typing import Type, Union, overload
@@ -1489,3 +1497,23 @@ def bar(o: Type[Union[X, Y]]): pass
1489
1497
bar(X)
1490
1498
bar(Y)
1491
1499
[out]
1500
+
1501
+ [case testTypeUsingTypeCTypeAny]
1502
+ from typing import Type, Any
1503
+ def foo(arg: Type[Any]):
1504
+ x = arg()
1505
+ reveal_type(x) # E: Revealed type is 'Any'
1506
+ class X: pass
1507
+ foo(X)
1508
+ [out]
1509
+ main: note: In function "foo":
1510
+
1511
+ [case testTypeUsingTypeCTypeNoArg]
1512
+ from typing import Type
1513
+ def foo(arg: Type):
1514
+ x = arg()
1515
+ reveal_type(x) # E: Revealed type is 'Any'
1516
+ class X: pass
1517
+ foo(X)
1518
+ [out]
1519
+ main: note: In function "foo":
0 commit comments