Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Lib/test/test_type_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,31 @@ class D[U](T):
self.assertIn(int, C.D.__bases__)
self.assertIs(C.D.x, str)


class DynamicClassTest(unittest.TestCase):
def _set_type_params(self, ns, params):
ns['__type_params__'] = params

def test_types_new_class_with_callback(self):
T = TypeVar('T', infer_variance=True)
Klass = types.new_class('Klass', (Generic[T],), {},
lambda ns: self._set_type_params(ns, (T,)))

self.assertEqual(Klass.__bases__, (Generic,))
self.assertEqual(Klass.__orig_bases__, (Generic[T],))
self.assertEqual(Klass.__type_params__, (T,))
self.assertEqual(Klass.__parameters__, (T,))

def test_types_new_class_no_callback(self):
T = TypeVar('T', infer_variance=True)
Klass = types.new_class('Klass', (Generic[T],), {})

self.assertEqual(Klass.__bases__, (Generic,))
self.assertEqual(Klass.__orig_bases__, (Generic[T],))
self.assertEqual(Klass.__type_params__, ()) # must be explicitly set
self.assertEqual(Klass.__parameters__, (T,))


class TypeParamsManglingTest(unittest.TestCase):
def test_mangling(self):
class Foo[__T]:
Expand Down