-
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][A-8] Add type annotations for python/paddle/tensor/math.py
#65073
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
if TYPE_CHECKING: | ||
from paddle import 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.
之后的PR都这样吗? 不用 paddle.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.
都可以,这样可以省去每次都写 paddle.Tensor
,两者对于 type checker 是等价的
这里使用 TYPE_CHECKING
是为了避免运行时产生 circular import,高层次模块不必如此,直接 import 即可
2024-06-12 18:16:28 <string>:4:22: error: Argument 1 to "to_tensor" has incompatible type "List[object]"; expected "Union[Union[ndarray[Any, dtype[Any]], Tensor, Union[int, float, complex, number[Any], Tensor]], NestedNumbericSequence]" [arg-type]
# input = [[[2.0, 2, -2], [3, 0.3, 3]], [[2, -8, 2], [3.1, 3.7, 3]]] 有问题
input = [[[2.0, 2., -2.], [3., 0.3, 3.]], [[2., -8., 2.], [3.1, 3.7, 3.]]] 可以
to_tensor(input) 这个地方,我觉得不用改 第一种属于不太规范,也不提倡 ~ @SigureMo 觉得呢? |
嗯,这样是更合适的 |
python/paddle/tensor/math.py
python/paddle/tensor/math.py
python/paddle/tensor/math.py
python/paddle/tensor/math.py
PR Category
User Experience
PR Types
Improvements
Description
Add type annotations for
python/paddle/tensor/math.py
Need #64954
Related links
PCard-66972