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)
| 649 | return |
| 650 | |
| 651 | def _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 | |
| 674 | def _find_store_names(co): |
| 675 | """Find names of variables which are written in the code |
nothing calls this directly
no test coverage detected