Skip to content

Commit 1b5b106

Browse files
committed
Format README.rst for RsT; use importlib
1 parent 04a1b89 commit 1b5b106

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

README.rst

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ Over the years, more code optimization, specifically around handling jumps, has
2929
from code patterns. This was noticed as far back as Python 2.4 (2004), but since this is a difficult problem, so far it hasn't been tackled
3030
in a satisfactory way.
3131

32-
The initial attempt to fix this problem was to add markers in the
33-
instruction stream, initially this was a `COME_FROM` instruction, and then use that in pattern detection.
32+
The initial attempt to fix to this problem was to add markers in the
33+
instruction stream, initially this was a ``COME_FROM`` instruction, and
34+
then use that in pattern detection.
3435

3536
Over the years, I've extended that to be more specific, so
36-
`COME_FROM_LOOP` and `COME_FROM_WITH` were added. And I added checks
37-
at grammar-reduce time to try to make sure jumps match with the supposed `COME_FROM` targets.
37+
``COME_FROM_LOOP`` and ``COME_FROM_WITH`` were added. And I added checks
38+
at grammar-reduce time to make try to make sure jumps match with
39+
supposed ``COME_FROM`` targets.
3840

3941
However, all of this is complicated, not robust, has greatly slowed down deparsing and is not really tenable.
4042

@@ -44,10 +46,10 @@ However, even this isn't enough. Control flow needs
4446
to be addressed by using dominators and reverse-dominators, which the python-control-flow_ project can give.
4547

4648
This I am *finally* slowly doing in yet another non-public project. It
47-
is a lot of work. Funding in the form of sponsorship, while greatly
48-
appreciated, isn't commensurate with the amount of effort, and
49-
currently, I have a full-time job. So it may take time before it is
50-
available publicly.
49+
is a lot of work. Funding in the form of sponsorship while greatly
50+
appreciated isn't commensurate with the amount of effort, and
51+
currently I have a full-time job. So it may take time before it is
52+
available publicly, if at all.
5153

5254
Requirements
5355
------------
@@ -168,7 +170,7 @@ issues above the queue of other things I might be doing instead.
168170
See Also
169171
--------
170172

171-
* https://github.com/andrew-tavera/unpyc37/ : indirect fork of https://code.google.com/archive/p/unpyc3/. The above projects use a different decompiling technique than what is used here. Instructions are walked. Some instructions use the stack to generate strings, while others don't. Because control flow isn't dealt with directly, it too suffers the same problems as the various `uncompyle` and `decompyle` programs.
173+
* https://github.com/andrew-tavera/unpyc37/ : indirect fork of https://code.google.com/archive/p/unpyc3/ The above projects use a different decompiling technique than what is used here. Instructions are walked. Some instructions use the stack to generate strings, while others don't. Because control flow isn't dealt with directly, it too suffers the same problems as the various ``uncompyle`` and ``decompyle`` programs.
172174
* https://github.com/rocky/python-xdis : Cross Python version disassembler
173175
* https://github.com/rocky/python-xasm : Cross Python version assembler
174176
* https://github.com/rocky/python-decompile3/wiki : Wiki Documents that describe the code and aspects of it in more detail

decompyle3/scanner.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2016, 2018-2021, 2024 by Rocky Bernstein
1+
# Copyright (c) 2016, 2018-2021, 2024-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 3.7 or 3.8.
2222
"""
2323

24+
import importlib
2425
from abc import ABC
2526
from array import array
2627
from collections import namedtuple
@@ -86,10 +87,10 @@ def __init__(self, version: tuple, show_asm=None, is_pypy=False):
8687

8788
if version[:2] in PYTHON_VERSIONS:
8889
v_str = f"""opcode_{version_tuple_to_str(version, start=0, end=2, delimiter="")}"""
90+
module_name = f"xdis.opcodes.{v_str}"
8991
if is_pypy:
90-
v_str += "pypy"
91-
exec(f"""from xdis.opcodes import {v_str}""")
92-
exec(f"self.opc = {v_str}")
92+
module_name += "pypy"
93+
self.opc = importlib.import_module(module_name)
9394
else:
9495
raise TypeError(
9596
f"{version_tuple_to_str(version)} is not a Python version I know about"

0 commit comments

Comments
 (0)