| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e114fe9 commit b5cc9cd
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2672,6 +2672,42 @@ def __init__(self) -> None: | |||
| 2672 | 2672 | with self.assertRaises(TypeError): | |
| 2673 | 2673 | issubclass(Eggs, Spam) | |
| 2674 | 2674 | ||
| 2675 | + def test_no_weird_caching_with_issubclass_after_isinstance2(self): | ||
| 2676 | + @runtime_checkable | ||
| 2677 | + class Spam(Protocol): | ||
| 2678 | + x: int | ||
| 2679 | + | ||
| 2680 | + class Eggs: ... | ||
| 2681 | + | ||
| 2682 | + # gh-104555: ABCMeta might cache the result of this isinstance check | ||
| 2683 | + # if we called super().__instancecheck__ in the wrong place | ||
| 2684 | + # in _ProtocolMeta.__instancecheck__... | ||
| 2685 | + self.assertNotIsInstance(Eggs(), Spam) | ||
| 2686 | + | ||
| 2687 | + # ...and if it did, then TypeError wouldn't be raised here! | ||
| 2688 | + with self.assertRaises(TypeError): | ||
| 2689 | + issubclass(Eggs, Spam) | ||
| 2690 | + | ||
| 2691 | + def test_no_weird_caching_with_issubclass_after_isinstance3(self): | ||
| 2692 | + @runtime_checkable | ||
| 2693 | + class Spam(Protocol): | ||
| 2694 | + x: int | ||
| 2695 | + | ||
| 2696 | + class Eggs: | ||
| 2697 | + def __getattr__(self, attr): | ||
| 2698 | + if attr == "x": | ||
| 2699 | + return 42 | ||
| 2700 | + raise AttributeError(attr) | ||
| 2701 | + | ||
| 2702 | + # gh-104555: ABCMeta might cache the result of this isinstance check | ||
| 2703 | + # if we called super().__instancecheck__ in the wrong place | ||
| 2704 | + # in _ProtocolMeta.__instancecheck__... | ||
| 2705 | + self.assertNotIsInstance(Eggs(), Spam) | ||
| 2706 | + | ||
| 2707 | + # ...and if it did, then TypeError wouldn't be raised here! | ||
| 2708 | + with self.assertRaises(TypeError): | ||
| 2709 | + issubclass(Eggs, Spam) | ||
| 2710 | + | ||
| 2675 | 2711 | def test_no_weird_caching_with_issubclass_after_isinstance_pep695(self): | |
| 2676 | 2712 | @runtime_checkable | |
| 2677 | 2713 | class Spam[T](Protocol): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments