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

Method test_parameter_detection

Lib/test/test_typing.py:5916–5931  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

5914 ...
5915
5916 def test_parameter_detection(self):
5917 self.assertEqual(List[T].__parameters__, (T,))
5918 self.assertEqual(List[List[T]].__parameters__, (T,))
5919 class A:
5920 __parameters__ = (T,)
5921 # Bare classes should be skipped
5922 for a in (List, list):
5923 for b in (A, int, TypeVar, TypeVarTuple, ParamSpec, types.GenericAlias, Union):
5924 with self.subTest(generic=a, sub=b):
5925 with self.assertRaisesRegex(TypeError, '.* is not a generic class'):
5926 a[b][str]
5927 # Duck-typing anything that looks like it has __parameters__.
5928 # These tests are optional and failure is okay.
5929 self.assertEqual(List[A()].__parameters__, (T,))
5930 # C version of GenericAlias
5931 self.assertEqual(list[A()].__parameters__, (T,))
5932
5933 def test_non_generic_subscript(self):
5934 T = TypeVar('T')

Callers

nothing calls this directly

Calls 4

assertRaisesRegexMethod · 0.80
AClass · 0.70
assertEqualMethod · 0.45
subTestMethod · 0.45

Tested by

no test coverage detected