-
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][PEP585 Upgrade][BUAA][121-129] Use standard collections for type hints for 9 files in python/paddle/{tensor,utils,vision}
#67222
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
…r | Image | npt.NDArray[Any]'.
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.
不少是不需要修改的,恢复就好,但并不是说这个任务不算完成,确认是否是类型注解语义下也是这个任务的一部分,或者说最主要的一部分
python/paddle/tensor/math.py
Outdated
from typing import TYPE_CHECKING, Literal | ||
|
||
if TYPE_CHECKING: | ||
from collections.abc import Sequence |
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.
TYPE_CHECKING 移到下面,其他的也一样
@@ -52,7 +51,7 @@ | |||
} | |||
|
|||
|
|||
class Cifar10(Dataset[Tuple["_ImageDataType", "npt.NDArray[Any]"]]): | |||
class Cifar10(Dataset[tuple["_ImageDataType", "npt.NDArray[Any]"]]): |
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.
运行时会跑,这里不要改
from PIL import Image | ||
|
||
import paddle | ||
from paddle import 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.
这几个为啥要挪出来?
def __getitem__(self, idx: int) -> tuple[_ImageDataType, npt.NDArray[Any]]: | ||
def __getitem__( | ||
self, idx: int | ||
) -> tuple[Tensor | Image | npt.NDArray[Any], npt.NDArray[Any]]: |
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.
不要修改这些
@@ -87,7 +89,7 @@ def is_valid_file(x): | |||
return images | |||
|
|||
|
|||
class DatasetFolder(Dataset[Tuple["_ImageDataType", int]]): | |||
class DatasetFolder(Dataset[tuple["_ImageDataType", int]]): |
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.
同上,非类型注解上下文,不可以修改
@@ -339,7 +341,7 @@ def default_loader(path): | |||
return pil_loader(path) | |||
|
|||
|
|||
class ImageFolder(Dataset[List["_ImageDataType"]]): | |||
class ImageFolder(Dataset[list["_ImageDataType"]]): |
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.
同上
@@ -38,7 +38,7 @@ | |||
__all__ = [] | |||
|
|||
|
|||
class MNIST(Dataset[Tuple["_ImageDataType", "npt.NDArray[np.int64]"]]): | |||
class MNIST(Dataset[tuple["_ImageDataType", "npt.NDArray[np.int64]"]]): |
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.
同上
@@ -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]"]]): |
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.
同上
@@ -72,10 +71,10 @@ class IntermediateLayerGetter(nn.LayerDict): | |||
""" | |||
|
|||
__annotations__ = { | |||
"return_layers": Dict[str, str], | |||
"return_layers": dict[str, str], |
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.
收到
python/paddle/{tensor/utils/vision}
python/paddle/{tensor/utils/vision}
python/paddle/{tensor,utils,vision}
__annotations__ = { | ||
"return_layers": Dict[str, str], | ||
"return_layers": dict[str, str], | ||
} |
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.
这里直接改成这样
- __annotations__ = {
- "return_layers": Dict[str, str],
- }
+ return_layers: dict[str, str]
这样就是合法的了
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.
啊,你这个文件都没用 PEP 563……你这会挂……
要用 PEP 563
上面那么多 comment 呢,都要改啊 |
2024-08-12 13:50:21 from .flowers import Flowers 您好,SOT会发生这样的报错 |
再看看我上面的 comment,明显是漏恢复了 |
python/paddle/tensor/stat.py
Outdated
if TYPE_CHECKING: | ||
from collections.abc import Sequence |
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.
if TYPE_CHECKING:
移到下面
from typing import TYPE_CHECKING, Any, Sequence | ||
from typing import TYPE_CHECKING, Any | ||
|
||
if TYPE_CHECKING: |
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.
已修改
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.
…type hints for 9 files in `python/paddle/{tensor,utils,vision}` (PaddlePaddle#67222)
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