Skip to content

Commit 58388fc

Browse files
committed
lazify, autocurry: leave type statements alone
1 parent 4084a29 commit 58388fc

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

unpythonic/syntax/autocurry.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from mcpyrate.quotes import is_captured_value
1111
from mcpyrate.walkers import ASTTransformer
1212

13+
from .astcompat import TypeAlias
1314
from .util import (suggest_decorator_index, isx, has_curry, sort_lambda_decorators)
1415

1516
from ..dynassign import dyn
@@ -85,6 +86,10 @@ def transform(self, tree):
8586
if is_captured_value(tree):
8687
return tree
8788

89+
# Python 3.12+: leave `type` statements alone (autocurrying a type declaration makes no sense)
90+
if type(tree) is TypeAlias:
91+
return tree
92+
8893
hascurry = self.state.hascurry
8994
if type(tree) is Call:
9095
# Don't auto-curry some calls we know not to need it. This is both a performance optimization

unpythonic/syntax/lazify.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from mcpyrate.unparser import unparse
1515
from mcpyrate.walkers import ASTTransformer
1616

17+
from .astcompat import TypeAlias
1718
from .util import (suggest_decorator_index, sort_lambda_decorators, detect_lambda,
1819
isx, getname, is_decorator)
1920
from .letdoutil import islet, isdo, ExpandedLetView
@@ -648,6 +649,10 @@ def f(tree):
648649
# else forcing_mode == "off"
649650
return tree
650651

652+
# Python 3.12+: leave `type` statements alone (lazifying a type declaration makes no sense)
653+
elif type(tree) is TypeAlias:
654+
return tree
655+
651656
elif type(tree) in (FunctionDef, AsyncFunctionDef, Lambda):
652657
if type(tree) is Lambda and id(tree) not in userlambdas:
653658
return self.generic_visit(tree) # ignore macro-introduced lambdas (but recurse inside them)

0 commit comments

Comments
 (0)