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

Method test_generic_dynamic

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

Source from the content-addressed store, hash-verified

2167 self.assertEqual(c.new_method(), 1.0)
2168
2169 def test_generic_dynamic(self):
2170 T = TypeVar('T')
2171
2172 @dataclass
2173 class Parent(Generic[T]):
2174 x: T
2175 Child = make_dataclass('Child', [('y', T), ('z', Optional[T], None)],
2176 bases=(Parent[int], Generic[T]), namespace={'other': 42})
2177 self.assertIs(Child[int](1, 2).z, None)
2178 self.assertEqual(Child[int](1, 2, 3).z, 3)
2179 self.assertEqual(Child[int](1, 2, 3).other, 42)
2180 # Check that type aliases work correctly.
2181 Alias = Child[T]
2182 self.assertEqual(Alias[int](1, 2).x, 1)
2183 # Check MRO resolution.
2184 self.assertEqual(Child.__mro__, (Child, Parent, Generic, object))
2185
2186 def test_dataclasses_pickleable(self):
2187 global P, Q, R

Callers

nothing calls this directly

Calls 3

assertIsMethod · 0.95
assertEqualMethod · 0.95
make_dataclassFunction · 0.85

Tested by

no test coverage detected