MCPcopy Create free account
hub / github.com/numpy/numpy / _lookfor_generate_cache

Function _lookfor_generate_cache

numpy/lib/utils.py:878–1015  ·  view source on GitHub ↗

Generate docstring cache for given module. Parameters ---------- module : str, None, module Module for which to generate docstring cache import_modules : bool Whether to import sub-modules in packages. regenerate : bool Re-generate the docstring cach

(module, import_modules, regenerate)

Source from the content-addressed store, hash-verified

876 print("\n".join(help_text))
877
878def _lookfor_generate_cache(module, import_modules, regenerate):
879 """
880 Generate docstring cache for given module.
881
882 Parameters
883 ----------
884 module : str, None, module
885 Module for which to generate docstring cache
886 import_modules : bool
887 Whether to import sub-modules in packages.
888 regenerate : bool
889 Re-generate the docstring cache
890
891 Returns
892 -------
893 cache : dict {obj_full_name: (docstring, kind, index), ...}
894 Docstring cache for the module, either cached one (regenerate=False)
895 or newly generated.
896
897 """
898 # Local import to speed up numpy's import time.
899 import inspect
900
901 from io import StringIO
902
903 if module is None:
904 module = "numpy"
905
906 if isinstance(module, str):
907 try:
908 __import__(module)
909 except ImportError:
910 return {}
911 module = sys.modules[module]
912 elif isinstance(module, list) or isinstance(module, tuple):
913 cache = {}
914 for mod in module:
915 cache.update(_lookfor_generate_cache(mod, import_modules,
916 regenerate))
917 return cache
918
919 if id(module) in _lookfor_caches and not regenerate:
920 return _lookfor_caches[id(module)]
921
922 # walk items and collect docstrings
923 cache = {}
924 _lookfor_caches[id(module)] = cache
925 seen = {}
926 index = 0
927 stack = [(module.__name__, module)]
928 while stack:
929 name, item = stack.pop(0)
930 if id(item) in seen:
931 continue
932 seen[id(item)] = True
933
934 index += 1
935 kind = "object"

Callers 1

lookforFunction · 0.85

Calls 7

_getmembersFunction · 0.85
updateMethod · 0.80
listdirMethod · 0.80
endswithMethod · 0.80
startswithMethod · 0.80
joinMethod · 0.45
getdocMethod · 0.45

Tested by

no test coverage detected