Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Allow deeper recursion in mypy daemon, better error reporting#17707

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
hauntsaninja merged 10 commits intopython:masterfromkcdodd:issue-17706
Apr 17, 2025
Merged
Changes from1 commit
Commits
Show all changes
10 commits
Select commitHold shift + click to select a range
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
PrevPrevious commit
NextNext commit
change unparse to ast.NodeVisitor
  • Loading branch information
@kcdodd
kcdodd committedAug 24, 2024
commitcc875de497b98e377281d6da6940202b9d455a38
58 changes: 29 additions & 29 deletionsmypy/fastparse.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -240,6 +240,34 @@ def parse(
strip_function_bodies=strip_function_bodies,
path=fnam,
).visit(ast)


except RecursionError as e:
# For very complex expressions it is possible to hit recursion limit
# before reaching a leaf node.
# Should reject at top level instead at bottom, since bottom would already
# be at the threshold of the recursion limit, and may fail again later.
# E.G. x1+x2+x3+...+xn -> BinOp(left=BinOp(left=BinOp(left=...
try:
# But to prove that is the cause of this particular recursion error,
# try to walk the tree using builtin visitor
ast3.NodeVisitor().visit(ast)
except RecursionError:
errors.report(
-1,
-1,
"Source expression too complex to parse",
blocker=False,
code=codes.MISC,
)

tree = MypyFile([], [], False, {})

else:
# re-raise original recursion error if it *can* be unparsed,
# maybe this is some other issue that shouldn't be silenced/misdirected
raise e

except SyntaxError as e:
# alias to please mypyc
is_py38_or_earlier = sys.version_info < (3, 9)
Expand DownExpand Up@@ -415,35 +443,7 @@ def visit(self, node: AST | None) -> Any:
visitor = getattr(self, method)
self.visitor_cache[typeobj] = visitor

try:

return visitor(node)

except RecursionError as e:
# For very complex expressions it is possible to hit recursion limit
# before reaching a leaf node.
# E.G. x1+x2+x3+...+xn -> BinOp(left=BinOp(left=BinOp(left=...
try:
# But to prove that is the cause of this particular recursion error,
# try to unparse the node
ast3.unparse(node)
except RecursionError:
self.errors.report(
node.lineno,
node.col_offset,
"Expression too complex to parse",
blocker=True,
code=codes.MISC,
)

expr = TempNode(AnyType(TypeOfAny.from_error), no_rhs=True)
self.set_line(expr, node)
return expr

else:
# re-raise original recursion error if it *can* be unparsed,
# maybe this is some other issue that shouldn't be silenced/misdirected
raise e
return visitor(node)

def set_line(self, node: N, n: AstNode) -> N:
node.line = n.lineno
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp