Skip to content

Commit d855d66

Browse files
authored
Merge pull request #518 from rocky/python-3.12-woes
Python 3.12 woes
2 parents e85eabc + 1ce96f2 commit d855d66

File tree

7 files changed

+51
-54
lines changed

7 files changed

+51
-54
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ check-3.0 check-3.1 check-3.2 check-3.6:
4343
check-3.7: pytest
4444
$(MAKE) -C test check
4545

46-
check-3.8:
47-
$(MAKE) -C test check
46+
check-3.8 check-3.9 check-3.10 check-3.11 check-3.12 check-3.13:
47+
$(MAKE) -C test check-3.8
4848

4949
#:PyPy 2.6.1 PyPy 5.0.1, or PyPy 5.8.0-beta0
5050
# Skip for now

pyproject.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
[build-system]
2-
requires = [
3-
"setuptools",
4-
# "setuptools>=59.6.0", # for 3.6
5-
]
6-
2+
requires = ["setuptools>=61.0"]
73
build-backend = "setuptools.build_meta"
84

95
[project]
@@ -44,6 +40,7 @@ classifiers = [
4440
"Programming Language :: Python :: 3.10",
4541
"Programming Language :: Python :: 3.11",
4642
"Programming Language :: Python :: 3.12",
43+
"Programming Language :: Python :: 3.13",
4744
]
4845
dynamic = ["version"]
4946

@@ -63,3 +60,6 @@ uncompyle6-tokenize = "uncompyle6.bin.pydisassemble:main"
6360

6461
[tool.setuptools.dynamic]
6562
version = {attr = "uncompyle6.version.__version__"}
63+
64+
[tool.setuptools.packages.find]
65+
include = ["uncompyle6*"] # Include all subpackages

setup.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

uncompyle6/__init__.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,26 @@
3030

3131
__docformat__ = "restructuredtext"
3232

33-
from uncompyle6.version import __version__ # noqa
33+
# from uncompyle6.version import __version__ # noqa
3434

35-
if hasattr(sys, "setrecursionlimit"):
36-
# pyston doesn't have setrecursionlimit
37-
sys.setrecursionlimit(5000)
35+
# if hasattr(sys, "setrecursionlimit"):
36+
# # pyston doesn't have setrecursionlimit
37+
# sys.setrecursionlimit(5000)
3838

39-
from uncompyle6.semantics import fragments, pysource
39+
# from uncompyle6.semantics import semantics
4040

41-
# Export some functions
42-
from uncompyle6.main import decompile_file # noqa
41+
# # Export some functions
42+
# from uncompyle6.main import decompile_file # noqa
4343

44-
# Convenience functions so you can say:
45-
# from uncompyle6 import (code_deparse, deparse_code2str)
44+
# # Convenience functions so you can say:
45+
# # from uncompyle6 import (code_deparse, deparse_code2str)
4646

47-
from uncompyle6.semantics.pysource import code_deparse, deparse_code2str
47+
# from uncompyle6.semantics.pysource import code_deparse, deparse_code2str
4848

49-
__all__ = [
50-
"__version__",
51-
"code_deparse",
52-
"decompile_file",
53-
"deparse_code2str",
54-
"fragments",
55-
"pysource",
56-
]
49+
# # __all__ = [
50+
# # "__version__",
51+
# # "code_deparse",
52+
# # "decompile_file",
53+
# # "deparse_code2str",
54+
# # "semantics",
55+
# # ]

uncompyle6/main.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@
2929

3030
from uncompyle6.code_fns import check_object_path
3131
from uncompyle6.parser import ParserError
32-
from uncompyle6.semantics import pysource
3332
from uncompyle6.semantics.fragments import code_deparse as code_deparse_fragments
3433
from uncompyle6.semantics.linemap import deparse_code_with_map
35-
from uncompyle6.semantics.pysource import PARSER_DEFAULT_DEBUG, code_deparse
34+
from uncompyle6.semantics.pysource import (
35+
PARSER_DEFAULT_DEBUG,
36+
SourceWalkerError,
37+
code_deparse,
38+
)
3639
from uncompyle6.version import __version__
3740

3841
# from uncompyle6.linenumbers import line_number_mapping
@@ -173,9 +176,9 @@ def write(s):
173176
pass
174177
real_out.write("\n")
175178
return deparsed
176-
except pysource.SourceWalkerError as e:
179+
except SourceWalkerError as e:
177180
# deparsing failed
178-
raise pysource.SourceWalkerError(str(e))
181+
raise SourceWalkerError(str(e))
179182

180183

181184
def compile_file(source_path: str) -> str:
@@ -412,7 +415,7 @@ def main(
412415
# sys.stderr.write(f"Ran {deparsed_object.f.name}\n")
413416
pass
414417
tot_files += 1
415-
except (ValueError, SyntaxError, ParserError, pysource.SourceWalkerError) as e:
418+
except (ValueError, SyntaxError, ParserError, SourceWalkerError) as e:
416419
sys.stdout.write("\n")
417420
sys.stderr.write(f"\n# file {infile}\n# {e}\n")
418421
failed_files += 1

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"

uncompyle6/semantics/fragments.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2015-2019, 2021-2024 by Rocky Bernstein
1+
# Copyright (c) 2015-2019, 2021-2025 by Rocky Bernstein
22
#
33
# This program is free software: you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License as published by
@@ -73,10 +73,9 @@
7373
from xdis import iscode
7474
from xdis.version_info import IS_PYPY, PYTHON_VERSION_TRIPLE
7575

76-
import uncompyle6.parser as python_parser
76+
from uncompyle6.parser import ParserError as ParserError, parse
7777
from uncompyle6.parsers.treenode import SyntaxTree
7878
from uncompyle6.scanner import Code, Token, get_scanner
79-
from uncompyle6.semantics import pysource
8079
from uncompyle6.semantics.check_ast import checker
8180
from uncompyle6.semantics.consts import (
8281
INDENT_PER_LEVEL,
@@ -90,8 +89,9 @@
9089
from uncompyle6.semantics.pysource import (
9190
DEFAULT_DEBUG_OPTS,
9291
TREE_DEFAULT_DEBUG,
93-
ParserError,
92+
SourceWalker,
9493
StringIO,
94+
find_globals_and_nonlocals,
9595
)
9696
from uncompyle6.show import maybe_show_asm, maybe_show_tree
9797

@@ -147,7 +147,7 @@
147147
}
148148

149149

150-
class FragmentsWalker(pysource.SourceWalker, object):
150+
class FragmentsWalker(SourceWalker, object):
151151
MAP_DIRECT_FRAGMENT = ()
152152

153153
stacked_params = ("f", "indent", "is_lambda", "_globals")
@@ -163,7 +163,7 @@ def __init__(
163163
linestarts={},
164164
tolerate_errors=True,
165165
):
166-
pysource.SourceWalker.__init__(
166+
SourceWalker.__init__(
167167
self,
168168
version=version,
169169
out=StringIO(),
@@ -237,7 +237,7 @@ def set_pos_info(self, node, start, finish, name=None):
237237

238238
def preorder(self, node=None):
239239
start = len(self.f.getvalue())
240-
super(pysource.SourceWalker, self).preorder(node)
240+
super(SourceWalker, self).preorder(node)
241241
self.set_pos_info(node, start, len(self.f.getvalue()))
242242

243243
return
@@ -1177,11 +1177,11 @@ def build_ast(
11771177
p_insts = self.p.insts
11781178
self.p.insts = self.scanner.insts
11791179
self.p.offset2inst_index = self.scanner.offset2inst_index
1180-
ast = python_parser.parse(self.p, tokens, customize, code)
1180+
ast = parse(self.p, tokens, customize, code)
11811181
self.customize(customize)
11821182
self.p.insts = p_insts
11831183

1184-
except (python_parser.ParserError, AssertionError) as e:
1184+
except (ParserError, AssertionError) as e:
11851185
raise ParserError(e, tokens)
11861186
transform_tree = self.treeTransform.transform(ast, code)
11871187
maybe_show_tree(self, ast)
@@ -1219,9 +1219,9 @@ def build_ast(
12191219
self.p.insts = self.scanner.insts
12201220
self.p.offset2inst_index = self.scanner.offset2inst_index
12211221
self.p.opc = self.scanner.opc
1222-
ast = python_parser.parse(self.p, tokens, customize, code)
1222+
ast = parse(self.p, tokens, customize, code)
12231223
self.p.insts = p_insts
1224-
except (python_parser.ParserError, AssertionError) as e:
1224+
except (ParserError, AssertionError) as e:
12251225
raise ParserError(e, tokens, {})
12261226

12271227
checker(ast, False, self.ast_errors)
@@ -2116,7 +2116,7 @@ def code_deparse(
21162116
debug_parser["errorstack"] = True
21172117

21182118
# Build Syntax Tree from tokenized and massaged disassembly.
2119-
# deparsed = pysource.FragmentsWalker(out, scanner, showast=showast)
2119+
# deparsed = FragmentsWalker(out, scanner, showast=showast)
21202120
show_tree = debug_opts.get("tree", False)
21212121
linestarts = dict(scanner.opc.findlinestarts(co))
21222122
deparsed = walker(
@@ -2142,7 +2142,7 @@ def code_deparse(
21422142
# convert leading '__doc__ = "..." into doc string
21432143
assert deparsed.ast == "stmts"
21442144

2145-
(deparsed.mod_globs, _) = pysource.find_globals_and_nonlocals(
2145+
(deparsed.mod_globs, _) = find_globals_and_nonlocals(
21462146
deparsed.ast, set(), set(), co, version
21472147
)
21482148

0 commit comments

Comments
 (0)