summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_inspect.py
diff options
context:
space:
mode:
authorNate <nate@so8r.es>2017-04-24 17:06:15 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-04-24 17:06:15 (GMT)
commitfcfe80ec2592fed8b3941c79056a8737abef7d3b (patch)
tree5dc4a68452313e95e2e9bcecac7b9821d14c3a15 /Lib/test/test_inspect.py
parent2e576f5aec1f8f23f07001e2eb3db9276851a4fc (diff)
downloadcpython-fcfe80ec2592fed8b3941c79056a8737abef7d3b.zip
cpython-fcfe80ec2592fed8b3941c79056a8737abef7d3b.tar.gz
cpython-fcfe80ec2592fed8b3941c79056a8737abef7d3b.tar.bz2
bpo-29822: Make inspect.isabstract() work during __init_subclass__. (#678)
At the time when an abstract base class' __init_subclass__ runs, ABCMeta.__new__ has not yet finished running, so in the presence of __init_subclass__, inspect.isabstract() can no longer depend only on TPFLAGS_IS_ABSTRACT.
Diffstat (limited to 'Lib/test/test_inspect.py')
-rw-r--r--Lib/test/test_inspect.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index 2f12e98..799a9fa 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -229,6 +229,30 @@ class TestPredicates(IsTestBase):
self.assertFalse(inspect.isabstract(int))
self.assertFalse(inspect.isabstract(5))
+ def test_isabstract_during_init_subclass(self):
+ from abc import ABCMeta, abstractmethod
+ isabstract_checks = []
+ class AbstractChecker(metaclass=ABCMeta):
+ def __init_subclass__(cls):
+ isabstract_checks.append(inspect.isabstract(cls))
+ class AbstractClassExample(AbstractChecker):
+ @abstractmethod
+ def foo(self):
+ pass
+ class ClassExample(AbstractClassExample):
+ def foo(self):
+ pass
+ self.assertEqual(isabstract_checks, [True, False])
+
+ isabstract_checks.clear()
+ class AbstractChild(AbstractClassExample):
+ pass
+ class AbstractGrandchild(AbstractChild):
+ pass
+ class ConcreteGrandchild(ClassExample):
+ pass
+ self.assertEqual(isabstract_checks, [True, True, False])
+
class TestInterpreterStack(IsTestBase):
def __init__(self, *args, **kwargs):