-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[Typing] type checking with apis #64991
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提交成功,感谢你对开源项目的贡献! |
tools/sampcd_processor_utils.py
Outdated
@@ -598,41 +598,48 @@ def get_test_capacity(run_on_device="cpu"): | |||
def get_docstring( | |||
full_test: bool = False, | |||
filter_api: typing.Callable[[str], bool] | None = None, | |||
apis: tuple[tuple[str, str], ...] | None = None, |
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.
这里是不是用 list 更合适?
# We type-check the `Example` codes from docstring. | ||
# We type-check the `Example` codes from docstring, like: | ||
# 1. checking from input `apis` | ||
# > python type_checking.py paddle.abs paddle.abs_ paddle.sin |
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.
这里的 1 需要预先手动生成 spec 么?
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.
不用 ~ 单独检查指定的 api (如 python type_checking.py paddle.abs paddle.abs_ paddle.sin
)与通过 spec 检查(如 python type_checking.py
)是互斥的 ~
也就是说,开发者可以用这个脚本在本地检查 api 的 typing ~
本来是想把这个功能单独写一个工具的,就像之前 xdoctest 那个,但是,出于以下考虑,整合在了这里:
-
type checking 需要动态获取 api 的签名
之前的 xdoctest 可以看作是静态检查,而 type checking 需要开发者改完之后重新打包安装,或者手动覆盖掉修改的文件,所以要麻烦很多 ~
-
mypy 的配置文件应该会不断更新
如果像之前那样单列工具,那么两边同步的工作会很多,不利用使用 ~
由此,这里把 type_checking.py
简单扩展了一下,方便开发者本地调试 ~ 当然,调试前还是需要自己手动重新打包安装 ~
看看还没有什么更好的方式?
执行方式:
> python type_checking.py paddle.abs paddle.acos
----------------Codeblock Type Checking Start--------------------
>>> Get docstring from api ...
API_PR is diff from API_DEV: dict_keys(['paddle.abs', 'paddle.acos'])
Total api: 2
>>> Running type checker ...
>>> Print summary ...
----------------Check results--------------------
----------------Check results--------------------
>>> Type checking is successful!
>>> Type checking is successful!
----------------End of the Check--------------------
----------------End of the Check--------------------
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.
嗯嗯,这里没什么更多问题了,只是在 CI 中是否可以像 codestyle 流水线一样,失败后提示用户如何复现问题?
Paddle/tools/codestyle/pre_commit.sh
Lines 49 to 62 in ed8168d
echo "Your PR code style check failed." | |
echo "Please install pre-commit locally and set up git hook scripts:" | |
echo "" | |
echo " pip install pre-commit==2.17.0" | |
echo " pre-commit install" | |
echo "" | |
if [[ $num_diff_files -le 100 ]];then | |
echo "Then, run pre-commit to check codestyle issues in your PR:" | |
echo "" | |
echo " pre-commit run --files" $(echo ${diff_files} | tr "\n" " ") | |
echo "" | |
fi | |
echo "For more information, please refer to our codestyle check guide:" | |
echo "https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/dev_guides/git_guides/codestyle_check_guide_cn.html" |
仅提示失败的那几个就好~比如 API diff 含 paddle.abs
、paddle.acos
,前者成功,后者失败,那么提示使用 python type_checking.py paddle.acos
来复现
tools/type_checking.py
Outdated
logger.error( | ||
">>> Please recheck the type annotations. Run `tools/type_checking.py` to check the typing issues:" | ||
) | ||
logger.error("> python type_checking.py " + " ".join(failed_apis)) |
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.
logger.error("> python type_checking.py " + " ".join(failed_apis)) | |
logger.error("> python tools/type_checking.py " + " ".join(failed_apis)) |
需要过滤一下? |
喔喔,没注意用了 |
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.
PR Category
User Experience
PR Types
Improvements
Description
修改
tools/type_checking.py
,使其可以单独检查指定的 api,具体用法为:apis
> python type_checking.py paddle.abs paddle.abs_ paddle.sin
> python type_checking.py
> python type_checking.py --full-test
--full-test
andapis
should not be set at the same time.@SigureMo