Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.9 ast changes #333

Merged
merged 4 commits into from
Mar 20, 2021
Merged

Python 3.9 ast changes #333

merged 4 commits into from
Mar 20, 2021

Conversation

mattst88
Copy link
Contributor

The ast module in Python 3.9 has some API changes. Quoting [1]:

Simplified AST for subscription. Simple indices will be represented by their value, extended slices will be represented as tuples. Index(value) will return a value itself, ExtSlice(slices) will return Tuple(slices, Load()). (Contributed by Serhiy Storchaka in bpo-34822.)

The second patch is still a work-in-progress, for two reasons: I don't know if the bit I added is functionally correct (though it resolves 20/24 of the test failures), and I don't know how to handle ast.Call (and potentially anything else) that seems to be the cause of the remaining 4 failures.

Help required.

[1] https://docs.python.org/3/whatsnew/3.9.html#changes-in-the-python-api

@mcepl
Copy link
Contributor

mcepl commented Mar 15, 2021

  1. Please add this patch:
From 97a1a57137e075ee00879ee663e057f7e3c78147 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mat=C4=9Bj=20Cepl?= <mcepl@cepl.eu>
Date: Mon, 15 Mar 2021 22:06:35 +0100
Subject: [PATCH rope] Test for Python 3.9 as well

---
 .github/workflows/main.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 229dd195..eef68621 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -9,7 +9,7 @@ jobs:
 
     strategy:
       matrix:
-        python-version: [2.7, 3.5, 3.6, 3.7, 3.8]
+        python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9]
 
     steps:
     - uses: actions/checkout@v2
-- 
2.30.2
  1. Open this pull request for contributions from maintainers (right column, bottom)

@mattst88
Copy link
Contributor Author

Done and Done (I see "Allow edits by maintainers" checked)

mcepl and others added 4 commits March 19, 2021 18:46
Fixes the following two tests under Python 3.9:

FAILED ropetest/refactor/patchedasttest.py::PatchedASTTest::test_ext_slice_node - AssertionError: Node <ExtSlice> cannot be found
FAILED ropetest/refactor/patchedasttest.py::PatchedASTTest::test_simple_subscript - AssertionError: False is not true : Expected <Index> but was <Constant>

The ast module in Python 3.9 has some API changes. Quoting [1]:

    Simplified AST for subscription. Simple indices will be represented
    by their value, extended slices will be represented as tuples.
    Index(value) will return a value itself, ExtSlice(slices) will
    return Tuple(slices, Load()). (Contributed by Serhiy Storchaka in
    bpo-34822.)

[1] https://docs.python.org/3/whatsnew/3.9.html#changes-in-the-python-api
The ast module in Python 3.9 has some API changes. Quoting [1]:

    Simplified AST for subscription. Simple indices will be represented
    by their value, extended slices will be represented as tuples.
    Index(value) will return a value itself, ExtSlice(slices) will
    return Tuple(slices, Load()). (Contributed by Serhiy Storchaka in
    bpo-34822.)

[1] https://docs.python.org/3/whatsnew/3.9.html#changes-in-the-python-api

isinstance(thing, ast.Index) always return false in Python >= 3.9, so we
need to handle... whatever the value is now. ast.expr catches 20 of the
remaining 24 failures. The remaining 4 are resolved in the next patch.

Fixes: #299
The ast module in Python 3.9 has some API changes. Quoting [1]:

    Simplified AST for subscription. Simple indices will be represented
    by their value, extended slices will be represented as tuples.
    Index(value) will return a value itself, ExtSlice(slices) will
    return Tuple(slices, Load()). (Contributed by Serhiy Storchaka in
    bpo-34822.)

[1] https://docs.python.org/3/whatsnew/3.9.html#changes-in-the-python-api

This fixes the remaining 4 failures under Python 3.9.

FAILED ropetest/advanced_oi_test.py::NewStaticOITest::test_static_oi_for_dicts_depending_on_append_function
FAILED ropetest/advanced_oi_test.py::NewStaticOITest::test_static_oi_for_dicts_depending_on_for_loops
FAILED ropetest/advanced_oi_test.py::NewStaticOITest::test_static_oi_for_dicts_depending_on_update
FAILED ropetest/advanced_oi_test.py::NewStaticOITest::test_static_oi_for_lists_per_object_for_set_item

Fixes: #299
@mattst88
Copy link
Contributor Author

Okay. I fixed the remaining four failures. I feel like I'm just banging on it with a hammer until it works, so someone please review. :)

@mcepl
Copy link
Contributor

mcepl commented Mar 20, 2021

Thank you, thank you, thank you!

@mcepl mcepl merged commit 4dba2ff into python-rope:master Mar 20, 2021
@mattst88 mattst88 deleted the python-3.9-ast-changes branch March 20, 2021 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants