diff options
| author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-11-04 13:20:21 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-04 21:20:21 +0100 |
| commit | 1e29dce1138a39e095ba47ab4c1e445fd08716e2 (patch) | |
| tree | 7a7d6ce609498b6d331ac4ff4b5eccf6cbfd54e5 /Lib/test/test_isinstance.py | |
| parent | effb72fa0f6f8f8ec92687fc6a29d63bbdb7e98d (diff) | |
| download | cpython-git-1e29dce1138a39e095ba47ab4c1e445fd08716e2.tar.gz | |
bpo-30570: Use Py_EnterRecursiveCall() in issubclass() (GH-29048) (GH-29178)
* Use Py_EnterRecursiveCall() in issubclass()
Reviewed-by: Gregory P. Smith <greg@krypto.org> [Google]
(cherry picked from commit 423fa1c1817abfa8c3d1bc308ddbbd8f28b69d68)
Co-authored-by: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
Diffstat (limited to 'Lib/test/test_isinstance.py')
| -rw-r--r-- | Lib/test/test_isinstance.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_isinstance.py b/Lib/test/test_isinstance.py index 31b3899693..34082a1a4b 100644 --- a/Lib/test/test_isinstance.py +++ b/Lib/test/test_isinstance.py @@ -281,6 +281,36 @@ class TestIsInstanceIsSubclass(unittest.TestCase): self.assertRaises(RecursionError, issubclass, int, X()) self.assertRaises(RecursionError, isinstance, 1, X()) + def test_infinite_recursion_via_bases_tuple(self): + """Regression test for bpo-30570.""" + class Failure(object): + def __getattr__(self, attr): + return (self, None) + + with self.assertRaises(RecursionError): + issubclass(Failure(), int) + + def test_infinite_cycle_in_bases(self): + """Regression test for bpo-30570.""" + class X: + @property + def __bases__(self): + return (self, self, self) + self.assertRaises(RecursionError, issubclass, X(), int) + + def test_infinitely_many_bases(self): + """Regression test for bpo-30570.""" + class X: + def __getattr__(self, attr): + self.assertEqual(attr, "__bases__") + class A: + pass + class B: + pass + A.__getattr__ = B.__getattr__ = X.__getattr__ + return (A(), B()) + self.assertRaises(RecursionError, issubclass, X(), int) + def blowstack(fxn, arg, compare_to): # Make sure that calling isinstance with a deeply nested tuple for its |
