diff options
| author | Christian Heimes <christian@cheimes.de> | 2008-03-03 18:28:04 (GMT) |
|---|---|---|
| committer | Christian Heimes <christian@cheimes.de> | 2008-03-03 18:28:04 (GMT) |
| commit | 608c1d8e87b20116011fe8fce634e980e115d514 (patch) | |
| tree | e7204b4c31d30b37d308dda03cc03c032f5df08e /Lib/inspect.py | |
| parent | 1f178a6fac790f380b6830642b8c9afc0a3a9931 (diff) | |
| download | cpython-608c1d8e87b20116011fe8fce634e980e115d514.zip cpython-608c1d8e87b20116011fe8fce634e980e115d514.tar.gz cpython-608c1d8e87b20116011fe8fce634e980e115d514.tar.bz2 | |
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?
Diffstat (limited to 'Lib/inspect.py')
| -rw-r--r-- | Lib/inspect.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 42f2c31..3f9199f 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -38,11 +38,15 @@ import dis 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 @@ def isgenerator(object): """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.""" |
