MCPcopy Index your code
hub / github.com/RustPython/RustPython / _find_imports

Function _find_imports

Lib/dis.py:995–1016  ·  view source on GitHub ↗

Find import statements in the code Generate triplets (name, level, fromlist) where name is the imported module and level, fromlist are the corresponding args to __import__.

(co)

Source from the content-addressed store, hash-verified

993 return
994
995def _find_imports(co):
996 """Find import statements in the code
997
998 Generate triplets (name, level, fromlist) where
999 name is the imported module and level, fromlist are
1000 the corresponding args to __import__.
1001 """
1002 IMPORT_NAME = opmap['IMPORT_NAME']
1003
1004 consts = co.co_consts
1005 names = co.co_names
1006 opargs = [(op, arg) for _, _, op, arg in _unpack_opargs(co.co_code)
1007 if op != EXTENDED_ARG]
1008 for i, (op, oparg) in enumerate(opargs):
1009 if op == IMPORT_NAME and i >= 2:
1010 from_op = opargs[i-1]
1011 level_op = opargs[i-2]
1012 if (from_op[0] in hasconst and
1013 (level_op[0] in hasconst or level_op[0] == LOAD_SMALL_INT)):
1014 level = _get_const_value(level_op[0], level_op[1], consts)
1015 fromlist = _get_const_value(from_op[0], from_op[1], consts)
1016 yield (names[oparg], level, fromlist)
1017
1018def _find_store_names(co):
1019 """Find names of variables which are written in the code

Callers

nothing calls this directly

Calls 3

_unpack_opargsFunction · 0.85
enumerateFunction · 0.85
_get_const_valueFunction · 0.85

Tested by

no test coverage detected