@@ -1456,3 +1456,69 @@ class Other:
14561456 __slots__ = ('x',)
14571457 x: int
14581458[builtins fixtures/dataclasses.pyi]
1459+
1460+
1461+ [case testSlotsDefinitionWithTwoPasses1]
1462+ # flags: --python-version 3.10
1463+ # https://github.com/python/mypy/issues/11821
1464+ from typing import TypeVar, Protocol, Generic
1465+ from dataclasses import dataclass
1466+
1467+ C = TypeVar("C", bound="Comparable")
1468+
1469+ class Comparable(Protocol):
1470+ pass
1471+
1472+ V = TypeVar("V", bound=Comparable)
1473+
1474+ @dataclass(slots=True)
1475+ class Node(Generic[V]): # Error was here
1476+ data: V
1477+ [builtins fixtures/dataclasses.pyi]
1478+
1479+ [case testSlotsDefinitionWithTwoPasses2]
1480+ # flags: --python-version 3.10
1481+ from typing import TypeVar, Protocol, Generic
1482+ from dataclasses import dataclass
1483+
1484+ C = TypeVar("C", bound="Comparable")
1485+
1486+ class Comparable(Protocol):
1487+ pass
1488+
1489+ V = TypeVar("V", bound=Comparable)
1490+
1491+ @dataclass(slots=True) # Explicit slots are still not ok:
1492+ class Node(Generic[V]): # E: "Node" both defines "__slots__" and is used with "slots=True"
1493+ __slots__ = ('data',)
1494+ data: V
1495+ [builtins fixtures/dataclasses.pyi]
1496+
1497+ [case testSlotsDefinitionWithTwoPasses3]
1498+ # flags: --python-version 3.10
1499+ from typing import TypeVar, Protocol, Generic
1500+ from dataclasses import dataclass
1501+
1502+ C = TypeVar("C", bound="Comparable")
1503+
1504+ class Comparable(Protocol):
1505+ pass
1506+
1507+ V = TypeVar("V", bound=Comparable)
1508+
1509+ @dataclass(slots=True) # Explicit slots are still not ok, even empty ones:
1510+ class Node(Generic[V]): # E: "Node" both defines "__slots__" and is used with "slots=True"
1511+ __slots__ = ()
1512+ data: V
1513+ [builtins fixtures/dataclasses.pyi]
1514+
1515+ [case testSlotsDefinitionWithTwoPasses4]
1516+ # flags: --python-version 3.10
1517+ import dataclasses as dtc
1518+
1519+ PublishedMessagesVar = dict[int, 'PublishedMessages']
1520+
1521+ @dtc.dataclass(frozen=True, slots=True)
1522+ class PublishedMessages:
1523+ left: int
1524+ [builtins fixtures/dataclasses.pyi]
0 commit comments