MCPcopy Index your code
hub / github.com/python/cpython / test_generic_extending

Method test_generic_extending

Lib/test/test_dataclasses/__init__.py:2146–2167  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2144 Alias = List[LabeledBox[int]]
2145
2146 def test_generic_extending(self):
2147 S = TypeVar('S')
2148 T = TypeVar('T')
2149
2150 @dataclass
2151 class Base(Generic[T, S]):
2152 x: T
2153 y: S
2154
2155 @dataclass
2156 class DataDerived(Base[int, T]):
2157 new_field: str
2158 Alias = DataDerived[str]
2159 c = Alias(0, 'test1', 'test2')
2160 self.assertEqual(astuple(c), (0, 'test1', 'test2'))
2161
2162 class NonDataDerived(Base[int, T]):
2163 def new_method(self):
2164 return self.y
2165 Alias = NonDataDerived[float]
2166 c = Alias(10, 1.0)
2167 self.assertEqual(c.new_method(), 1.0)
2168
2169 def test_generic_dynamic(self):
2170 T = TypeVar('T')

Callers

nothing calls this directly

Calls 3

assertEqualMethod · 0.95
astupleFunction · 0.85
new_methodMethod · 0.80

Tested by

no test coverage detected