Skip to content

[Typing][PEP585 Upgrade][BUAA][121-129] Use standard collections for type hints for 9 files in python/paddle/{tensor,utils,vision} - #67222

Merged
SigureMo merged 13 commits into
PaddlePaddle:developfrom
Whsjrczr:typing3
Aug 13, 2024
Merged

SigureMo merged 13 commits into
PaddlePaddle:developfrom
Whsjrczr:typing3

Conversation

@Whsjrczr

@Whsjrczr Whsjrczr commented Aug 8, 2024 •

Copy link
Copy Markdown
Contributor

PR Category

User Experience

PR Types

Others

Description

修改了九个文件:
modified: python/paddle/tensor/math.py
modified: python/paddle/tensor/stat.py
modified: python/paddle/utils/cpp_extension/cpp_extension.py
modified: python/paddle/vision/datasets/cifar.py
modified: python/paddle/vision/datasets/flowers.py
modified: python/paddle/vision/datasets/folder.py
modified: python/paddle/vision/datasets/mnist.py
modified: python/paddle/vision/datasets/voc2012.py
modified: python/paddle/vision/models/_utils.py

@paddle-bot

paddle-bot Bot commented Aug 8, 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.

@Whsjrczr Whsjrczr changed the title Typing3 [Typing][PEP585 Upgrade][BUAA][121-129] Use standard collections for type hints for 9 files in python/paddle/{tensor/utils/vision} Aug 8, 2024
@paddle-bot paddle-bot Bot added the contributor External developers label Aug 8, 2024
@luotao1 luotao1 added the HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 label Aug 9, 2024

@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.

不少是不需要修改的,恢复就好,但并不是说这个任务不算完成,确认是否是类型注解语义下也是这个任务的一部分,或者说最主要的一部分

Comment thread python/paddle/tensor/math.py Outdated
from typing import TYPE_CHECKING, Literal

if TYPE_CHECKING:
from collections.abc import Sequence

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.

TYPE_CHECKING 移到下面,其他的也一样

Comment thread python/paddle/vision/datasets/cifar.py Outdated


class Cifar10(Dataset[Tuple["_ImageDataType", "npt.NDArray[Any]"]]):
class Cifar10(Dataset[tuple["_ImageDataType", "npt.NDArray[Any]"]]):

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.

运行时会跑,这里不要改

Comment thread python/paddle/vision/datasets/cifar.py Outdated
from PIL import Image

import paddle
from paddle import Tensor

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.

这几个为啥要挪出来?

Comment thread python/paddle/vision/datasets/cifar.py Outdated
def __getitem__(self, idx: int) -> tuple[_ImageDataType, npt.NDArray[Any]]:
def __getitem__(
self, idx: int
) -> tuple[Tensor | Image | npt.NDArray[Any], npt.NDArray[Any]]:

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.

不要修改这些

Comment thread python/paddle/vision/datasets/folder.py Outdated


class DatasetFolder(Dataset[Tuple["_ImageDataType", int]]):
class DatasetFolder(Dataset[tuple["_ImageDataType", int]]):

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.

同上,非类型注解上下文,不可以修改

Comment thread python/paddle/vision/datasets/folder.py Outdated


class ImageFolder(Dataset[List["_ImageDataType"]]):
class ImageFolder(Dataset[list["_ImageDataType"]]):

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.

同上

Comment thread python/paddle/vision/datasets/mnist.py Outdated


class MNIST(Dataset[Tuple["_ImageDataType", "npt.NDArray[np.int64]"]]):
class MNIST(Dataset[tuple["_ImageDataType", "npt.NDArray[np.int64]"]]):

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.

同上



class VOC2012(Dataset[Tuple["_ImageDataType", "npt.NDArray[Any]"]]):
class VOC2012(Dataset[tuple["_ImageDataType", "npt.NDArray[Any]"]]):

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.

同上

Comment thread python/paddle/vision/models/_utils.py Outdated

__annotations__ = {
"return_layers": Dict[str, str],
"return_layers": dict[str, str],

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.

这里也会对运行时有影响,不需要修改

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

收到

@SigureMo SigureMo changed the title [Typing][PEP585 Upgrade][BUAA][121-129] Use standard collections for type hints for 9 files in python/paddle/{tensor/utils/vision} [Typing][PEP585 Upgrade][BUAA][121-129] Use standard collections for type hints for 9 files in python/paddle/{tensor/utils/vision} Aug 9, 2024
@SigureMo SigureMo changed the title [Typing][PEP585 Upgrade][BUAA][121-129] Use standard collections for type hints for 9 files in python/paddle/{tensor/utils/vision} [Typing][PEP585 Upgrade][BUAA][121-129] Use standard collections for type hints for 9 files in python/paddle/{tensor,utils,vision} Aug 9, 2024
Comment thread python/paddle/vision/models/_utils.py Outdated
Comment on lines 73 to 75
__annotations__ = {
"return_layers": Dict[str, str],
"return_layers": dict[str, str],
}

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.

这里直接改成这样

-    __annotations__ = {
-        "return_layers": Dict[str, str],
-    }
+    return_layers: dict[str, str]

这样就是合法的了

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.

啊,你这个文件都没用 PEP 563……你这会挂……

要用 PEP 563

@SigureMo

Copy link
Copy Markdown
Collaborator

上面那么多 comment 呢,都要改啊

@Whsjrczr

Copy link
Copy Markdown
Contributor Author

2024-08-12 13:50:21 from .flowers import Flowers
2024-08-12 13:50:21 File "/workspace/Paddle/build/python/paddle/vision/datasets/flowers.py", line 54, in
2024-08-12 13:50:21 class Flowers(Dataset[tuple["_ImageDataType", "npt.NDArray[np.int64]"]]):
2024-08-12 13:50:21 TypeError: 'type' object is not subscriptable

您好,SOT会发生这样的报错

@SigureMo

Copy link
Copy Markdown
Collaborator

再看看我上面的 comment,明显是漏恢复了

Comment thread python/paddle/tensor/stat.py Outdated
Comment on lines +19 to +20
if TYPE_CHECKING:
from collections.abc import Sequence

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.

if TYPE_CHECKING: 移到下面

from typing import TYPE_CHECKING, Any, Sequence
from typing import TYPE_CHECKING, Any

if TYPE_CHECKING:

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.

同上

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已修改

@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 🐾

@SigureMo
SigureMo merged commit 171efa1 into PaddlePaddle:develop Aug 13, 2024
Jeff114514 pushed a commit to Jeff114514/Paddle that referenced this pull request Aug 14, 2024
…type hints for 9 files in `python/paddle/{tensor,utils,vision}` (PaddlePaddle#67222)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants