diff Lib/inspect.py @ 45634:6282dfd5dc49 legacy-trunk

Since abc._Abstract was replaces by a new type flags the regression test suite fails. I've added a new function inspect.isabstract(). Is the mmethod fine or should I check if object is a instance of type or subclass of object, too?
author Christian Heimes <christian@cheimes.de>
date Mon, 03 Mar 2008 18:28:04 +0000
parents 1bc923a107d9
children 8543f8c81da0
line wrap: on
line diff
--- a/Lib/inspect.py	Mon Mar 03 12:40:17 2008 +0000
+++ b/Lib/inspect.py	Mon Mar 03 18:28:04 2008 +0000
@@ -38,11 +38,15 @@
 import imp
 import tokenize
 import linecache
+from abc import ABCMeta
 from operator import attrgetter
 from collections import namedtuple
 from compiler.consts import (CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS,
     CO_VARKEYWORDS, CO_GENERATOR)
 
+# See Include/object.h
+TPFLAGS_IS_ABSTRACT = 1 << 20
+
 # ----------------------------------------------------------- type-checking
 def ismodule(object):
     """Return true if the object is a module.
@@ -241,6 +245,10 @@
     """Return true if the object is a generator object."""
     return isinstance(object, types.GeneratorType)
 
+def isabstract(object):
+    """Return true if the object is an abstract base class (ABC)."""
+    return object.__flags__ & TPFLAGS_IS_ABSTRACT
+
 def getmembers(object, predicate=None):
     """Return all members of an object as (name, value) pairs sorted by name.
     Optionally, only return members that satisfy a given predicate."""