forked from pool/python-ast-decompiler
Compare commits
4 Commits
| Author | SHA256 | Date | |
|---|---|---|---|
| b25101a4d9 | |||
| f07b055a5f | |||
| ffba975e26 | |||
| 3f103a90ed |
@@ -1,3 +0,0 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
|
||||||
oid sha256:efc3a507e5f8963ec7b4b2ce2ea693e3755c2f52b741c231bc344a4526738337
|
|
||||||
size 18413
|
|
||||||
3
ast_decompiler-0.8.0.tar.gz
Normal file
3
ast_decompiler-0.8.0.tar.gz
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:daef5ca5c2bcb9ba7cf72a9308c7cd596c092d7201c0bbaf28947c721ce26441
|
||||||
|
size 18526
|
||||||
@@ -1,68 +1,74 @@
|
|||||||
---
|
diff -Nru ast_decompiler-0.8.0.orig/tests/test_basic.py ast_decompiler-0.8.0/tests/test_basic.py
|
||||||
tests/test_basic.py | 2 +-
|
--- ast_decompiler-0.8.0.orig/tests/test_basic.py 2024-05-17 11:24:40.473753700 +0000
|
||||||
tests/test_indentation.py | 2 +-
|
+++ ast_decompiler-0.8.0/tests/test_basic.py 2024-11-08 10:13:46.230356472 +0000
|
||||||
tests/test_line_length.py | 2 +-
|
|
||||||
tests/test_literal.py | 2 +-
|
|
||||||
tests/test_patma.py | 2 +-
|
|
||||||
tests/test_precedence.py | 2 +-
|
|
||||||
tests/test_py3_syntax.py | 2 +-
|
|
||||||
7 files changed, 7 insertions(+), 7 deletions(-)
|
|
||||||
|
|
||||||
--- a/tests/test_basic.py
|
|
||||||
+++ b/tests/test_basic.py
|
|
||||||
@@ -1,6 +1,6 @@
|
@@ -1,6 +1,6 @@
|
||||||
import ast
|
import ast
|
||||||
from ast_decompiler import decompile
|
from ast_decompiler import decompile
|
||||||
-from .tests import assert_decompiles, check, only_on_version
|
-from .tests import assert_decompiles, check
|
||||||
+from tests import assert_decompiles, check, only_on_version
|
+from tests import assert_decompiles, check
|
||||||
|
|
||||||
|
|
||||||
def test_non_module() -> None:
|
def test_non_module() -> None:
|
||||||
--- a/tests/test_indentation.py
|
diff -Nru ast_decompiler-0.8.0.orig/tests/test_indentation.py ast_decompiler-0.8.0/tests/test_indentation.py
|
||||||
+++ b/tests/test_indentation.py
|
--- ast_decompiler-0.8.0.orig/tests/test_indentation.py 2024-05-17 11:24:40.473753700 +0000
|
||||||
|
+++ ast_decompiler-0.8.0/tests/test_indentation.py 2024-11-08 10:13:46.230356472 +0000
|
||||||
@@ -1,4 +1,4 @@
|
@@ -1,4 +1,4 @@
|
||||||
-from .tests import assert_decompiles
|
-from .tests import assert_decompiles
|
||||||
+from tests import assert_decompiles
|
+from tests import assert_decompiles
|
||||||
|
|
||||||
|
|
||||||
def test_indentation() -> None:
|
def test_indentation() -> None:
|
||||||
--- a/tests/test_line_length.py
|
diff -Nru ast_decompiler-0.8.0.orig/tests/test_line_length.py ast_decompiler-0.8.0/tests/test_line_length.py
|
||||||
+++ b/tests/test_line_length.py
|
--- ast_decompiler-0.8.0.orig/tests/test_line_length.py 2024-05-17 11:24:40.473753700 +0000
|
||||||
|
+++ ast_decompiler-0.8.0/tests/test_line_length.py 2024-11-08 10:13:46.234356491 +0000
|
||||||
@@ -1,4 +1,4 @@
|
@@ -1,4 +1,4 @@
|
||||||
-from .tests import assert_decompiles
|
-from .tests import assert_decompiles
|
||||||
+from tests import assert_decompiles
|
+from tests import assert_decompiles
|
||||||
|
|
||||||
|
|
||||||
def check_split(original: str, multiline: str, length_reduction: int = 2) -> None:
|
def check_split(original: str, multiline: str, length_reduction: int = 2) -> None:
|
||||||
--- a/tests/test_literal.py
|
diff -Nru ast_decompiler-0.8.0.orig/tests/test_literal.py ast_decompiler-0.8.0/tests/test_literal.py
|
||||||
+++ b/tests/test_literal.py
|
--- ast_decompiler-0.8.0.orig/tests/test_literal.py 2024-05-17 11:24:40.473753700 +0000
|
||||||
|
+++ ast_decompiler-0.8.0/tests/test_literal.py 2024-11-08 10:13:46.234356491 +0000
|
||||||
@@ -1,4 +1,4 @@
|
@@ -1,4 +1,4 @@
|
||||||
-from .tests import assert_decompiles, only_on_version
|
-from .tests import assert_decompiles
|
||||||
+from tests import assert_decompiles, only_on_version
|
+from tests import assert_decompiles
|
||||||
|
|
||||||
|
|
||||||
def test_With() -> None:
|
def test_With() -> None:
|
||||||
--- a/tests/test_patma.py
|
diff -Nru ast_decompiler-0.8.0.orig/tests/test_patma.py ast_decompiler-0.8.0/tests/test_patma.py
|
||||||
+++ b/tests/test_patma.py
|
--- ast_decompiler-0.8.0.orig/tests/test_patma.py 2024-05-17 11:24:40.473753700 +0000
|
||||||
|
+++ ast_decompiler-0.8.0/tests/test_patma.py 2024-11-08 10:13:46.234356491 +0000
|
||||||
@@ -1,4 +1,4 @@
|
@@ -1,4 +1,4 @@
|
||||||
-from .tests import check, skip_before
|
-from .tests import check, skip_before
|
||||||
+from tests import check, skip_before
|
+from tests import check, skip_before
|
||||||
|
|
||||||
|
|
||||||
@skip_before((3, 10))
|
@skip_before((3, 10))
|
||||||
--- a/tests/test_precedence.py
|
diff -Nru ast_decompiler-0.8.0.orig/tests/test_pep695.py ast_decompiler-0.8.0/tests/test_pep695.py
|
||||||
+++ b/tests/test_precedence.py
|
--- ast_decompiler-0.8.0.orig/tests/test_pep695.py 2024-05-17 11:24:40.477753600 +0000
|
||||||
|
+++ ast_decompiler-0.8.0/tests/test_pep695.py 2024-11-08 10:13:46.234356491 +0000
|
||||||
@@ -1,4 +1,4 @@
|
@@ -1,4 +1,4 @@
|
||||||
-from .tests import check, only_on_version
|
-from .tests import check, skip_before
|
||||||
+from tests import check, only_on_version
|
+from tests import check, skip_before
|
||||||
|
|
||||||
|
|
||||||
|
@skip_before((3, 12))
|
||||||
|
diff -Nru ast_decompiler-0.8.0.orig/tests/test_precedence.py ast_decompiler-0.8.0/tests/test_precedence.py
|
||||||
|
--- ast_decompiler-0.8.0.orig/tests/test_precedence.py 2024-05-17 11:24:40.477753600 +0000
|
||||||
|
+++ ast_decompiler-0.8.0/tests/test_precedence.py 2024-11-08 10:13:46.238356510 +0000
|
||||||
|
@@ -1,4 +1,4 @@
|
||||||
|
-from .tests import check
|
||||||
|
+from tests import check
|
||||||
|
|
||||||
|
|
||||||
def test_Yield() -> None:
|
def test_Yield() -> None:
|
||||||
--- a/tests/test_py3_syntax.py
|
diff -Nru ast_decompiler-0.8.0.orig/tests/test_py3_syntax.py ast_decompiler-0.8.0/tests/test_py3_syntax.py
|
||||||
+++ b/tests/test_py3_syntax.py
|
--- ast_decompiler-0.8.0.orig/tests/test_py3_syntax.py 2024-05-17 11:24:40.477753600 +0000
|
||||||
|
+++ ast_decompiler-0.8.0/tests/test_py3_syntax.py 2024-11-08 10:13:46.238356510 +0000
|
||||||
@@ -1,4 +1,4 @@
|
@@ -1,4 +1,4 @@
|
||||||
-from .tests import check, skip_before, skip_after
|
-from .tests import check
|
||||||
+from tests import check, skip_before, skip_after
|
+from tests import check
|
||||||
|
|
||||||
|
|
||||||
@skip_before((3, 5))
|
def test_MatMult() -> None:
|
||||||
|
|||||||
191
py314.patch
Normal file
191
py314.patch
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
From 07a9e25c56e4a153488d2173236f2cd4a06065be Mon Sep 17 00:00:00 2001
|
||||||
|
From: Jelle Zijlstra <jelle.zijlstra@gmail.com>
|
||||||
|
Date: Mon, 12 May 2025 21:29:43 -0700
|
||||||
|
Subject: [PATCH 1/2] Support Python 3.14
|
||||||
|
|
||||||
|
---
|
||||||
|
.github/workflows/test.yml | 2 +-
|
||||||
|
CHANGELOG.md | 3 ++
|
||||||
|
ast_decompiler/decompiler.py | 71 ++++++++++++++++++++++++++++++------
|
||||||
|
pyproject.toml | 5 ++-
|
||||||
|
tests/test_pep695.py | 10 +++++
|
||||||
|
tests/test_py3_syntax.py | 11 +++++-
|
||||||
|
tox.ini | 17 +++++----
|
||||||
|
7 files changed, 95 insertions(+), 24 deletions(-)
|
||||||
|
|
||||||
|
Index: ast_decompiler-0.8.0/ast_decompiler/decompiler.py
|
||||||
|
===================================================================
|
||||||
|
--- ast_decompiler-0.8.0.orig/ast_decompiler/decompiler.py
|
||||||
|
+++ ast_decompiler-0.8.0/ast_decompiler/decompiler.py
|
||||||
|
@@ -879,7 +879,10 @@ class Decompiler(ast.NodeVisitor):
|
||||||
|
self.write(delimiter)
|
||||||
|
|
||||||
|
def visit_FormattedValue(self, node: ast.FormattedValue) -> None:
|
||||||
|
- has_parent = isinstance(self.get_parent_node(), ast.JoinedStr)
|
||||||
|
+ has_parent = isinstance(self.get_parent_node(), ast.JoinedStr) or (
|
||||||
|
+ sys.version_info >= (3, 14)
|
||||||
|
+ and isinstance(self.get_parent_node(), ast.TemplateStr)
|
||||||
|
+ )
|
||||||
|
with self.f_literalise_if(not has_parent):
|
||||||
|
self.write("{")
|
||||||
|
if isinstance(node.value, ast.JoinedStr):
|
||||||
|
@@ -911,20 +914,64 @@ class Decompiler(ast.NodeVisitor):
|
||||||
|
self.write("}")
|
||||||
|
|
||||||
|
def visit_JoinedStr(self, node: ast.JoinedStr) -> None:
|
||||||
|
- has_parent = isinstance(self.get_parent_node(), ast.FormattedValue)
|
||||||
|
+ has_parent = isinstance(self.get_parent_node(), ast.FormattedValue) or (
|
||||||
|
+ sys.version_info >= (3, 14)
|
||||||
|
+ and isinstance(self.get_parent_node(), ast.Interpolation)
|
||||||
|
+ )
|
||||||
|
with self.f_literalise_if(not has_parent):
|
||||||
|
for value in node.values:
|
||||||
|
- if isinstance(value, ast.Constant) and isinstance(value.value, str):
|
||||||
|
- # always escape '
|
||||||
|
- self.write(
|
||||||
|
- value.value.encode("unicode-escape")
|
||||||
|
- .decode("ascii")
|
||||||
|
- .replace("'", r"\'")
|
||||||
|
- .replace("{", "{{")
|
||||||
|
- .replace("}", "}}")
|
||||||
|
- )
|
||||||
|
+ self._write_tf_string_part(value)
|
||||||
|
+
|
||||||
|
+ def _write_tf_string_part(self, value: ast.expr) -> None:
|
||||||
|
+ if isinstance(value, ast.Constant) and isinstance(value.value, str):
|
||||||
|
+ # always escape '
|
||||||
|
+ self.write(
|
||||||
|
+ value.value.encode("unicode-escape")
|
||||||
|
+ .decode("ascii")
|
||||||
|
+ .replace("'", r"\'")
|
||||||
|
+ .replace("{", "{{")
|
||||||
|
+ .replace("}", "}}")
|
||||||
|
+ )
|
||||||
|
+ else:
|
||||||
|
+ self.visit(value)
|
||||||
|
+
|
||||||
|
+ if sys.version_info >= (3, 14):
|
||||||
|
+
|
||||||
|
+ def visit_TemplateStr(self, node: ast.TemplateStr) -> None:
|
||||||
|
+ self.write("t'")
|
||||||
|
+ for value in node.values:
|
||||||
|
+ self._write_tf_string_part(value)
|
||||||
|
+ self.write("'")
|
||||||
|
+
|
||||||
|
+ def visit_Interpolation(self, node: ast.Interpolation) -> None:
|
||||||
|
+ self.write("{")
|
||||||
|
+ if isinstance(node.value, ast.JoinedStr):
|
||||||
|
+ raise NotImplementedError(
|
||||||
|
+ "ast_decompiler does not support nested f-strings yet"
|
||||||
|
+ )
|
||||||
|
+ add_space = isinstance(
|
||||||
|
+ node.value, (ast.Set, ast.Dict, ast.SetComp, ast.DictComp)
|
||||||
|
+ )
|
||||||
|
+ if add_space:
|
||||||
|
+ self.write(" ")
|
||||||
|
+ self.write(node.str)
|
||||||
|
+ if node.conversion != -1:
|
||||||
|
+ self.write(f"!{chr(node.conversion)}")
|
||||||
|
+ if node.format_spec is not None:
|
||||||
|
+ self.write(":")
|
||||||
|
+ if isinstance(node.format_spec, ast.JoinedStr):
|
||||||
|
+ self.visit(node.format_spec)
|
||||||
|
+ elif isinstance(node.format_spec, ast.Constant) and isinstance(
|
||||||
|
+ node.format_spec.value, str
|
||||||
|
+ ):
|
||||||
|
+ self.write(node.format_spec.value)
|
||||||
|
else:
|
||||||
|
- self.visit(value)
|
||||||
|
+ raise TypeError(
|
||||||
|
+ f"format spec must be a string, not {node.format_spec}"
|
||||||
|
+ )
|
||||||
|
+ if add_space:
|
||||||
|
+ self.write(" ")
|
||||||
|
+ self.write("}")
|
||||||
|
|
||||||
|
def visit_Constant(self, node: ast.Constant) -> None:
|
||||||
|
if isinstance(node.value, str):
|
||||||
|
Index: ast_decompiler-0.8.0/pyproject.toml
|
||||||
|
===================================================================
|
||||||
|
--- ast_decompiler-0.8.0.orig/pyproject.toml
|
||||||
|
+++ ast_decompiler-0.8.0/pyproject.toml
|
||||||
|
@@ -21,12 +21,12 @@ classifiers = [
|
||||||
|
"Operating System :: OS Independent",
|
||||||
|
"Programming Language :: Python :: 3",
|
||||||
|
"Programming Language :: Python :: 3 :: Only",
|
||||||
|
- "Programming Language :: Python :: 3.8",
|
||||||
|
"Programming Language :: Python :: 3.9",
|
||||||
|
"Programming Language :: Python :: 3.10",
|
||||||
|
"Programming Language :: Python :: 3.11",
|
||||||
|
"Programming Language :: Python :: 3.12",
|
||||||
|
"Programming Language :: Python :: 3.13",
|
||||||
|
+ "Programming Language :: Python :: 3.14",
|
||||||
|
"Topic :: Software Development",
|
||||||
|
]
|
||||||
|
|
||||||
|
@@ -40,7 +40,7 @@ email = "jelle.zijlstra@gmail.com"
|
||||||
|
include = ["CHANGELOG", "README.rst", "*/test*.py"]
|
||||||
|
exclude = []
|
||||||
|
|
||||||
|
-[tool.pyanalyze]
|
||||||
|
+[tool.pycroscope]
|
||||||
|
paths = ["ast_decompiler", "tests"]
|
||||||
|
import_paths = ["."]
|
||||||
|
|
||||||
|
@@ -55,7 +55,7 @@ suggested_return_type = true
|
||||||
|
incompatible_override = true
|
||||||
|
|
||||||
|
[tool.black]
|
||||||
|
-target_version = ['py36']
|
||||||
|
+target-version = ['py38', 'py39', 'py310', 'py311', 'py312', 'py313']
|
||||||
|
skip-magic-trailing-comma = true
|
||||||
|
preview = true
|
||||||
|
|
||||||
|
Index: ast_decompiler-0.8.0/tests/test_pep695.py
|
||||||
|
===================================================================
|
||||||
|
--- ast_decompiler-0.8.0.orig/tests/test_pep695.py
|
||||||
|
+++ ast_decompiler-0.8.0/tests/test_pep695.py
|
||||||
|
@@ -29,3 +29,13 @@ type X = int
|
||||||
|
type Y[T: (int, str), *Ts, *P] = T
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+@skip_before((3, 13))
|
||||||
|
+def test_type_var_default() -> None:
|
||||||
|
+ check(
|
||||||
|
+ """
|
||||||
|
+def f[T=int, *Ts=(int, str), **P=()]() -> None:
|
||||||
|
+ pass
|
||||||
|
+"""
|
||||||
|
+ )
|
||||||
|
Index: ast_decompiler-0.8.0/tests/test_py3_syntax.py
|
||||||
|
===================================================================
|
||||||
|
--- ast_decompiler-0.8.0.orig/tests/test_py3_syntax.py
|
||||||
|
+++ ast_decompiler-0.8.0/tests/test_py3_syntax.py
|
||||||
|
@@ -1,4 +1,4 @@
|
||||||
|
-from tests import check
|
||||||
|
+from tests import check, skip_after, skip_before
|
||||||
|
|
||||||
|
|
||||||
|
def test_MatMult() -> None:
|
||||||
|
@@ -276,6 +276,7 @@ f({})
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
+@skip_after((3, 14))
|
||||||
|
def test_finally_continue() -> None:
|
||||||
|
check(
|
||||||
|
"""
|
||||||
|
@@ -335,3 +336,11 @@ def f(x, /):
|
||||||
|
def test_fstring_debug_specifier() -> None:
|
||||||
|
check("f'{user=} {member_since=}'")
|
||||||
|
check("f'{user=!s} {delta.days=:,d}'")
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+@skip_before((3, 14))
|
||||||
|
+def test_tstring() -> None:
|
||||||
|
+ check("t'a'")
|
||||||
|
+ check("t'{a}'")
|
||||||
|
+ check("t'{a!s}'")
|
||||||
|
+ check("t'{a:b}'")
|
||||||
@@ -1,3 +1,16 @@
|
|||||||
|
-------------------------------------------------------------------
|
||||||
|
Fri Nov 14 10:07:07 UTC 2025 - Markéta Machová <mmachova@suse.com>
|
||||||
|
|
||||||
|
- Add upstream patch py314.patch to support Python 3.14
|
||||||
|
|
||||||
|
-------------------------------------------------------------------
|
||||||
|
Fri Nov 8 10:14:29 UTC 2024 - John Paul Adrian Glaubitz <adrian.glaubitz@suse.com>
|
||||||
|
|
||||||
|
- Update to 0.8.0
|
||||||
|
* Support Python 3.12 and 3.13; stop testing Python 3.6 and 3.7
|
||||||
|
* Fix all DeprecationWarnings in the codebase
|
||||||
|
- Refresh no-relative-imports.patch
|
||||||
|
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
Tue Oct 18 12:44:05 UTC 2022 - Matej Cepl <mcepl@suse.com>
|
Tue Oct 18 12:44:05 UTC 2022 - Matej Cepl <mcepl@suse.com>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#
|
#
|
||||||
# spec file for package python-ast_decompiler
|
# spec file for package python-ast-decompiler
|
||||||
#
|
#
|
||||||
# Copyright (c) 2022 SUSE LLC
|
# Copyright (c) 2025 SUSE LLC and contributors
|
||||||
#
|
#
|
||||||
# All modifications and additions to the file contributed by third parties
|
# All modifications and additions to the file contributed by third parties
|
||||||
# remain the property of their copyright owners, unless otherwise agreed
|
# remain the property of their copyright owners, unless otherwise agreed
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
|
|
||||||
Name: python-ast-decompiler
|
Name: python-ast-decompiler
|
||||||
Version: 0.7.0
|
Version: 0.8.0
|
||||||
Release: 0
|
Release: 0
|
||||||
Summary: Python module to decompile AST to Python code
|
Summary: Python module to decompile AST to Python code
|
||||||
License: Apache-2.0
|
License: Apache-2.0
|
||||||
@@ -26,12 +26,14 @@ Source: https://files.pythonhosted.org/packages/source/a/ast-decompiler/
|
|||||||
# PATCH-FIX-UPSTREAM no-relative-imports.patch gh#JelleZijlstra/ast_decompiler#52 mcepl@suse.com
|
# PATCH-FIX-UPSTREAM no-relative-imports.patch gh#JelleZijlstra/ast_decompiler#52 mcepl@suse.com
|
||||||
# Fix erroring tests
|
# Fix erroring tests
|
||||||
Patch0: no-relative-imports.patch
|
Patch0: no-relative-imports.patch
|
||||||
BuildRequires: python-rpm-macros
|
# PATCH-FIX-UPSTREAM https://github.com/JelleZijlstra/ast_decompiler/pull/59 Support Python 3.14
|
||||||
BuildRequires: %{python_module pip}
|
Patch1: py314.patch
|
||||||
BuildRequires: %{python_module wheel}
|
|
||||||
BuildRequires: %{python_module flit-core}
|
BuildRequires: %{python_module flit-core}
|
||||||
|
BuildRequires: %{python_module pip}
|
||||||
BuildRequires: %{python_module pytest}
|
BuildRequires: %{python_module pytest}
|
||||||
|
BuildRequires: %{python_module wheel}
|
||||||
BuildRequires: fdupes
|
BuildRequires: fdupes
|
||||||
|
BuildRequires: python-rpm-macros
|
||||||
BuildArch: noarch
|
BuildArch: noarch
|
||||||
%python_subpackages
|
%python_subpackages
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user