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][C-116,C-117] Add type annotations for "paddle/geometric/*" #66792

Merged
merged 11 commits into from
Aug 1, 2024

Conversation

successfulbarrier
Copy link
Contributor

@successfulbarrier successfulbarrier commented Jul 30, 2024

PR Category

User Experience

PR Types

Improvements

Description

C-116,C117 ,为公开AP添加类型提示信息
#65008

Copy link

paddle-bot bot commented Jul 30, 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.

count: Tensor,
value_buffer: Tensor | None = None,
index_buffer: Tensor | None = None,
name: Tensor | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
name: Tensor | None = None,
name: str | None = None,

Comment on lines 152 to 158
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]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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]:

@luotao1 luotao1 added contributor External developers HappyOpenSource 快乐开源活动issue与PR labels Jul 30, 2024
@successfulbarrier successfulbarrier changed the title [Typing][C-116] Add type annotations for "paddle/geometric/reindex.py" [Typing][C-116,C-117] Add type annotations for "paddle/geometric/*" Jul 30, 2024
Comment on lines 30 to 38
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]:
Copy link
Contributor

Choose a reason for hiding this comment

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

使用 overload 区分不同的输出情况

Comment on lines 179 to 187
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]:
Copy link
Contributor

Choose a reason for hiding this comment

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

同上

Copy link
Contributor

@megemini megemini Jul 31, 2024

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已经修正,感谢您的耐心指导

Copy link
Contributor

@megemini megemini Jul 31, 2024

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. 更新了上面的示例

Copy link
Contributor Author

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],
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return_eids: bool = Literal[True],
return_eids: Literal[True] = ...,

其他几个类似 ~

Copy link
Contributor

@megemini megemini left a comment

Choose a reason for hiding this comment

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

LGTM ~

@luotao1 luotao1 merged commit d365726 into PaddlePaddle:develop Aug 1, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers HappyOpenSource 快乐开源活动issue与PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants