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 1 commit
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build-backend = "hatchling.build"
name = "latexify-py"
description = "Generates LaTeX math description from Python functions."
readme = "README.md"
requires-python = ">=3.7, <3.13"
requires-python = ">=3.9, <3.14"
license = {text = "Apache Software License 2.0"}
authors = [
{name = "Yusuke Oda", email = "[email protected]"}
Expand All @@ -24,12 +24,11 @@ classifiers = [
"Framework :: IPython",
"Framework :: Jupyter",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Scientific/Engineering :: Mathematics",
"Topic :: Software Development :: Code Generators",
"Topic :: Text Processing :: Markup :: LaTeX",
Expand Down
30 changes: 11 additions & 19 deletions src/latexify/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,15 @@ def ast_equal(observed: ast.AST, expected: ast.AST) -> bool:
Returns:
True if observed and expected represent the same AST, False otherwise.
"""
ignore_keys = {"lineno", "col_offset", "end_lineno", "end_col_offset", "kind"}
if sys.version_info.minor <= 12:
ignore_keys.add("type_params")

try:
assert type(observed) is type(expected)

for k, ve in vars(expected).items():
if k in {"col_offset", "end_col_offset", "end_lineno", "kind", "lineno"}:
if k in ignore_keys:
continue

vo = getattr(observed, k) # May cause AttributeError.
Expand All @@ -93,8 +97,8 @@ def ast_equal(observed: ast.AST, expected: ast.AST) -> bool:
assert type(vo) is type(ve)
assert vo == ve

except (AssertionError, AttributeError):
return False
except (AssertionError, AttributeError) as e:
raise e # raise to debug easier.
maycuatroi marked this conversation as resolved.
Show resolved Hide resolved

return True

Expand All @@ -109,19 +113,7 @@ def assert_ast_equal(observed: ast.AST, expected: ast.AST) -> None:
Raises:
AssertionError: observed and expected represent different ASTs.
"""
if sys.version_info.minor >= 9:
assert ast_equal(
observed, expected
), f"""\
AST does not match.
observed={ast.dump(observed, indent=4)}
expected={ast.dump(expected, indent=4)}
"""
else:
assert ast_equal(
observed, expected
), f"""\
AST does not match.
observed={ast.dump(observed)}
expected={ast.dump(expected)}
"""
indent = 4 if sys.version_info.minor >= 9 else None
assert ast_equal(
observed, expected
), f"AST does not match. observed = {observed}\nexpected = {expected}"
maycuatroi marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions src/latexify/transformers/assignment_reducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ def visit_FunctionDef(self, node: ast.FunctionDef) -> Any:

# Pop stack
self._assignments = parent_assignments

type_params = getattr(node, "type_params", [])
return ast.FunctionDef(
name=node.name,
args=node.args,
body=[return_transformed],
decorator_list=node.decorator_list,
returns=node.returns,
type_params=node.type_params,
type_params=type_params,
)

def visit_Name(self, node: ast.Name) -> Any:
Expand Down
4 changes: 2 additions & 2 deletions src/latexify/transformers/identifier_replacer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ def visit_FunctionDef(self, node: ast.FunctionDef) -> ast.FunctionDef:
kwarg=visited.args.kwarg,
defaults=visited.args.defaults,
)

type_params = getattr(visited, "type_params", [])
return ast.FunctionDef(
name=self._mapping.get(visited.name, visited.name),
args=args,
body=visited.body,
decorator_list=visited.decorator_list,
returns=visited.returns,
type_params=visited.type_params,
type_params=type_params,
)

def visit_Name(self, node: ast.Name) -> ast.Name:
Expand Down