Skip to content

Commit

Permalink
lazify, autocurry: leave type statements alone
Browse files Browse the repository at this point in the history
  • Loading branch information
Technologicat committed Sep 27, 2024
1 parent 4084a29 commit 58388fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions unpythonic/syntax/autocurry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions unpythonic/syntax/lazify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 58388fc

Please sign in to comment.