-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[Fix] use py_compile
for pyi file syntax check
#71872
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
没有印象,确实很奇怪 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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
tools/gen_pybind11_stub.py
Outdated
while True: | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@megemini 顺师傅看看这里还要改么?看着是有点合理的,不过问题不大,不改的话就直接 merge 了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那我把 limit 加回去吧 ~ 🫣
PR Category
User Experience
PR Types
Bug fixes
Description
Use
py_compile
instead ofast.parse
for pyi file syntax check.ast.parse
at Python 3.9 can not guarantee raiseSyntaxError
.@SigureMo