Skip to content

Commit

Permalink
Merge pull request hylang#2445 from scauligi/py312-what-are-type-params
Browse files Browse the repository at this point in the history
Deal with new Python 3.12 AST changes
  • Loading branch information
Kodiologist authored May 26, 2023
2 parents 152cd21 + 7f20bfc commit ff9bbfe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions hy/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
PY3_9 = sys.version_info >= (3, 9)
PY3_10 = sys.version_info >= (3, 10)
PY3_11 = sys.version_info >= (3, 11)
PY3_12 = sys.version_info >= (3, 12)
PYPY = platform.python_implementation() == "PyPy"
PYODIDE = platform.system() == "Emscripten"

Expand Down
6 changes: 5 additions & 1 deletion hy/core/result_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from funcparserlib.parser import finished, forward_decl, many, maybe, oneplus, some

from hy._compat import PY3_11
from hy._compat import PY3_11, PY3_12
from hy.compiler import Result, asty, hy_eval, mkexpr
from hy.errors import HyEvalError, HyInternalError, HyTypeError
from hy.macros import pattern_macro, require, require_reader
Expand Down Expand Up @@ -896,6 +896,7 @@ def f(parts):
),
body=stmts + f(parts).stmts,
decorator_list=[],
**({"type_params": []} if PY3_12 else {}),
)
# Immediately call the new function. Unless the user asked
# for a generator, wrap the call in `[].__class__(...)` or
Expand Down Expand Up @@ -1134,6 +1135,7 @@ def compile_match_expression(compiler, expr, root, subject, clauses):
),
body=guard.stmts + [asty.Return(guard.expr, value=guard.expr)],
decorator_list=[],
**({"type_params": []} if PY3_12 else {}),
)
lifted_if_defs.append(guardret)
guard = Result(expr=asty.parse(guard, f"{fname}()").body[0].value)
Expand Down Expand Up @@ -1466,6 +1468,7 @@ def compile_function_node(compiler, expr, node, decorators, name, args, returns,
body=body.stmts or [asty.Pass(expr)],
decorator_list=decorators,
returns=compiler.compile(returns).force_expr if returns is not None else None,
**({"type_params": []} if PY3_12 else {}),
)

ast_name = asty.Name(expr, id=name, ctx=ast.Load())
Expand Down Expand Up @@ -1679,6 +1682,7 @@ def compile_class_expression(compiler, expr, root, decorators, name, rest):
kwargs=None,
bases=bases_expr,
body=bodyr.stmts or [asty.Pass(expr)],
**({"type_params": []} if PY3_12 else {}),
)


Expand Down

0 comments on commit ff9bbfe

Please sign in to comment.