diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2021-09-09 13:04:12 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-09 13:04:12 (GMT) |
commit | 04676b69466d2e6d2903f1c6879d2cb292721455 (patch) | |
tree | 9e9901e4c25cb84800949d990a9cbaef851d32be /Lib/modulefinder.py | |
parent | 49acac00c08838d8080ce00d02c05284b94f8fb2 (diff) | |
download | cpython-04676b69466d2e6d2903f1c6879d2cb292721455.zip cpython-04676b69466d2e6d2903f1c6879d2cb292721455.tar.gz cpython-04676b69466d2e6d2903f1c6879d2cb292721455.tar.bz2 |
bpo-45017: move opcode-related logic from modulefinder to dis (GH-28246)
Diffstat (limited to 'Lib/modulefinder.py')
-rw-r--r-- | Lib/modulefinder.py | 33 |
1 files changed, 7 insertions, 26 deletions
diff --git a/Lib/modulefinder.py b/Lib/modulefinder.py index cb455f4..a0a020f 100644 --- a/Lib/modulefinder.py +++ b/Lib/modulefinder.py @@ -8,14 +8,6 @@ import os import io import sys - -LOAD_CONST = dis.opmap['LOAD_CONST'] -IMPORT_NAME = dis.opmap['IMPORT_NAME'] -STORE_NAME = dis.opmap['STORE_NAME'] -STORE_GLOBAL = dis.opmap['STORE_GLOBAL'] -STORE_OPS = STORE_NAME, STORE_GLOBAL -EXTENDED_ARG = dis.EXTENDED_ARG - # Old imp constants: _SEARCH_ERROR = 0 @@ -394,24 +386,13 @@ class ModuleFinder: def scan_opcodes(self, co): # Scan the code, and yield 'interesting' opcode combinations - code = co.co_code - names = co.co_names - consts = co.co_consts - opargs = [(op, arg) for _, op, arg in dis._unpack_opargs(code) - if op != EXTENDED_ARG] - for i, (op, oparg) in enumerate(opargs): - if op in STORE_OPS: - yield "store", (names[oparg],) - continue - if (op == IMPORT_NAME and i >= 2 - and opargs[i-1][0] == opargs[i-2][0] == LOAD_CONST): - level = consts[opargs[i-2][1]] - fromlist = consts[opargs[i-1][1]] - if level == 0: # absolute import - yield "absolute_import", (fromlist, names[oparg]) - else: # relative import - yield "relative_import", (level, fromlist, names[oparg]) - continue + for name in dis._find_store_names(co): + yield "store", (name,) + for name, level, fromlist in dis._find_imports(co): + if level == 0: # absolute import + yield "absolute_import", (fromlist, name) + else: # relative import + yield "relative_import", (level, fromlist, name) def scan_code(self, co, m): code = co.co_code |