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] 修理部分示例中的类型缺失 var-annotated 以及添加具体 ignore 类型 #65644

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/paddle/amp/debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def check_layer_numerics(func):
... return x @ self._w + self._b
...
>>> dtype = 'float32'
>>> x = paddle.rand([10, 2, 2], dtype=dtype) # type: ignore
>>> x = paddle.rand([10, 2, 2], dtype=dtype) # type: ignore[arg-type]
>>> model = MyLayer(dtype)
>>> x[0] = float(0)
>>> loss = model(x)
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/base/layers/math_op_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def astype(self, dtype):
>>> import paddle
>>> import numpy as np

>>> x = np.ones([2, 2], np.float32)
>>> x = np.ones([2, 2], np.float32) # type: ignore[var-annotated]
>>> with base.dygraph.guard():
... original_variable = paddle.to_tensor(x)
... print("original var's dtype is: {}, numpy dtype is {}".format(original_variable.dtype, original_variable.numpy().dtype))
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/distributed/communication/stream/gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def gather(
>>> import paddle.distributed as dist

>>> dist.init_parallel_env()
>>> gather_list = []
>>> gather_list = [] # type: ignore[var-annotated]
>>> if dist.get_rank() == 0:
... data = paddle.to_tensor([1, 2, 3])
... dist.stream.gather(data, gather_list, dst=0)
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/distributed/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ class DataParallel(layers.Layer):
... model = paddle.DataParallel(model)
... opt = paddle.optimizer.SGD(learning_rate=0.01, parameters=model.parameters())
... for step in range(10):
... x_data = numpy.random.randn(2, 2).astype(numpy.float32)
... x_data = numpy.random.randn(2, 2).astype(numpy.float32) # type: ignore[var-annotated]
... x = paddle.to_tensor(x_data)
... x.stop_gradient = False
... # step 1 : skip gradient synchronization by 'no_sync'
Expand Down
6 changes: 3 additions & 3 deletions python/paddle/optimizer/lbfgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,10 @@ class LBFGS(Optimizer):

>>> paddle.disable_static()
>>> np.random.seed(0)
>>> np_w = np.random.rand(1).astype(np.float32) # type: ignore
>>> np_x = np.random.rand(1).astype(np.float32) # type: ignore
>>> np_w = np.random.rand(1).astype(np.float32) # type: ignore[var-annotated]
>>> np_x = np.random.rand(1).astype(np.float32) # type: ignore[var-annotated]

>>> inputs = [np.random.rand(1).astype(np.float32) for i in range(10)] # type: ignore
>>> inputs = [np.random.rand(1).astype(np.float32) for i in range(10)] # type: ignore[var-annotated]
>>> # y = 2x
>>> targets = [2 * x for x in inputs]

Expand Down
2 changes: 1 addition & 1 deletion python/paddle/tensor/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def shape(input: Tensor) -> Tensor:
>>> exe = paddle.static.Executor(paddle.CPUPlace())
>>> exe.run(paddle.static.default_startup_program())

>>> img = np.ones((3, 100, 100)).astype(np.float32) # type: ignore
>>> img = np.ones((3, 100, 100)).astype(np.float32) # type: ignore[var-annotated]

>>> res = exe.run(paddle.static.default_main_program(), feed={'x':img}, fetch_list=[output])
>>> print(res)
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/tensor/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2483,7 +2483,7 @@ def assign(x: TensorLike, output: paddle.Tensor | None = None) -> paddle.Tensor:
[2.5 2.5]]
>>> array = np.array([[1, 1], [3, 4], [1, 3]]).astype(
... np.int64
... ) # type: ignore
... ) # type: ignore[var-annotated]
>>> result1 = paddle.zeros(shape=[3, 3], dtype='float32')
>>> paddle.assign(array, result1)
>>> print(result1.numpy())
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/vision/transforms/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class BaseTransform(_Transform[_InputT, _RetT]):
... else:
... raise TypeError("Unexpected type {}".format(type(img)))
...
>>> class CustomRandomFlip(BaseTransform): # type: ignore
>>> class CustomRandomFlip(BaseTransform): # type: ignore[type-arg]
... def __init__(self, prob=0.5, keys=None):
... super().__init__(keys)
... self.prob = prob
Expand Down