[Fix] use `py_compile` for pyi file syntax check by megemini · Pull Request #71872 · PaddlePaddle/Paddle

@megemini

@megemini

@paddle-bot

你的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.

@megemini

修改前:

image

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

image

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

@SigureMo

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

没有印象,确实很奇怪

SigureMo

Choose a reason for hiding this comment

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

LGTMeow 🐾

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

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.

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

Copilot uses AI. Check for mistakes.

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

那我把 limit 加回去吧 ~ 🫣

@megemini

SigureMo

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