From 7eb7eba659854fdd9223bbd3398dc3603c856e80 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 29 Apr 2015 00:44:30 +0300 Subject: [PATCH] inspect: Add initial, mostly dummy, implementation. Only few most obvious functions are implemented, several more added with dummy implementation. The intention of this module will likely always stay to be able to run software which depends on this module for exceptional parts (like error reporting), not to actually inspect objects. --- inspect/inspect.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 inspect/inspect.py diff --git a/inspect/inspect.py b/inspect/inspect.py new file mode 100644 index 00000000..0865517d --- /dev/null +++ b/inspect/inspect.py @@ -0,0 +1,59 @@ +import sys + + +def getmembers(obj, pred=None): + res = [] + for name in dir(obj): + val = getattr(obj, name) + if pred is None or pred(val): + res.append((name, val)) + res.sort() + return res + +def isfunction(obj): + return isinstance(obj, type(isfunction)) + +def isgeneratorfunction(obj): + return isinstance(obj, type(lambda:(yield))) + +def isgenerator(obj): + return isinstance(obj, type(lambda:(yield)())) + +class _Class: + def meth(): pass +_Instance = _Class() + +def ismethod(obj): + return isinstance(obj, type(_Instance.meth)) + +def isclass(obj): + return isinstance(object, type) + +def ismodule(obj): + return isinstance(obj, type(sys)) + + +def getargspec(func): + raise NotImplementedError("This is over-dynamic function, not supported by MicroPython") + +def getmodule(obj, _filename=None): + return None # Not known + +def getmro(cls): + return [cls] + +def getsourcefile(obj): + return None # Not known + +def getfile(obj): + return "" + +def getsource(obj): + return "" + + +def currentframe(): + return None + +def getframeinfo(frame, context=1): + return ("", -1, "", [""], 0)