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][PEP585 Upgrade][BUAA][121-129] Use standard collections for type hints for 9 files in python/paddle/{tensor,utils,vision} #67222

Merged
merged 13 commits into from
Aug 13, 2024

Conversation

Whsjrczr
Copy link
Contributor

@Whsjrczr Whsjrczr commented Aug 8, 2024

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

Copy link

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

@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
Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

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

from typing import TYPE_CHECKING, Literal

if TYPE_CHECKING:
from collections.abc import Sequence
Copy link
Member

Choose a reason for hiding this comment

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

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

@@ -52,7 +51,7 @@
}


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

Choose a reason for hiding this comment

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

运行时会跑,这里不要改

from PIL import Image

import paddle
from paddle import Tensor
Copy link
Member

Choose a reason for hiding this comment

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

这几个为啥要挪出来?

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
Member

Choose a reason for hiding this comment

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

不要修改这些

@@ -87,7 +89,7 @@ def is_valid_file(x):
return images


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

Choose a reason for hiding this comment

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

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

@@ -339,7 +341,7 @@ def default_loader(path):
return pil_loader(path)


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

Choose a reason for hiding this comment

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

同上

@@ -38,7 +38,7 @@
__all__ = []


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

Choose a reason for hiding this comment

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

同上

@@ -51,7 +51,7 @@
MODE_FLAG_MAP = {'train': 'trainval', 'test': 'train', 'valid': "val"}


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

Choose a reason for hiding this comment

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

同上

@@ -72,10 +71,10 @@ class IntermediateLayerGetter(nn.LayerDict):
"""

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

Choose a reason for hiding this comment

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

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

Copy link
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 on lines 73 to 75
__annotations__ = {
"return_layers": Dict[str, str],
"return_layers": dict[str, str],
}
Copy link
Member

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
Member

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
Member

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

@Whsjrczr
Copy link
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
Member

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

Comment on lines 19 to 20
if TYPE_CHECKING:
from collections.abc import Sequence
Copy link
Member

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
Member

Choose a reason for hiding this comment

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

同上

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
Member

@SigureMo SigureMo left a comment

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
29 of 30 checks passed
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