(self)
| 2763 | self.assertIs(z, x) |
| 2764 | |
| 2765 | def test_patma_runtime_checkable_protocol(self): |
| 2766 | # Runtime-checkable protocol |
| 2767 | from typing import Protocol, runtime_checkable |
| 2768 | |
| 2769 | @runtime_checkable |
| 2770 | class P(Protocol): |
| 2771 | x: int |
| 2772 | y: int |
| 2773 | |
| 2774 | class A: |
| 2775 | def __init__(self, x: int, y: int): |
| 2776 | self.x = x |
| 2777 | self.y = y |
| 2778 | |
| 2779 | class B(A): ... |
| 2780 | |
| 2781 | for cls in (A, B): |
| 2782 | with self.subTest(cls=cls.__name__): |
| 2783 | inst = cls(1, 2) |
| 2784 | w = 0 |
| 2785 | match inst: |
| 2786 | case P() as p: |
| 2787 | self.assertIsInstance(p, cls) |
| 2788 | self.assertEqual(p.x, 1) |
| 2789 | self.assertEqual(p.y, 2) |
| 2790 | w = 1 |
| 2791 | self.assertEqual(w, 1) |
| 2792 | |
| 2793 | q = 0 |
| 2794 | match inst: |
| 2795 | case P(x=x, y=y): |
| 2796 | self.assertEqual(x, 1) |
| 2797 | self.assertEqual(y, 2) |
| 2798 | q = 1 |
| 2799 | self.assertEqual(q, 1) |
| 2800 | |
| 2801 | |
| 2802 | def test_patma_generic_protocol(self): |
nothing calls this directly
no test coverage detected