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

define type_params on gast.ClassDef instantiation to support compatibility with python>=3.12 #28858

Merged
merged 5 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions .github/workflows/test-transpiler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ on:
jobs:

transformations:
strategy:
matrix:
python-version: ["3.10", "3.12"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -18,14 +21,17 @@ jobs:
persist-credentials: false
- uses: actions/setup-python@v3
with:
python-version: "3.10"
python-version: ${{ matrix.python-version }}
- name: Run Transformations Tests
id: tests
run: |
cd ivy
docker run --rm -v "$(pwd)":/ivy ivyllc/ivy:latest scripts/shell/run_transpiler_tests.sh transformations

translations:
strategy:
matrix:
python-version: ["3.10", "3.12"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -34,14 +40,17 @@ jobs:
persist-credentials: false
- uses: actions/setup-python@v3
with:
python-version: "3.10"
python-version: ${{ matrix.python-version }}
- name: Run Translations Tests
id: tests
run: |
cd ivy
docker run --rm -v "$(pwd)":/ivy ivyllc/ivy:latest scripts/shell/run_transpiler_tests.sh translations

module:
strategy:
matrix:
python-version: ["3.10", "3.12"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -50,15 +59,17 @@ jobs:
persist-credentials: false
- uses: actions/setup-python@v3
with:
python-version: "3.10"

python-version: ${{ matrix.python-version }}
- name: Run Module Tests
id: tests
run: |
cd ivy
docker run --rm -v "$(pwd)":/ivy ivyllc/ivy:latest scripts/shell/run_transpiler_tests.sh module

sourcegen:
strategy:
matrix:
python-version: ["3.10", "3.12"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -67,14 +78,17 @@ jobs:
persist-credentials: false
- uses: actions/setup-python@v3
with:
python-version: "3.10"
python-version: ${{ matrix.python-version }}
- name: Run SourceGen Tests
id: tests
run: |
cd ivy
docker run --rm -v "$(pwd)":/ivy ivyllc/ivy:latest scripts/shell/run_transpiler_tests.sh sourcegen

hf:
strategy:
matrix:
python-version: ["3.10", "3.12"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -83,14 +97,17 @@ jobs:
persist-credentials: false
- uses: actions/setup-python@v3
with:
python-version: "3.10"
python-version: ${{ matrix.python-version }}
- name: Run HuggingFace Tests
id: tests
run: |
cd ivy
docker run --rm -v "$(pwd)":/ivy ivyllc/ivy:latest scripts/shell/run_transpiler_tests.sh hf

kornia:
strategy:
matrix:
python-version: ["3.10", "3.12"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -99,7 +116,7 @@ jobs:
persist-credentials: false
- uses: actions/setup-python@v3
with:
python-version: "3.10"
python-version: ${{ matrix.python-version }}
- name: Run Kornia Tests
id: tests
run: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# global
from ast import FunctionDef
import gast
import inspect
import textwrap
Expand All @@ -10,7 +9,6 @@
)
from ...transformer import Transformer
from ....utils import pickling_utils
from ....utils.api_utils import is_frontend_stateful_api
from ....utils.ast_utils import (
ast_to_source_code,
is_super_call_node,
Expand Down Expand Up @@ -115,6 +113,7 @@ def visit_ClassDef(self, node):
decorator_list=method_node.decorator_list,
returns=method_node.returns,
type_comment=method_node.type_comment,
type_params=method_node.type_params if hasattr(method_node, "type_params") else [],
)
new_method_node = gast.copy_location(new_method_node, method_node)
BaseRenameTransformer(new_method_node).rename(
Expand Down Expand Up @@ -161,6 +160,7 @@ def visit_Module(self, node):
keywords=cls_node.keywords,
body=[*cls_node.body, *method_nodes_to_add],
decorator_list=cls_node.decorator_list,
type_params=cls_node.type_params if hasattr(cls_node, "type_params") else [],
)
new_node = gast.copy_location(new_node, cls_node)
# attach origin info to the new node
Expand Down Expand Up @@ -224,6 +224,7 @@ def remove_explicit_self_from_super_init(node):
decorator_list=method_node.decorator_list,
returns=method_node.returns,
type_comment=method_node.type_comment,
type_params=method_node.type_params if hasattr(method_node, "type_params") else [],
)
new_method_node = gast.copy_location(new_method_node, method_node)
self._method_nodes_to_add.append(new_method_node)
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ astor
cryptography>=40.0.0
dill
einops
gast<=0.5.4
gast
networkx
numpy
packaging
Expand Down
Loading