improve method to list APIs in NumPy/SciPy
import importlib
+import inspect
+
+import numpy
def _get_functions(obj, exclude=[]):
return set([
- n for n in dir(obj)
- if ((exclude is None or n not in exclude)
- and callable(getattr(obj, n)) # callable
- and not isinstance(getattr(obj, n), type) # not class
- and n[0].islower() # starts with lower char
- and not n.startswith('__') # not special methods
+ n for n, target in [(n, getattr(obj, n)) for n in dir(obj)]
+ if (
+ # not in exclude list
+ (exclude is None or n not in exclude)
+ # not module:
+ and not inspect.ismodule(target)
+ # not constant:
+ and not isinstance(target, (int, float, bool, str, numpy.bool_))
+ # not exceptions or warning classes:
+ and (not inspect.isclass(target) or
+ not issubclass(target, (BaseException,)))
+ # not private/special method:
+ and not n.startswith('_')
)
])
@@ -93,8 +103,10 @@ def generate():
'add_docstring',
'add_newdoc',
'add_newdoc_ufunc',
+ '_add_newdoc_ufunc',
'fastCopyAndTranspose',
'test',
+ 'Tester',
])
buf += _section(
'Multi-Dimensional Array',
