-
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][C-116,C-117] Add type annotations for "paddle/geometric/*" #66792
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
python/paddle/geometric/reindex.py
Outdated
count: Tensor, | ||
value_buffer: Tensor | None = None, | ||
index_buffer: Tensor | None = None, | ||
name: Tensor | 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.
name: Tensor | None = None, | |
name: str | None = None, |
python/paddle/geometric/reindex.py
Outdated
x: Tensor, | ||
neighbors: list | tuple, | ||
count: list | tuple, | ||
value_buffer: Tensor | None = None, | ||
index_buffer: Tensor | None = None, | ||
name: str | None = None, | ||
) -> tuple[Tensor, Tensor, 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.
x: Tensor, | |
neighbors: list | tuple, | |
count: list | tuple, | |
value_buffer: Tensor | None = None, | |
index_buffer: Tensor | None = None, | |
name: str | None = None, | |
) -> tuple[Tensor, Tensor, Tensor]: | |
x: Tensor, | |
neighbors: Sequence[Tensor], | |
count: Sequence[Tensor], | |
value_buffer: Tensor | None = None, | |
index_buffer: Tensor | None = None, | |
name: str | None = None, | |
) -> tuple[Tensor, Tensor, Tensor]: |
row: Tensor, | ||
colptr: Tensor, | ||
input_nodes: Tensor, | ||
sample_size: int = -1, | ||
eids: Tensor | None = None, | ||
return_eids: bool = False, | ||
perm_buffer: Tensor | None = None, | ||
name: str | None = None, | ||
) -> tuple[Tensor, Tensor, Tensor] | tuple[Tensor, 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.
使用 overload
区分不同的输出情况
row: Tensor, | ||
colptr: Tensor, | ||
edge_weight: Tensor, | ||
input_nodes: Tensor, | ||
sample_size: int = -1, | ||
eids: Tensor | None = None, | ||
return_eids: bool = False, | ||
name: str | None = None, | ||
) -> tuple[Tensor, Tensor, Tensor] | tuple[Tensor, 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.
同上
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.
重写了一遍函数?overload
不是这么用的,可以搜一下已经使用了 overload
标注的地方 ~
一个简单的例子
@overload
def foo(arg0: Any, arg1: Literal[True]) -> int: ...
@overload
def foo(arg0: Any, arg1: Literal[False]) -> str: ...
@overload
def foo(arg0: Any, arg1: bool = ...) -> int | str: ...
def foo(arg0, arg1=True):
if arg1:
return int(arg0)
return str(arg0)
x: int = foo(1, True)
y: str = foo(1, False)
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.
改的还是有点问题,注意几个地方:
overload
中一般不写具体参数值,更不能更改原赋值overload
中使用Literal
,如果原定义中有默认值,可以跟= ...
- 需要单独一个
arg1: bool = ...
的overload
,用于针对参数传值而非直接传值 - 使用
overload
后,原函数不需要再标注类型(也可以不定义最后的overload
,而直接在原函数中标注)
overload
本身有些行为定义的还不是很清楚,但,一定要分清楚类型标注和默认值的关系 ~
p.s. 更新了上面的示例
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.
是这样吗?
input_nodes: Tensor, | ||
sample_size: int = ..., | ||
eids: Tensor | None = ..., | ||
return_eids: bool = Literal[True], |
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.
return_eids: bool = Literal[True], | |
return_eids: Literal[True] = ..., |
其他几个类似 ~
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
C-116,C117 ,为公开AP添加类型提示信息
#65008