Skip to content

Commit 8755233

Browse files
committed
Use modern importlib to get modules
Older exec() no longer works.
1 parent 3ce8b99 commit 8755233

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

uncompyle6/scanner.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2016, 2018-2024 by Rocky Bernstein
1+
# Copyright (c) 2016, 2018-2025 by Rocky Bernstein
22
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
33
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
44
# Copyright (c) 1999 John Aycock
@@ -21,6 +21,7 @@
2121
scanners, e.g. for Python 2.7 or 3.4.
2222
"""
2323

24+
import importlib
2425
from abc import ABC
2526
from array import array
2627
from collections import namedtuple
@@ -115,15 +116,15 @@ def __init__(self, version: tuple, show_asm=None, is_pypy=False):
115116
self.show_asm = show_asm
116117
self.is_pypy = is_pypy
117118

118-
# Temoorary initialization.
119+
# Temporary initialization.
119120
self.opc = ModuleType("uninitialized")
120121

121122
if version[:2] in PYTHON_VERSIONS:
122123
v_str = f"""opcode_{version_tuple_to_str(version, start=0, end=2, delimiter="")}"""
124+
module_name = f"xdis.opcodes.{v_str}"
123125
if is_pypy:
124-
v_str += "pypy"
125-
exec(f"""from xdis.opcodes import {v_str}""")
126-
exec("self.opc = %s" % v_str)
126+
module_name += "pypy"
127+
self.opc = importlib.import_module(module_name)
127128
else:
128129
raise TypeError(
129130
"%s is not a Python version I know about"

0 commit comments

Comments
 (0)