@@ -1568,3 +1568,54 @@ class B:
1568
1568
class Derived(A, B):
1569
1569
pass
1570
1570
[builtins fixtures/dataclasses.pyi]
1571
+
1572
+ [case testDataclassGenericInheritance2]
1573
+ # flags: --python-version 3.7
1574
+ from dataclasses import dataclass
1575
+ from typing import Any, Callable, Generic, TypeVar, List
1576
+
1577
+ T = TypeVar("T")
1578
+ S = TypeVar("S")
1579
+
1580
+ @dataclass
1581
+ class Parent(Generic[T]):
1582
+ f: Callable[[T], Any]
1583
+
1584
+ @dataclass
1585
+ class Child(Parent[T]): ...
1586
+
1587
+ class A: ...
1588
+ def func(obj: A) -> bool: ...
1589
+
1590
+ reveal_type(Child[A](func).f) # N: Revealed type is "def (__main__.A) -> Any"
1591
+
1592
+ @dataclass
1593
+ class Parent2(Generic[T]):
1594
+ a: List[T]
1595
+
1596
+ @dataclass
1597
+ class Child2(Generic[T, S], Parent2[S]):
1598
+ b: List[T]
1599
+
1600
+ reveal_type(Child2([A()], [1]).a) # N: Revealed type is "builtins.list[__main__.A]"
1601
+ reveal_type(Child2[int, A]([A()], [1]).b) # N: Revealed type is "builtins.list[builtins.int]"
1602
+ [builtins fixtures/dataclasses.pyi]
1603
+
1604
+ [case testDataclassInheritOptionalType]
1605
+ # flags: --python-version 3.7 --strict-optional
1606
+ from dataclasses import dataclass
1607
+ from typing import Any, Callable, Generic, TypeVar, List, Optional
1608
+
1609
+ T = TypeVar("T")
1610
+
1611
+ @dataclass
1612
+ class Parent(Generic[T]):
1613
+ x: Optional[str]
1614
+ @dataclass
1615
+ class Child(Parent):
1616
+ y: Optional[int]
1617
+ Child(x=1, y=1) # E: Argument "x" to "Child" has incompatible type "int"; expected "Optional[str]"
1618
+ Child(x='', y='') # E: Argument "y" to "Child" has incompatible type "str"; expected "Optional[int]"
1619
+ Child(x='', y=1)
1620
+ Child(x=None, y=None)
1621
+ [builtins fixtures/dataclasses.pyi]
0 commit comments