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

Pump Version python to 3.12, 3.13. Allow pip install for python 3.12, 3.13 #210

Merged
merged 16 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 0 additions & 1 deletion src/latexify/analyzers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from latexify import analyzers, ast_utils, exceptions, test_utils


@test_utils.require_at_least(8)
@pytest.mark.parametrize(
"code,start,stop,step,start_int,stop_int,step_int",
[
Expand Down
6 changes: 6 additions & 0 deletions src/latexify/ast_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,9 @@ def extract_function_name_or_none(node: ast.Call) -> str | None:
return node.func.attr

return None


def ast_function_def(*args, **kwargs) -> ast.FunctionDef:
maycuatroi marked this conversation as resolved.
Show resolved Hide resolved
if sys.version_info.minor < 12:
kwargs.pop("type_params", None)
return ast.FunctionDef(*args, **kwargs)
maycuatroi marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 0 additions & 6 deletions src/latexify/ast_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def test_make_attribute() -> None:
)


@test_utils.require_at_most(7)
maycuatroi marked this conversation as resolved.
Show resolved Hide resolved
@pytest.mark.parametrize(
maycuatroi marked this conversation as resolved.
Show resolved Hide resolved
"value,expected",
[
Expand All @@ -56,7 +55,6 @@ def test_make_constant_legacy(value: Any, expected: ast.Constant) -> None:
)


@test_utils.require_at_least(8)
@pytest.mark.parametrize(
"value,expected",
[
Expand All @@ -83,7 +81,6 @@ def test_make_constant_invalid() -> None:
ast_utils.make_constant(object())


@test_utils.require_at_most(7)
@pytest.mark.parametrize(
"value,expected",
[
Expand All @@ -101,7 +98,6 @@ def test_is_constant_legacy(value: ast.AST, expected: bool) -> None:
assert ast_utils.is_constant(value) is expected


@test_utils.require_at_least(8)
@pytest.mark.parametrize(
"value,expected",
[
Expand All @@ -114,7 +110,6 @@ def test_is_constant(value: ast.AST, expected: bool) -> None:
assert ast_utils.is_constant(value) is expected


@test_utils.require_at_most(7)
@pytest.mark.parametrize(
"value,expected",
[
Expand All @@ -132,7 +127,6 @@ def test_is_str_legacy(value: ast.AST, expected: bool) -> None:
assert ast_utils.is_str(value) is expected


@test_utils.require_at_least(8)
@pytest.mark.parametrize(
"value,expected",
[
Expand Down
4 changes: 1 addition & 3 deletions src/latexify/codegen/expression_codegen_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pytest

from latexify import ast_utils, exceptions, test_utils
from latexify import ast_utils, exceptions
from latexify.codegen import expression_codegen


Expand Down Expand Up @@ -792,7 +792,6 @@ def test_visit_boolop(code: str, latex: str) -> None:
assert expression_codegen.ExpressionCodegen().visit(tree) == latex


@test_utils.require_at_most(7)
@pytest.mark.parametrize(
"code,cls,latex",
[
Expand All @@ -817,7 +816,6 @@ def test_visit_constant_lagacy(code: str, cls: type[ast.expr], latex: str) -> No
assert expression_codegen.ExpressionCodegen().visit(tree) == latex


@test_utils.require_at_least(8)
@pytest.mark.parametrize(
"code,latex",
[
Expand Down
3 changes: 2 additions & 1 deletion src/latexify/parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest

from latexify import exceptions, parser, test_utils
from latexify.ast_utils import ast_function_def
maycuatroi marked this conversation as resolved.
Show resolved Hide resolved


def test_parse_function_with_posonlyargs() -> None:
Expand All @@ -15,7 +16,7 @@ def f(x):

expected = ast.Module(
body=[
ast.FunctionDef(
ast_function_def(
name="f",
args=ast.arguments(
posonlyargs=[],
Expand Down
3 changes: 2 additions & 1 deletion src/latexify/transformers/assignment_reducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Any

from latexify import exceptions
from latexify.ast_utils import ast_function_def


class AssignmentReducer(ast.NodeTransformer):
Expand Down Expand Up @@ -67,7 +68,7 @@ def visit_FunctionDef(self, node: ast.FunctionDef) -> Any:
# Pop stack
self._assignments = parent_assignments
type_params = getattr(node, "type_params", [])
return ast.FunctionDef(
return ast_function_def(
name=node.name,
args=node.args,
body=[return_transformed],
Expand Down
2 changes: 1 addition & 1 deletion src/latexify/transformers/assignment_reducer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _make_ast(body: list[ast.stmt]) -> ast.Module:
"""
return ast.Module(
body=[
ast.FunctionDef(
ast_utils.ast_function_def(
name="f",
args=ast.arguments(
args=[ast.arg(arg="x")],
Expand Down
2 changes: 1 addition & 1 deletion src/latexify/transformers/docstring_remover_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def f():
tree = parser.parse_function(f).body[0]
assert isinstance(tree, ast.FunctionDef)

expected = ast.FunctionDef(
expected = ast_utils.ast_function_def(
name="f",
body=[
ast.Assign(
Expand Down
5 changes: 3 additions & 2 deletions src/latexify/transformers/identifier_replacer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

import ast
import keyword
import sys
from typing import cast

from latexify.ast_utils import ast_function_def


class IdentifierReplacer(ast.NodeTransformer):
"""NodeTransformer to replace identifier names.
Expand Down Expand Up @@ -59,7 +60,7 @@ def visit_FunctionDef(self, node: ast.FunctionDef) -> ast.FunctionDef:
defaults=visited.args.defaults,
)
type_params = getattr(visited, "type_params", [])
return ast.FunctionDef(
return ast_function_def(
name=self._mapping.get(visited.name, visited.name),
args=args,
body=visited.body,
Expand Down
55 changes: 3 additions & 52 deletions src/latexify/transformers/identifier_replacer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest

from latexify import test_utils
from latexify.ast_utils import ast_function_def
from latexify.transformers.identifier_replacer import IdentifierReplacer


Expand Down Expand Up @@ -35,62 +36,12 @@ def test_name_not_replaced() -> None:
test_utils.assert_ast_equal(transformed, expected)


@test_utils.require_at_most(7)
def test_functiondef() -> None:
# Subtree of:
# @d
# def f(y=b, *, z=c):
# pass
source = ast.FunctionDef(
name="f",
args=ast.arguments(
posonlyargs=[],
args=[ast.arg(arg="y")],
kwonlyargs=[ast.arg(arg="z")],
kw_defaults=[ast.Name(id="c", ctx=ast.Load())],
defaults=[
ast.Name(id="a", ctx=ast.Load()),
ast.Name(id="b", ctx=ast.Load()),
],
),
body=[ast.Pass()],
decorator_list=[ast.Name(id="d", ctx=ast.Load())],
returns=None,
type_comment=None,
type_params=[],
)

expected = ast.FunctionDef(
name="F",
args=ast.arguments(
posonlyargs=[],
args=[ast.arg(arg="Y")],
kwonlyargs=[ast.arg(arg="Z")],
kw_defaults=[ast.Name(id="C", ctx=ast.Load())],
defaults=[
ast.Name(id="a", ctx=ast.Load()),
ast.Name(id="b", ctx=ast.Load()),
],
),
body=[ast.Pass()],
decorator_list=[ast.Name(id="d", ctx=ast.Load())],
returns=None,
type_comment=None,
type_params=[],
)

mapping = {x: x.upper() for x in "abcdfyz"}
transformed = IdentifierReplacer(mapping).visit(source)
test_utils.assert_ast_equal(transformed, expected)


@test_utils.require_at_least(8)
def test_functiondef_with_posonlyargs() -> None:
# Subtree of:
# @d
# def f(x=a, /, y=b, *, z=c):
# pass
source = ast.FunctionDef(
source = ast_function_def(
name="f",
args=ast.arguments(
posonlyargs=[ast.arg(arg="x")],
Expand All @@ -109,7 +60,7 @@ def test_functiondef_with_posonlyargs() -> None:
type_params=[],
)

expected = ast.FunctionDef(
expected = ast_function_def(
name="F",
args=ast.arguments(
posonlyargs=[ast.arg(arg="X")],
Expand Down
Loading