-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[Typing][B-50,B-51] Add type annotations for python/paddle/static/{io,input.py}
#67047
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
python/paddle/static/input.py
Outdated
def setitem( | ||
x: Tensor, | ||
index: int | slice | Sequence[int] | Tensor | None, | ||
value: Tensor | npt.NDArray[Any] | bool | complex, |
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.
_typing
里面有 Numberic
,或者直接用 TensorLike
?
python/paddle/static/io.py
Outdated
inference_program, feed_target_names, feed_holder_name='feed' | ||
): | ||
inference_program: Program, | ||
feed_target_names: list[str], |
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.
feed_target_names: list[str], | |
feed_target_names: Sequence[str], |
输入的地方如果没有特殊要求(如 list 的 append
方法,或者用 isinstance
进行判断等),最好用 Sequence
吧 ~
后面有几个也一样 ~
python/paddle/static/io.py
Outdated
program: Program, | ||
feed_vars: Tensor | list[Tensor], | ||
fetch_vars: Tensor | list[Tensor], | ||
**kwargs: Any, |
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.
可以用 TypedDict
?
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.
已添加~
python/paddle/static/io.py
Outdated
def serialize_program( | ||
feed_vars: Tensor | list[Tensor], | ||
fetch_vars: Tensor | list[Tensor], | ||
**kwargs: Any, |
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.
TypedDict
?后面的几个是不是也可以?
python/paddle/static/io.py
Outdated
def load_inference_model(path_prefix, executor, **kwargs): | ||
def load_inference_model( | ||
path_prefix: str | None, executor: Executor, **kwargs: Any | ||
) -> list[Program, list[str], list[Tensor]]: |
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[Program, list[str], list[Tensor]]: | |
) -> list[Program | list[str] | list[Tensor]]: |
list
只能有一个参数 ~ 其实,代码用 tuple
返回更好 ... ...
Sorry to inform you that e7d0910's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually. |
@ooooo-create 别忘了这里还有个任务 🫣 |
抱歉抱歉,收到~ |
… pr/ooooo-create/67047
python/paddle/static/io.py
Outdated
@@ -19,6 +20,7 @@ | |||
import pickle | |||
import sys | |||
import warnings | |||
from typing import TYPE_CHECKING, Any, TypedDict, Unpack, overload |
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.
Unpack 在 typing_extensions 里面 ~
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.
Thanks, done
path_prefix: str | None, | ||
executor: Executor, | ||
**kwargs: Unpack[_LoadInferenceModelKwargs], | ||
) -> list[Program | list[str] | list[Tensor]]: |
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.
原代码写的有点奇怪,一般没有把返回的 tuple
转为 list
的,没什么意义 ... ...
这也导致示例代码中无法正确判断返回值的类型。
ignore 一下示例吧
>>> results = exe.run(inference_program, # type: ignore[arg-type]
... feed={feed_target_names[0]: tensor_img}, # type: ignore[index,dict-item]
... fetch_list=fetch_targets) # type: ignore[arg-type]
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.
LGTM ~ 🤟
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
类型标注:
-
python/paddle/static/io.py
-
python/paddle/static/input.py
Related links
@SigureMo @megemini