Skip to content

Commit 7c7c0ae

Browse files
committed
pyp: drop support for python 3.8
1 parent e117ca8 commit 7c7c0ae

7 files changed

Lines changed: 19 additions & 69 deletions

File tree

‎.github/workflows/tests.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ jobs:
2626
fail-fast: false
2727
matrix:
2828
include:
29-
- {python: '3.8', tox: py38}
3029
- {python: '3.9', tox: py39}
3130
- {python: '3.10', tox: py310}
3231
- {python: '3.11', tox: py311}

‎FAQ.md‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,6 @@ ff = defaultdict(lambda: None, dict(enumerate(x.split())))
6464
d = defaultdict(list)
6565
```
6666

67-
#### What are pyp's dependencies?
68-
69-
If run on Python 3.9 or later, pyp has no dependencies.
70-
71-
On earlier Python versions, pyp is dependent on [astunparse](https://github.com/simonpercivall/astunparse)
72-
for `--explain`/`--script` to work as promised. Note you can use `pyp.py` as a Python script without
73-
installing `astunparse` and everything else will work. (In fact `--script` will still output a
74-
script that does what you want it to, but it won't be particularly readable...)
75-
7667
#### Can I customise the shebang on the output of `--script`?
7768

7869
Yes! Just add the shebang you want to your [config file](https://github.com/hauntsaninja/pyp#pyp-is-configurable).
@@ -81,10 +72,7 @@ of `--explain`/`--script`.
8172

8273
#### The output of `--explain` is a little weirdly formatted
8374

84-
Try running with Python 3.9 or later! The AST unparser that the standard library includes in 3.9
85-
and later fixes a lot of formatting nits that are present in third party AST unparsers.
86-
87-
You can also pipe the output of `pyp --explain` to an autoformatter like [black](https://github.com/psf/black):
75+
You can pipe the output of `pyp --explain` to an autoformatter like [black](https://github.com/psf/black):
8876

8977
```
9078
$ pyp --explain x | black --quiet -
@@ -144,4 +132,4 @@ Benchmark #1: seq 1 999999 | pyp 'sum(map(int, lines))'
144132
You should be able to use PyPy! Tests currently pass against PyPy (run `tox -e pypy3`).
145133
You can install pyp using PyPy with something like `pypy3 -m pip install pypyp`.
146134
Running `pyp sys.version` will tell you whether it worked. Note that pyp requires at least
147-
Python 3.8; this constraint naturally applies when using PyPy as well.
135+
Python 3.9; this constraint naturally applies when using PyPy as well.

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ You can also install pyp in other ways:
1616
- [nixpkgs](https://search.nixos.org/packages?channel=unstable&show=pyp)
1717
- [AUR](https://aur.archlinux.org/packages/pyp)
1818

19-
pyp requires Python 3.8 or above.
19+
pyp requires Python 3.9 or above.
2020

2121
## How it works
2222

‎pyp.py‎

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -600,43 +600,12 @@ def build(self) -> ast.Module:
600600
return ast.fix_missing_locations(ret)
601601

602602

603-
def unparse(tree: ast.AST, short_fallback: bool = False) -> str:
604-
"""Returns Python code equivalent to executing ``tree``."""
605-
if sys.version_info >= (3, 9):
606-
return ast.unparse(tree)
607-
try:
608-
import astunparse # type: ignore
609-
610-
return cast(str, astunparse.unparse(tree))
611-
except ImportError:
612-
pass
613-
return (
614-
fallback_unparse(tree)
615-
if not short_fallback
616-
else f"# {ast.dump(tree)} # --explain has instructions to make this readable"
617-
)
618-
619-
620-
def fallback_unparse(tree: ast.AST) -> str:
621-
return f"""
622-
from ast import *
623-
tree = fix_missing_locations({ast.dump(tree)})
624-
625-
# To see this in human readable form, run pyp with Python 3.9
626-
# Alternatively, install a third party ast unparser: `python3 -m pip install astunparse`
627-
# Once you've done that, simply re-run.
628-
# In the meantime, this script is fully functional, if not easily readable or modifiable...
629-
630-
exec(compile(tree, filename="<ast>", mode="exec"), {{}})
631-
"""
632-
633-
634603
def run_pyp(args: argparse.Namespace) -> None:
635604
config = PypConfig()
636605
tree = PypTransform(args.before, args.code, args.after, args.define_pypprint, config).build()
637606
if args.explain:
638607
print(config.shebang)
639-
print(unparse(tree))
608+
print(ast.unparse(tree))
640609
return
641610
try:
642611
exec(compile(tree, filename="<pyp>", mode="exec"), {})
@@ -654,7 +623,7 @@ def code_for_line(lineno: int) -> str:
654623
for _, value in ast.iter_fields(node):
655624
if isinstance(value, list) and value and isinstance(value[0], ast.stmt):
656625
value.clear()
657-
return unparse(node, short_fallback=True).strip()
626+
return ast.unparse(node).strip()
658627

659628
# Time to commit several sins against CPython implementation details
660629
tb_except = traceback.TracebackException(

‎pyproject.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ classifiers = [
1414
"Topic :: Software Development",
1515
"Topic :: Utilities",
1616
]
17-
requires-python = ">=3.8"
18-
dependencies = ["astunparse; python_version<'3.9'"]
17+
requires-python = ">=3.9"
18+
dependencies = []
1919

2020
[project.scripts]
2121
pyp = "pyp:main"

‎tests/test_find_names.py‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,17 @@ def test_walrus():
146146
check_find_names("{(x := y): (y := 1) for _ in range(5)}", {"x", "y"}, {"y", "range"})
147147
check_find_names("{(x := 1): (y := x) for _ in range(5)}", {"x", "y"}, {"range"})
148148

149-
if sys.version_info >= (3, 9):
150-
check_find_names(
151-
"d1 = lambda i: i\n@(d2 := d1)\n@(d3 := d2)\ndef f(): ...",
152-
{"d1", "d2", "d3", "f"},
153-
set(),
154-
)
155-
check_find_names(
156-
"d1 = id\n@(d3 := d2)\n@(d2 := d1)\ndef f(): ...", {"d1", "d2", "d3", "f"}, {"d2", "id"}
157-
)
158-
check_find_names(
159-
"d1 = lambda i: i\n@(d2 := d1)\ndef f(x=d2): (x, d2)", {"d1", "d2", "f"}, set()
160-
)
149+
check_find_names(
150+
"d1 = lambda i: i\n@(d2 := d1)\n@(d3 := d2)\ndef f(): ...",
151+
{"d1", "d2", "d3", "f"},
152+
set(),
153+
)
154+
check_find_names(
155+
"d1 = id\n@(d3 := d2)\n@(d2 := d1)\ndef f(): ...", {"d1", "d2", "d3", "f"}, {"d2", "id"}
156+
)
157+
check_find_names(
158+
"d1 = lambda i: i\n@(d2 := d1)\ndef f(x=d2): (x, d2)", {"d1", "d2", "f"}, set()
159+
)
161160

162161

163162
def test_comprehensions():

‎tests/test_pyp.py‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,7 @@ def compare_scripts(explain_output: str, script: str) -> None:
6868
"""Tests whether two scripts are equivalent."""
6969
explain_output = explain_output.strip("\n")
7070
script = script.strip("\n")
71-
if sys.version_info < (3, 9):
72-
# astunparse seems to parenthesise things slightly differently, so filter through ast to
73-
# hackily ensure that the scripts are the same.
74-
assert pyp.unparse(ast.parse(explain_output)) == pyp.unparse(ast.parse(script))
75-
else:
76-
assert explain_output == script
71+
assert explain_output == script
7772

7873

7974
# ====================

0 commit comments

Comments
 (0)