Repository navigation
[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]'.
SigureMo
left a comment
There was a problem hiding this comment.
不少是不需要修改的,恢复就好,但并不是说这个任务不算完成,确认是否是类型注解语义下也是这个任务的一部分,或者说最主要的一部分
| from typing import TYPE_CHECKING, Literal | ||
|
|
||
| if TYPE_CHECKING: | ||
| from collections.abc import Sequence |
There was a problem hiding this comment.
TYPE_CHECKING 移到下面,其他的也一样
|
|
||
|
|
||
| class Cifar10(Dataset[Tuple["_ImageDataType", "npt.NDArray[Any]"]]): | ||
| class Cifar10(Dataset[tuple["_ImageDataType", "npt.NDArray[Any]"]]): |
| from PIL import Image | ||
|
|
||
| import paddle | ||
| from paddle import Tensor |
| def __getitem__(self, idx: int) -> tuple[_ImageDataType, npt.NDArray[Any]]: | ||
| def __getitem__( | ||
| self, idx: int | ||
| ) -> tuple[Tensor | Image | npt.NDArray[Any], npt.NDArray[Any]]: |
|
|
||
|
|
||
| class DatasetFolder(Dataset[Tuple["_ImageDataType", int]]): | ||
| class DatasetFolder(Dataset[tuple["_ImageDataType", int]]): |
|
|
||
|
|
||
| class ImageFolder(Dataset[List["_ImageDataType"]]): | ||
| class ImageFolder(Dataset[list["_ImageDataType"]]): |
|
|
||
|
|
||
| class MNIST(Dataset[Tuple["_ImageDataType", "npt.NDArray[np.int64]"]]): | ||
| class MNIST(Dataset[tuple["_ImageDataType", "npt.NDArray[np.int64]"]]): |
|
|
||
|
|
||
| class VOC2012(Dataset[Tuple["_ImageDataType", "npt.NDArray[Any]"]]): | ||
| class VOC2012(Dataset[tuple["_ImageDataType", "npt.NDArray[Any]"]]): |
|
|
||
| __annotations__ = { | ||
| "return_layers": Dict[str, str], | ||
| "return_layers": dict[str, str], |
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.
这里直接改成这样
- __annotations__ = {
- "return_layers": Dict[str, str],
- }
+ return_layers: dict[str, str]这样就是合法的了
There was a problem hiding this comment.
啊,你这个文件都没用 PEP 563……你这会挂……
要用 PEP 563
|
上面那么多 comment 呢,都要改啊 |
|
2024-08-12 13:50:21 from .flowers import Flowers 您好,SOT会发生这样的报错 |
|
再看看我上面的 comment,明显是漏恢复了 |
| if TYPE_CHECKING: | ||
| from collections.abc import Sequence |
| from typing import TYPE_CHECKING, Any, Sequence | ||
| from typing import TYPE_CHECKING, Any | ||
|
|
||
| if TYPE_CHECKING: |
…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