MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _find_imports

Function _find_imports

tools/python-3.11.9-amd64/Lib/dis.py:651–672  ·  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

649 return
650
651def _find_imports(co):
652 """Find import statements in the code
653
654 Generate triplets (name, level, fromlist) where
655 name is the imported module and level, fromlist are
656 the corresponding args to __import__.
657 """
658 IMPORT_NAME = opmap['IMPORT_NAME']
659 LOAD_CONST = opmap['LOAD_CONST']
660
661 consts = co.co_consts
662 names = co.co_names
663 opargs = [(op, arg) for _, op, arg in _unpack_opargs(co.co_code)
664 if op != EXTENDED_ARG]
665 for i, (op, oparg) in enumerate(opargs):
666 if op == IMPORT_NAME and i >= 2:
667 from_op = opargs[i-1]
668 level_op = opargs[i-2]
669 if (from_op[0] in hasconst and level_op[0] in hasconst):
670 level = _get_const_value(level_op[0], level_op[1], consts)
671 fromlist = _get_const_value(from_op[0], from_op[1], consts)
672 yield (names[oparg], level, fromlist)
673
674def _find_store_names(co):
675 """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