MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_nested_paramspec

Method test_nested_paramspec

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

Source from the content-addressed store, hash-verified

2575 self.assertEqual(C[...], Callable[Concatenate[int, ...], int])
2576
2577 def test_nested_paramspec(self):
2578 # Since Callable has some special treatment, we want to be sure
2579 # that substitution works correctly, see gh-103054
2580 Callable = self.Callable
2581 P = ParamSpec('P')
2582 P2 = ParamSpec('P2')
2583 T = TypeVar('T')
2584 T2 = TypeVar('T2')
2585 Ts = TypeVarTuple('Ts')
2586 class My(Generic[P, T]):
2587 pass
2588
2589 self.assertEqual(My.__parameters__, (P, T))
2590
2591 C1 = My[[int, T2], Callable[P2, T2]]
2592 self.assertEqual(C1.__args__, ((int, T2), Callable[P2, T2]))
2593 self.assertEqual(C1.__parameters__, (T2, P2))
2594 self.assertEqual(C1[str, [list[int], bytes]],
2595 My[[int, str], Callable[[list[int], bytes], str]])
2596
2597 C2 = My[[Callable[[T2], int], list[T2]], str]
2598 self.assertEqual(C2.__args__, ((Callable[[T2], int], list[T2]), str))
2599 self.assertEqual(C2.__parameters__, (T2,))
2600 self.assertEqual(C2[list[str]],
2601 My[[Callable[[list[str]], int], list[list[str]]], str])
2602
2603 C3 = My[[Callable[P2, T2], T2], T2]
2604 self.assertEqual(C3.__args__, ((Callable[P2, T2], T2), T2))
2605 self.assertEqual(C3.__parameters__, (P2, T2))
2606 self.assertEqual(C3[[], int],
2607 My[[Callable[[], int], int], int])
2608 self.assertEqual(C3[[str, bool], int],
2609 My[[Callable[[str, bool], int], int], int])
2610 self.assertEqual(C3[[str, bool], T][int],
2611 My[[Callable[[str, bool], int], int], int])
2612
2613 C4 = My[[Callable[[int, *Ts, str], T2], T2], T2]
2614 self.assertEqual(C4.__args__, ((Callable[[int, *Ts, str], T2], T2), T2))
2615 self.assertEqual(C4.__parameters__, (Ts, T2))
2616 self.assertEqual(C4[bool, bytes, float],
2617 My[[Callable[[int, bool, bytes, str], float], float], float])
2618
2619 def test_errors(self):
2620 Callable = self.Callable

Callers

nothing calls this directly

Calls 4

ParamSpecClass · 0.85
TypeVarClass · 0.85
TypeVarTupleClass · 0.85
assertEqualMethod · 0.45

Tested by

no test coverage detected