Skip to content

[Typing] tensor.prototype.pyi 添加额外的 import 并对 Literal 进行转换 - #65377

Merged
SigureMo merged 2 commits into
PaddlePaddle:developfrom
megemini:tensor_stub_import
Jun 23, 2024
Merged

SigureMo merged 2 commits into
PaddlePaddle:developfrom
megemini:tensor_stub_import

Conversation

@megemini

Copy link
Copy Markdown
Contributor

PR Category

User Experience

PR Types

Others

Description

  • tensor.prototype.pyi 添加额外的 import

    目前不确定什么原因,ParamAttr TensorHookRemoveHelper 写入签名的时候,没有使用 paddle.xxx.xxx 的形式,因此在模板中增加这两个模块

  • 修改 Literal

    "Literal[('raise', 'wrap', 'clip')]" 转换为 "Literal['raise', 'wrap', 'clip']" ,去掉中间的括号。Literal 写入签名的时候会有括号,但是 vscode 不能正确解析,所以需要将其去掉 ~

@SigureMo

@paddle-bot

paddle-bot Bot commented Jun 22, 2024

Copy link
Copy Markdown

你的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.

@paddle-bot paddle-bot Bot added the contributor External developers label Jun 22, 2024
from paddle.base.dygraph.tensor_patch_methods import (
TensorHookRemoveHelper, # noqa: F401
)
from paddle.base.param_attr import ParamAttr # noqa: F401

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
from paddle.base.param_attr import ParamAttr # noqa: F401
from paddle import ParamAttr # noqa: F401

Comment thread tools/gen_tensor_stub.py
"""
convert bad annotation, e.g.:

"Literal[('raise', 'wrap', 'clip')]" -> "Literal['raise', 'wrap', 'clip']"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

image

我这边现在生成的就不带括号

我实验了下,发现是和 Python 版本有关:

from __future__ import annotations
import inspect
from typing import TypeVar, Union, Sequence, Dict, List, Tuple, Any, Literal


def foo(x: Literal["a", "b"]): ...


sig = inspect.signature(foo)
print(sig)
# 3.8
# (x: "Literal[('a', 'b')]")
# 3.9, 3.10 ...
# (x: "Literal['a', 'b']")

估计是 3.8 没有 unparse 模块,反编译回字符串出 bug 了,这里记一下吧,方便将来 3.8 退场时候一起清理~

之后我在 #59685 也记一下

@SigureMo SigureMo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTMeow 🐾

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants