Skip to content

Conversation

megemini
Copy link
Contributor

PR Category

User Experience

PR Types

Bug fixes

Description

Use py_compile instead of ast.parse for pyi file syntax check.

ast.parse at Python 3.9 can not guarantee raise SyntaxError.

@SigureMo

Copy link

paddle-bot bot commented Mar 24, 2025

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Mar 24, 2025
@megemini
Copy link
Contributor Author

修改前:

image

修改后,可以删除掉语法错误的地方:

image

不过,为啥会生成的 pyi 这么怪,有可能是 cinn 最近引入了啥神奇的语法,pybind11_stubgen 还没跟上? 只能后面有机会再看看了 ~

@SigureMo
Copy link
Member

不过,为啥会生成的 pyi 这么怪,有可能是 cinn 最近引入了啥神奇的语法,pybind11_stubgen 还没跟上

没有印象,确实很奇怪

@SigureMo SigureMo added the HappyOpenSource 快乐开源活动issue与PR label Mar 24, 2025
@SigureMo SigureMo requested a review from Copilot March 24, 2025 13:49
SigureMo
SigureMo previously approved these changes Mar 24, 2025
Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTMeow 🐾

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a syntax check issue in .pyi files by replacing the use of ast.parse with py_compile, ensuring that syntax errors are reliably caught. Key changes include:

  • Removing the "limit" parameter and using an infinite loop to repeatedly attempt syntax checking.
  • Replacing ast.parse with py_compile.compile for validating file syntax.
  • Updating error handling logic to delete lines causing syntax errors.
Comments suppressed due to low confidence (1)

tools/gen_pybind11_stub.py:15

  • The code uses traceback.format_exc(), but there is no import for the traceback module. Please add 'import traceback' to ensure proper functionality.
from __future__ import annotations

Comment on lines 335 to 336
while True:

Copy link
Preview

Copilot AI Mar 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of the loop limit may result in an infinite loop if a syntax error persists and the file never becomes fully compilable. Consider reintroducing a maximum iteration count or an alternative escape strategy.

Suggested change
while True:
max_iterations = 10
iteration_count = 0
while iteration_count < max_iterations:

Copilot uses AI. Check for mistakes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@megemini 顺师傅看看这里还要改么?看着是有点合理的,不过问题不大,不改的话就直接 merge 了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那我把 limit 加回去吧 ~ 🫣

@SigureMo SigureMo merged commit 378c948 into PaddlePaddle:develop Mar 25, 2025
30 checks passed
co63oc pushed a commit to co63oc/Paddle that referenced this pull request Mar 27, 2025
YqGe585 pushed a commit to YqGe585/Paddle that referenced this pull request May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers HappyOpenSource 快乐开源活动issue与PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants