From 58388fc0f3d7950dad5eac9f4ff9643e992c9082 Mon Sep 17 00:00:00 2001 From: Juha Jeronen Date: Fri, 27 Sep 2024 14:31:30 +0300 Subject: [PATCH] lazify, autocurry: leave `type` statements alone --- unpythonic/syntax/autocurry.py | 5 +++++ unpythonic/syntax/lazify.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/unpythonic/syntax/autocurry.py b/unpythonic/syntax/autocurry.py index ea8c398c..18c83f91 100644 --- a/unpythonic/syntax/autocurry.py +++ b/unpythonic/syntax/autocurry.py @@ -10,6 +10,7 @@ from mcpyrate.quotes import is_captured_value from mcpyrate.walkers import ASTTransformer +from .astcompat import TypeAlias from .util import (suggest_decorator_index, isx, has_curry, sort_lambda_decorators) from ..dynassign import dyn @@ -85,6 +86,10 @@ def transform(self, tree): if is_captured_value(tree): return tree + # Python 3.12+: leave `type` statements alone (autocurrying a type declaration makes no sense) + if type(tree) is TypeAlias: + return tree + hascurry = self.state.hascurry if type(tree) is Call: # Don't auto-curry some calls we know not to need it. This is both a performance optimization diff --git a/unpythonic/syntax/lazify.py b/unpythonic/syntax/lazify.py index 0115805c..c63a78e4 100644 --- a/unpythonic/syntax/lazify.py +++ b/unpythonic/syntax/lazify.py @@ -14,6 +14,7 @@ from mcpyrate.unparser import unparse from mcpyrate.walkers import ASTTransformer +from .astcompat import TypeAlias from .util import (suggest_decorator_index, sort_lambda_decorators, detect_lambda, isx, getname, is_decorator) from .letdoutil import islet, isdo, ExpandedLetView @@ -648,6 +649,10 @@ def f(tree): # else forcing_mode == "off" return tree + # Python 3.12+: leave `type` statements alone (lazifying a type declaration makes no sense) + elif type(tree) is TypeAlias: + return tree + elif type(tree) in (FunctionDef, AsyncFunctionDef, Lambda): if type(tree) is Lambda and id(tree) not in userlambdas: return self.generic_visit(tree) # ignore macro-introduced lambdas (but recurse inside them)