From 506d9e2c05974299af006047b4b63cef3b8eae18 Mon Sep 17 00:00:00 2001 From: megemini Date: Fri, 23 Aug 2024 14:49:21 +0800 Subject: [PATCH] =?UTF-8?q?[Typing]=20=E4=BF=AE=E5=A4=8D=E7=A4=BA=E4=BE=8B?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E7=B1=BB=E5=9E=8B=E6=A0=87=E6=B3=A8=E9=94=99?= =?UTF-8?q?=E8=AF=AF=20(#67618)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Add] typing * [Fix] typing --- paddle/fluid/pybind/eager_method.cc | 2 +- python/paddle/amp/auto_cast.py | 4 +++- python/paddle/vision/transforms/transforms.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/paddle/fluid/pybind/eager_method.cc b/paddle/fluid/pybind/eager_method.cc index 5d12e85b1336b..7ad3780cdb3d5 100644 --- a/paddle/fluid/pybind/eager_method.cc +++ b/paddle/fluid/pybind/eager_method.cc @@ -142,7 +142,7 @@ Returns a numpy array shows the value of current Tensor. >>> import paddle >>> x = paddle.to_tensor([[1.0, 2.0, 3.0], - [4.0, 5.0, 6.0]]) + ... [4.0, 5.0, 6.0]]) >>> x.numpy() array([[1., 2., 3.], [4., 5., 6.]], dtype=float32) diff --git a/python/paddle/amp/auto_cast.py b/python/paddle/amp/auto_cast.py index 19f182252a92a..4da8092030434 100644 --- a/python/paddle/amp/auto_cast.py +++ b/python/paddle/amp/auto_cast.py @@ -23,6 +23,8 @@ List, Literal, Protocol, + Set, + Tuple, TypeVar, Union, overload, @@ -54,7 +56,7 @@ from paddle.static import Operator, Program _AmpLevelLiteral = Literal["O0", "OD", "O1", "O2"] - _CustomList: TypeAlias = Union[list[str], tuple[str, ...], set[str]] + _CustomList: TypeAlias = Union[List[str], Tuple[str, ...], Set[str]] class _OptimizerLike(Protocol): def minimize( diff --git a/python/paddle/vision/transforms/transforms.py b/python/paddle/vision/transforms/transforms.py index e7916dcf4bab6..0584f836d43ff 100644 --- a/python/paddle/vision/transforms/transforms.py +++ b/python/paddle/vision/transforms/transforms.py @@ -918,7 +918,7 @@ class Normalize(BaseTransform[_InputT, _RetT]): ... data_format='HWC') ... >>> fake_img = paddle.rand([300,320,3]).numpy() * 255. - >>> fake_img = normalize(fake_img) + >>> fake_img = normalize(fake_img) # type: ignore[call-overload] >>> print(fake_img.shape) (300, 320, 3) >>> print(fake_img.max(), fake_img.min())