[Fix] use py_compile for pyi file syntax check#71872
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
没有印象,确实很奇怪 |
There was a problem hiding this comment.
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
| while True: | ||
|
|
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
@megemini 顺师傅看看这里还要改么?看着是有点合理的,不过问题不大,不改的话就直接 merge 了
There was a problem hiding this comment.
那我把 limit 加回去吧 ~ 🫣


PR Category
User Experience
PR Types
Bug fixes
Description
Use
py_compileinstead ofast.parsefor pyi file syntax check.ast.parseat Python 3.9 can not guarantee raiseSyntaxError.@SigureMo