mirror of
https://github.com/python/cpython.git
synced 2025-08-19 16:20:59 +00:00
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 423fa1c181
)
Co-authored-by: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
This commit is contained in:
parent
effb72fa0f
commit
1e29dce113
3 changed files with 46 additions and 7 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue