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