(self)
| 2803 | |
| 2804 | |
| 2805 | def test_patma_generic_protocol(self): |
| 2806 | # Runtime-checkable generic protocol |
| 2807 | from typing import Generic, TypeVar, Protocol, runtime_checkable |
| 2808 | |
| 2809 | T = TypeVar('T') # not using PEP695 to be able to backport changes |
| 2810 | |
| 2811 | @runtime_checkable |
| 2812 | class P(Protocol[T]): |
| 2813 | a: T |
| 2814 | b: T |
| 2815 | |
| 2816 | class A: |
| 2817 | def __init__(self, x: int, y: int): |
| 2818 | self.x = x |
| 2819 | self.y = y |
| 2820 | |
| 2821 | class G(Generic[T]): |
| 2822 | def __init__(self, x: T, y: T): |
| 2823 | self.x = x |
| 2824 | self.y = y |
| 2825 | |
| 2826 | for cls in (A, G): |
| 2827 | with self.subTest(cls=cls.__name__): |
| 2828 | inst = cls(1, 2) |
| 2829 | w = 0 |
| 2830 | match inst: |
| 2831 | case P(): |
| 2832 | w = 1 |
| 2833 | self.assertEqual(w, 0) |
| 2834 | |
| 2835 | def test_patma_protocol_with_match_args(self): |
| 2836 | # Runtime-checkable protocol with `__match_args__` |
nothing calls this directly
no test coverage detected