Skip to content
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

Merged
merged 7 commits into from
Jun 13, 2024

Conversation

SigureMo
Copy link
Member

PR Category

User Experience

PR Types

Improvements

Description

Add type annotations for python/paddle/tensor/math.py

Need #64954

Related links

PCard-66972

Copy link

paddle-bot bot commented Jun 12, 2024

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

Comment on lines +98 to +99
if TYPE_CHECKING:
from paddle import Tensor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之后的PR都这样吗? 不用 paddle.Tensor 了吗

Copy link
Member Author

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 即可

@megemini
Copy link
Contributor

megemini commented Jun 12, 2024

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)

这个地方,我觉得不用改 to_tensor 的标注或者 NestedNumbericSequence,改一下测试用例(示例代码)吧 ~

第一种属于不太规范,也不提倡 ~

@SigureMo 觉得呢?

@SigureMo
Copy link
Member Author

这个地方,我觉得不用改 to_tensor 的标注或者 NestedNumbericSequence,改一下测试用例(示例代码)吧 ~

第一种属于不太规范,也不提倡 ~

@SigureMo 觉得呢?

嗯,这样是更合适的

@SigureMo SigureMo changed the title [WIP][Typing][A-8] Add typing annotations for python/paddle/tensor/math.py [Typing][A-8] Add typing annotations for python/paddle/tensor/math.py Jun 12, 2024
@SigureMo SigureMo requested a review from zrr1999 June 12, 2024 15:57
@SigureMo SigureMo merged commit 5fddc49 into PaddlePaddle:develop Jun 13, 2024
31 of 33 checks passed
@SigureMo SigureMo deleted the typing/tensor-math branch June 13, 2024 04:42
@SigureMo SigureMo changed the title [Typing][A-8] Add typing annotations for python/paddle/tensor/math.py [Typing][A-8] Add type annotations for python/paddle/tensor/math.py Jun 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants