diff options
author | Ronan Lamy <ronan.lamy@gmail.com> | 2017-11-13 20:30:34 +0000 |
---|---|---|
committer | Ronan Lamy <ronan.lamy@gmail.com> | 2017-11-13 20:30:34 +0000 |
commit | df887ceb985c7370a1350a901ccab36f2b971747 (patch) | |
tree | 733b806211a6361427de1a2763f577fd48a24d63 /lib-python | |
parent | Test an obscure difference between C-defined and Python-defined functions (diff) | |
download | pypy-df887ceb985c7370a1350a901ccab36f2b971747.tar.gz pypy-df887ceb985c7370a1350a901ccab36f2b971747.tar.bz2 pypy-df887ceb985c7370a1350a901ccab36f2b971747.zip |
Implement cpyext.is_cpyext_function()
inspect.isbuiltin() now returns True for functions implemented in C,
like on CPython.
Diffstat (limited to 'lib-python')
-rw-r--r-- | lib-python/2.7/inspect.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib-python/2.7/inspect.py b/lib-python/2.7/inspect.py index 514e1f5fbb..4335258898 100644 --- a/lib-python/2.7/inspect.py +++ b/lib-python/2.7/inspect.py @@ -40,6 +40,10 @@ import tokenize import linecache from operator import attrgetter from collections import namedtuple +try: + from cpyext import is_cpyext_function as _is_cpyext_function +except ImportError: + _is_cpyext_function = lambda obj: False # These constants are from Include/code.h. CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, CO_VARKEYWORDS = 0x1, 0x2, 0x4, 0x8 @@ -230,7 +234,7 @@ def isbuiltin(object): __doc__ documentation string __name__ original name of this function or method __self__ instance to which a method is bound, or None""" - return isinstance(object, types.BuiltinFunctionType) + return isinstance(object, types.BuiltinFunctionType) or _is_cpyext_function(object) def isroutine(object): """Return true if the object is any kind of function or method.""" |