-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[Typing][A-1] Add type annotations for paddle/tensor/array.py
#65009
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提交成功,感谢你对开源项目的贡献! |
python/paddle/tensor/array.py
Outdated
@@ -57,16 +72,16 @@ def array_length(array): | |||
elif in_pir_mode(): | |||
if ( | |||
not isinstance(array, paddle.pir.Value) | |||
or not array.is_dense_tensor_array_type() | |||
or not array.is_dense_tensor_array_type() # type: ignore |
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.
我们代码里就不要加 # type: ignore
了吧,不然太多了,只在示例代码,以及我们自己写的代码里加吧,别人写的代码不用管
@megemini 觉得呢
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.
我们代码里就不要加
# type: ignore
了吧,不然太多了,只在示例代码,以及我们自己写的代码里加吧,别人写的代码不用管
嗯 ~ 加这个东西是为了过测试 ~ Paddle 本身不需要 mypy 检查,暂时也就没必要加这个了 ~
目前在 Example 里面的代码加上(如有必要)就行 ~
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.
done
python/paddle/tensor/array.py
Outdated
def array_read( | ||
array: list[T] | paddle.Tensor, i: paddle.Tensor | ||
) -> T | 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.
这个地方是否还需要添加类型?
python 官方的例子是没有的:
@overload
def utf8(value: None) -> None:
pass
@overload
def utf8(value: bytes) -> bytes:
pass
@overload
def utf8(value: unicode) -> bytes:
pass
def utf8(value):
<actual implementation>
感觉多少有点冗余 ~
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.
@SigureMo 帮忙看看 ~
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.
done
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/array.py
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.
改一下 docstring 中的返回值写法吧:
Returns:
Tensor: 0-D Tensor with shape [], which is the length of array.
改为
Returns:
Tensor, 0-D Tensor with shape [], which is the length of array.
参考讨论:#65064 (comment)
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.
done
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
PR Category
User Experience
PR Types
Improvements
Description
类型标注: