Skip to content

Commit

Permalink
Merge pull request #164 from rocky/go-over-add-test
Browse files Browse the repository at this point in the history
Fix up add-test for 3.8pypy ..
  • Loading branch information
rocky authored Feb 29, 2024
2 parents 4d97123 + c469ec8 commit beab1ff
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 12 deletions.
4 changes: 2 additions & 2 deletions decompyle3/bin/decompile.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def usage():
)
@click.argument("files", nargs=-1, type=click.Path(readable=True), required=True)
def main_bin(
asm: bool,
asm_plus: bool,
asm: bool,
show_grammar,
tree: bool,
tree_plus: bool,
Expand All @@ -96,7 +96,7 @@ def main_bin(
outfile,
start_offset: int,
stop_offset: int,
files,
files: List[str],
):
"""
Cross Python bytecode decompiler for Python 3.7-3.8 bytecode
Expand Down
35 changes: 25 additions & 10 deletions test/add-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
""" Trivial helper program to bytecompile and run an uncompile
"""
import os
import platform
import py_compile
import sys
from typing import List

import click
from xdis.version_info import version_tuple_to_str
Expand All @@ -26,13 +28,29 @@
]
),
)
@click.option(
"--asm++/--no-asm++",
"-A",
"asm_plus",
default=False,
help="show xdis assembler and tokenized assembler",
)
@click.option("--asm/--no-asm", "-a", "show_asm", default=False)
@click.option("--grammar/--no-grammar", "-g", default=False)
@click.option("--tree/--no-tree", "-t", default=False)
@click.option("--tree++/--no-tree++", "-T", "tree_plus", default=False)
@click.option("--optimize", "-O", default=-1)
@click.argument("files", nargs=-1, type=click.Path(readable=True), required=True)
def main(code_format, show_asm, grammar, tree, tree_plus, optimize, files):
def main(
code_format,
asm_plus: bool,
show_asm: bool,
grammar,
tree: bool,
tree_plus: bool,
optimize,
files: List[str],
):
"""Byte compile file and place it in the right category of testing bytecode."""

assert 2 <= len(sys.argv) <= 4
Expand All @@ -50,17 +68,14 @@ def main(code_format, show_asm, grammar, tree, tree_plus, optimize, files):
short = os.path.basename(path)
if short.endswith(".py"):
short = short[: -len(".py")]
if hasattr(sys, "pypy_version_info"):
version = version_tuple_to_str(end=2, delimiter="")
bytecode = f"bytecode_pypy{version}/{suffix}/{short}py{version}.pyc"
version = version_tuple_to_str(end=2)
pypy = "pypy" if platform.python_implementation() == "PyPy" else ""
if suffix in ("exec", "run"):
bytecode = f"bytecode_{version}{pypy}/{suffix}/{short}.pyc"
else:
version = version_tuple_to_str(end=2)
if suffix in ("exec", "run"):
bytecode = f"bytecode_{version}/{suffix}/{short}.pyc"
else:
bytecode = f"bytecode_{version}/code-fragment/{suffix}/{short}.pyc"
bytecode = f"bytecode_{version}{pypy}/code-fragment/{suffix}/{short}.pyc"

print(f"byte-compiling {path} to {bytecode}")
print(f"byte-compiling {path} to {bytecode}")
py_compile.compile(path, bytecode, optimize=optimize)
if code_format in ("exec", "run"):
os.system(f"../bin/decompyle3 {decompile_opts} {bytecode}")
Expand Down
Binary file modified test/bytecode_3.8/code-fragment/list-comprehension/03_async.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions test/simple_source/bug38pypy/01_basic_list_comprehension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 3.8 PyPy uses PyPy-specific BUILD_LIST_FROM_ARG
# fmt: off
[func for func
in
__file__]
70 changes: 70 additions & 0 deletions test/simple_source/comprehension/03_async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# These are an accumulation of list comprehensions using "async" or "await.
# They were culled from all list comprehensions on my disk under Python 3.8.

# From Python 3.8 tqdm/asyncio.py
# Note we need to add the "async def" for this list comprehension

# fmt: off
async def gather(cls, *fs, loop=None, timeout=None, total=None, **tqdm_kwargs):
[await f
for f in
cls.as_completed(
loop=loop,
total=total,
**tqdm_kwargs)]


# From Python 3.8 test/test_asyncgen.py
async def arange(n):
[i
async
for i
in range(10)
]

# From Python 3.8 test/test_coroutines.py

def make_brange(n):
return (i * 2
async
for i
in range(20))

# We were not parsing the "if" as one unit.
async def run_list():
return [i
async for i
in range(5)
if 0 <
i <
4]

# Another "if" parsing problem
async def run_list2():
return [i + 1
for pair in
([10, 20], [30, 40])
if pair > 10
async
for i in
ord(pair)
if i > 30]


async def run_list3():
return [i
async for i
in range(5)
if 0 <
i <
4]

# Adapted from line 2071 of 3.8.12 lib/python3.8/test/test_coroutines.py
# The bug was in the iterator tgt[0] which needs a
# store_subscript rule.
async def run_list4(tgt):
return [0
async for
tgt[0] in
__file__
]
70 changes: 70 additions & 0 deletions test/simple_source/list_comprehension_start/03_async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# These are an accumulation of list comprehensions using "async" or "await.
# They were culled from all list comprehensions on my disk under Python 3.8.

# From Python 3.8 tqdm/asyncio.py
# Note we need to add the "async def" for this list comprehension

# fmt: off
async def gather(cls, *fs, loop=None, timeout=None, total=None, **tqdm_kwargs):
[await f
for f in
cls.as_completed(
loop=loop,
total=total,
**tqdm_kwargs)]


# From Python 3.8 test/test_asyncgen.py
async def arange(n):
[i
async
for i
in range(10)
]

# From Python 3.8 test/test_coroutines.py

def make_brange(n):
return (i * 2
async
for i
in range(20))

# We were not parsing the "if" as one unit.
async def run_list():
return [i
async for i
in range(5)
if 0 <
i <
4]

# Another "if" parsing problem
async def run_list2():
return [i + 1
for pair in
([10, 20], [30, 40])
if pair > 10
async
for i in
ord(pair)
if i > 30]


async def run_list3():
return [i
async for i
in range(5)
if 0 <
i <
4]

# Adapted from line 2071 of 3.8.12 lib/python3.8/test/test_coroutines.py
# The bug was in the iterator tgt[0] which needs a
# store_subscript rule.
async def run_list4(tgt):
return [0
async for
tgt[0] in
__file__
]

0 comments on commit beab1ff

Please sign in to comment.