Skip to content

[CodeStyle] Clean up Python 3.10 type-hint diagnostics#79291

Merged
SigureMo merged 11 commits into
PaddlePaddle:developfrom
ShigureNyako:codestyle/py310-up045-up036-cleanup
Jun 10, 2026
Merged

[CodeStyle] Clean up Python 3.10 type-hint diagnostics#79291
SigureMo merged 11 commits into
PaddlePaddle:developfrom
ShigureNyako:codestyle/py310-up045-up036-cleanup

Conversation

@ShigureNyako

@ShigureNyako ShigureNyako commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

PR Category

Environment Adaptation

PR Types

Deprecations

Description

Related to #79289 and #79290.

This PR cleans Python 3.10 type-hint modernization diagnostics and enables Ruff's Python 3.10 target:

  • merge latest develop after [Typing] Upgrade mypy to 2.1.0 and target Python 3.10 #79289/[CodeStyle] Clean up Python 3.9 compatibility code #79290 and resolve the resulting conflict without force-push
  • set Ruff target-version = "py310"
  • clean py310 UP035 / UP007 / UP045 diagnostics by modernizing type-hint syntax and removing now-obsolete typing imports
  • keep runtime-sensitive forward references semantically equivalent where direct evaluation would be unsafe
  • keep test/compat/test_torch_proxy.py coverage for evaluated torch.device | None behavior
  • remove stale docstring-example # type: ignore suppressions that became unused after the type-hint cleanup

Validation:

  • ruff check . --fix
  • ruff check .
  • git diff --check upstream/develop...HEAD
  • python3.10 py_compile for 132 modified Python files ✅
  • pre-commit run --files $(git diff --name-only --diff-filter=ACMRT upstream/develop...HEAD)

是否引起精度变化

Comment thread test/compat/test_torch_proxy.py Outdated
Comment thread python/paddle/jit/sot/opcode_translator/executor/variables/base.py

@SigureMo SigureMo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

另外我觉得 UP035、UP007 也可以在这个 PR 里一起做了呀,都是类型提示相关的改动

@SigureWang

Copy link
Copy Markdown

整体看这组改动只是把 Optional[T] 清理为 PEP 604 的 T | None,并同步移除无用 import,语义上没有看到明显行为变化。

需要注意的兼容性前提是:这些文件现在会直接使用 | 类型联合语法,因此运行环境必须已经是 Python 3.10+。如果当前分支仍需要兼容 Python 3.9 或更低版本,这会变成语法级不兼容;仅从本次 diff 无法确认项目的最低 Python 版本是否已经提升。

测试风险方面,test/compat/test_torch_proxy.py 中断言从 Optional[torch.device] 改为 torch.device | None 是合理的,但它依赖 torch.device| 联合类型的行为正常。如果这是为 Ruff/pyupgrade 规则清理,建议至少确保相关 compat 测试在 Python 3.10+ 环境覆盖到,避免 torch.device 这类代理类型在类型联合构造时出现兼容问题。

@ShigureNyako ShigureNyako force-pushed the codestyle/py310-up045-up036-cleanup branch from e88e247 to ef578ce Compare June 9, 2026 16:46
@ShigureNyako ShigureNyako changed the title [CodeStyle] Clean up Python 3.10 UP045/UP036 diagnostics [CodeStyle] Clean up Python 3.10 type-hint diagnostics Jun 9, 2026
@ShigureNyako

Copy link
Copy Markdown
Contributor Author

已按建议补充到同一个 PR,见 ef578ce

这次一起清理了全仓 py310 target 下的 UP035 / UP007,并更新了 PR 标题和 description。验证结果:

  • ruff check . --target-version=py310 --select UP035,UP007 通过
  • ruff check . --target-version=py310 --select UP035,UP007,UP045,UP036 仅剩 [CodeStyle] Clean up Python 3.9 compatibility code #79290 已覆盖文件里的 7 个 UP036
  • pre-commit run --files $(git diff --name-only upstream/develop) 通过
  • python3.10 -B -m py_compile $(git diff --name-only upstream/develop -- '*.py') 通过

Comment thread python/paddle/_typing/backport.py Outdated
Comment thread python/paddle/device/cpu.py Outdated
@ShigureNyako ShigureNyako force-pushed the codestyle/py310-up045-up036-cleanup branch from ef578ce to 47869a3 Compare June 9, 2026 17:22
@paddle-bot paddle-bot Bot added the contributor External developers label Jun 9, 2026
@ShigureNyako ShigureNyako force-pushed the codestyle/py310-up045-up036-cleanup branch from 47869a3 to 76466a0 Compare June 9, 2026 18:24
@ShigureNyako

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

1 similar comment
@ShigureNyako

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@codecov-commenter

codecov-commenter commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@83c656a). Learn more about missing BASE report.

Additional details and impacted files
@@             Coverage Diff             @@
##             develop    #79291   +/-   ##
===========================================
  Coverage           ?   100.00%           
===========================================
  Files              ?        85           
  Lines              ?       119           
  Branches           ?         0           
===========================================
  Hits               ?       119           
  Misses             ?         0           
  Partials           ?         0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ShigureNyako

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

4 similar comments
@ShigureNyako

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@ShigureNyako

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@ShigureNyako

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@ShigureNyako

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@SigureMo

Copy link
Copy Markdown
Member

这个 PR 先别 rerun 了,相关问题等 #79289 解决了再说吧

@SigureMo

Copy link
Copy Markdown
Member

@ShigureNyako #79289#79290 合入了,merge 下最新代码,并解决下冲突,另外 ruff 的 target-version 可以改成 3.10 了,ruff 全量扫一下,修一下吧

@SigureMo

Copy link
Copy Markdown
Member

对了,不许 force-push!

ShigureNyako and others added 2 commits June 10, 2026 16:56
Co-authored-by: Codex <noreply@openai.com>

# Conflicts:
#	python/paddle/vision/transforms/transforms.py
Co-authored-by: Codex <noreply@openai.com>
@ShigureNyako

Copy link
Copy Markdown
Contributor Author

已按要求处理,且没有 force-push:

本地验证通过:

  • ruff check . --fix
  • ruff check .
  • git diff --check upstream/develop...HEAD
  • python3.10 py_compile 132 个改动 Python 文件
  • pre-commit run --files $(git diff --name-only --diff-filter=ACMRT upstream/develop...HEAD)

后续仍不会 force-push。

Comment thread test/compat/test_torch_proxy.py
Comment thread python/paddle/device/cuda/__init__.py
Comment thread python/paddle/device/xpu/__init__.py
Comment thread python/paddle/device/__init__.py
Comment thread python/paddle/device/cpu.py
Comment thread python/paddle/device/custom_device.py
ShigureNyako and others added 2 commits June 10, 2026 17:24
Remove obsolete RUF100 suppressions and the inactive FA100 token from the evaluated Optional torch.device coverage, keeping the active UP045 suppressions.

Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
@SigureMo

Copy link
Copy Markdown
Member

@ShigureNyako static check 挂了,得跟进了

不过喵的 static-check 里怎么有个下载的日志,导致完全看不到报错了,关键信息我提取了下:

2026-06-10T10:27:15.2057302Z ----------------Codeblock Type Checking Start--------------------
2026-06-10T10:27:15.2057859Z >>> Get docstring from api ...
2026-06-10T10:27:16.5560294Z ##[group]API_PR is diff from API_DEV
...
2026-06-10T10:27:16.6406240Z ##[endgroup]
2026-06-10T10:27:16.6406544Z Total api: 2624
2026-06-10T10:27:16.6406934Z >>> Store code snippets to /tmp/tmpa_cb1p80 ...
2026-06-10T10:27:16.9727118Z >>> Preprocess code snippets and run type checker ...
2026-06-10T10:27:26.8664227Z >>> Print summary ...
2026-06-10T10:27:26.8665131Z �[91m�[1mTYPE CHECKING FAILED�[0m in �[96m�[1mpaddle.vision.datasets.MNIST:1�[0m
2026-06-10T10:27:26.8666156Z /tmp/tmpa_cb1p80/paddle_vision_datasets_MNIST__1.py:28:22: �[1m�[31merror:�(B�[m Item �(B�[m�[1m"Image"�(B�[m
2026-06-10T10:27:26.8667207Z of �(B�[m�[1m"Tensor | Image | ndarray[tuple[int, ...], dtype[Any]]"�(B�[m has no attribute
2026-06-10T10:27:26.8667871Z �(B�[m�[1m"shape"�(B�[m  �(B�[m�[33m[union-attr]�(B�[m
2026-06-10T10:27:26.8668465Z �[2;10m        print(type(img), img.shape, label)�(B�[m
2026-06-10T10:27:26.8668947Z �[31m                         ^~~~~~~~~�(B�[m
2026-06-10T10:27:26.8669192Z 
2026-06-10T10:27:26.8669595Z �[91m�[1mTYPE CHECKING FAILED�[0m in �[96m�[1mpaddle.vision.datasets.Cifar100:1�[0m
2026-06-10T10:27:26.8670429Z /tmp/tmpa_cb1p80/paddle_vision_datasets_Cifar100__1.py:30:22: �[1m�[31merror:�(B�[m Item
2026-06-10T10:27:26.8671294Z �(B�[m�[1m"Image"�(B�[m of �(B�[m�[1m"Tensor | Image | ndarray[tuple[int, ...], dtype[Any]]"�(B�[m has no
2026-06-10T10:27:26.8672027Z attribute �(B�[m�[1m"shape"�(B�[m  �(B�[m�[33m[union-attr]�(B�[m
2026-06-10T10:27:26.8672904Z �[2;10m        print(type(img), img.shape, label)�(B�[m
2026-06-10T10:27:26.8673365Z �[31m                         ^~~~~~~~~�(B�[m
2026-06-10T10:27:26.8673620Z 
2026-06-10T10:27:26.8674000Z �[91m�[1mTYPE CHECKING FAILED�[0m in �[96m�[1mpaddle.vision.datasets.Cifar10:1�[0m
2026-06-10T10:27:26.8674817Z /tmp/tmpa_cb1p80/paddle_vision_datasets_Cifar10__1.py:30:22: �[1m�[31merror:�(B�[m Item
2026-06-10T10:27:26.8675668Z �(B�[m�[1m"Image"�(B�[m of �(B�[m�[1m"Tensor | Image | ndarray[tuple[int, ...], dtype[Any]]"�(B�[m has no
2026-06-10T10:27:26.8676393Z attribute �(B�[m�[1m"shape"�(B�[m  �(B�[m�[33m[union-attr]�(B�[m
2026-06-10T10:27:26.8676952Z �[2;10m        print(type(img), img.shape, label)�(B�[m
2026-06-10T10:27:26.8677406Z �[31m                         ^~~~~~~~~�(B�[m
2026-06-10T10:27:26.8677657Z 
2026-06-10T10:27:26.8678108Z �[91m�[1mTYPE CHECKING FAILED�[0m in �[96m�[1mpaddle.vision.datasets.Flowers:1�[0m
2026-06-10T10:27:26.8678929Z /tmp/tmpa_cb1p80/paddle_vision_datasets_Flowers__1.py:30:22: �[1m�[31merror:�(B�[m Item
2026-06-10T10:27:26.8679789Z �(B�[m�[1m"Image"�(B�[m of �(B�[m�[1m"Tensor | Image | ndarray[tuple[int, ...], dtype[Any]]"�(B�[m has no
2026-06-10T10:27:26.8680513Z attribute �(B�[m�[1m"shape"�(B�[m  �(B�[m�[33m[union-attr]�(B�[m
2026-06-10T10:27:26.8681067Z �[2;10m        print(type(img), img.shape, label)�(B�[m
2026-06-10T10:27:26.8681522Z �[31m                         ^~~~~~~~~�(B�[m
2026-06-10T10:27:26.8681780Z 
2026-06-10T10:27:26.8682209Z �[91m�[1mTYPE CHECKING FAILED�[0m in �[96m�[1mpaddle.amp.debugging.check_layer_numerics:1�[0m
2026-06-10T10:27:26.8683187Z /tmp/tmpa_cb1p80/paddle_amp_debugging_check_layer_numerics__1.py:13:5: �[1m�[31merror:�(B�[m
2026-06-10T10:27:26.8684238Z No overload variant of �(B�[m�[1m"rand"�(B�[m matches argument types �(B�[m�[1m"list[int]"�(B�[m, �(B�[m�[1m"str"�(B�[m 
2026-06-10T10:27:26.8684939Z �(B�[m�[33m[call-overload]�(B�[m
2026-06-10T10:27:26.8685392Z �[2;10m    x = paddle.rand([10, 2, 2], dtype=dtype)�(B�[m
2026-06-10T10:27:26.8685895Z �[31m        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~�(B�[m
2026-06-10T10:27:26.8686740Z /tmp/tmpa_cb1p80/paddle_amp_debugging_check_layer_numerics__1.py:13:5: �[34mnote:�(B�[m Possible overload variants:�(B�[m
2026-06-10T10:27:26.8690530Z /tmp/tmpa_cb1p80/paddle_amp_debugging_check_layer_numerics__1.py:13:5: �[34mnote:�(B�[m     def rand(shape: Sequence[int | Tensor | None] | Tensor | Sequence[int] | Tensor, dtype: paddle.framework.dtype.dtype | type[unsignedinteger[_8Bit]] | type[signedinteger[_8Bit]] | type[signedinteger[_16Bit]] | type[signedinteger[_32Bit]] | type[signedinteger[_64Bit]] | <7 more items> | Literal['uint8', 'int8', 'int16', 'int32', 'int64', 'float32', 'float64', 'float16', 'bfloat16', 'complex64', 'complex128', 'bool'] | None = ..., name: str | None = ..., *, out: Tensor | None = ..., device: Place | str | None = ..., pin_memory: bool = ..., requires_grad: bool = ...) -> Tensor�(B�[m
2026-06-10T10:27:26.8695895Z /tmp/tmpa_cb1p80/paddle_amp_debugging_check_layer_numerics__1.py:13:5: �[34mnote:�(B�[m     def rand(*size: int, out: Tensor | None = ..., dtype: paddle.framework.dtype.dtype | type[unsignedinteger[_8Bit]] | type[signedinteger[_8Bit]] | type[signedinteger[_16Bit]] | type[signedinteger[_32Bit]] | type[signedinteger[_64Bit]] | <7 more items> | Literal['uint8', 'int8', 'int16', 'int32', 'int64', 'float32', 'float64', 'float16', 'bfloat16', 'complex64', 'complex128', 'bool'] | None = ..., device: Place | str | None = ..., pin_memory: bool = ..., requires_grad: bool = ...) -> Tensor�(B�[m
2026-06-10T10:27:26.8698289Z 
2026-06-10T10:27:26.8698705Z �[91m�[1mTYPE CHECKING FAILED�[0m in �[96m�[1mpaddle.vision.datasets.FashionMNIST:1�[0m
2026-06-10T10:27:26.8699583Z /tmp/tmpa_cb1p80/paddle_vision_datasets_FashionMNIST__1.py:28:22: �[1m�[31merror:�(B�[m Item
2026-06-10T10:27:26.8700462Z �(B�[m�[1m"Image"�(B�[m of �(B�[m�[1m"Tensor | Image | ndarray[tuple[int, ...], dtype[Any]]"�(B�[m has no
2026-06-10T10:27:26.8701187Z attribute �(B�[m�[1m"shape"�(B�[m  �(B�[m�[33m[union-attr]�(B�[m
2026-06-10T10:27:26.8701929Z �[2;10m        print(type(img), img.shape, label)�(B�[m
2026-06-10T10:27:26.8702398Z �[31m                         ^~~~~~~~~�(B�[m
2026-06-10T10:27:26.8702659Z 
2026-06-10T10:27:26.8703012Z �[91m�[1mTYPE CHECKING FAILED�[0m in �[96m�[1mpaddle.distribution.Uniform:1�[0m
2026-06-10T10:27:26.8703868Z /tmp/tmpa_cb1p80/paddle_distribution_Uniform__1.py:7:10: �[1m�[31merror:�(B�[m List item 0 has
2026-06-10T10:27:26.8704820Z incompatible type �(B�[m�[1m"list[float]"�(B�[m; expected �(B�[m�[1m"float"�(B�[m  �(B�[m�[33m[list-item]�(B�[m
2026-06-10T10:27:26.8705520Z �[2;10m        low=[[1.0, 2.0], [3.0, 4.0]],�(B�[m
2026-06-10T10:27:26.8705938Z �[31m             ^~~~~~~~~~�(B�[m
2026-06-10T10:27:26.8706703Z /tmp/tmpa_cb1p80/paddle_distribution_Uniform__1.py:7:22: �[1m�[31merror:�(B�[m List item 1 has
2026-06-10T10:27:26.8707663Z incompatible type �(B�[m�[1m"list[float]"�(B�[m; expected �(B�[m�[1m"float"�(B�[m  �(B�[m�[33m[list-item]�(B�[m
2026-06-10T10:27:26.8708419Z �[2;10m        low=[[1.0, 2.0], [3.0, 4.0]],�(B�[m
2026-06-10T10:27:26.8708864Z �[31m                         ^~~~~~~~~~�(B�[m
2026-06-10T10:27:26.8709566Z /tmp/tmpa_cb1p80/paddle_distribution_Uniform__1.py:8:11: �[1m�[31merror:�(B�[m List item 0 has
2026-06-10T10:27:26.8710503Z incompatible type �(B�[m�[1m"list[float]"�(B�[m; expected �(B�[m�[1m"float"�(B�[m  �(B�[m�[33m[list-item]�(B�[m
2026-06-10T10:27:26.8711192Z �[2;10m        high=[[1.5, 2.5], [3.5, 4.5]],�(B�[m
2026-06-10T10:27:26.8711607Z �[31m              ^~~~~~~~~~�(B�[m
2026-06-10T10:27:26.8712255Z /tmp/tmpa_cb1p80/paddle_distribution_Uniform__1.py:8:23: �[1m�[31merror:�(B�[m List item 1 has
2026-06-10T10:27:26.8713336Z incompatible type �(B�[m�[1m"list[float]"�(B�[m; expected �(B�[m�[1m"float"�(B�[m  �(B�[m�[33m[list-item]�(B�[m
2026-06-10T10:27:26.8714031Z �[2;10m        high=[[1.5, 2.5], [3.5, 4.5]],�(B�[m
2026-06-10T10:27:26.8714487Z �[31m                          ^~~~~~~~~~�(B�[m
2026-06-10T10:27:26.8714733Z 
2026-06-10T10:27:26.8715087Z �[91m�[1mTYPE CHECKING FAILED�[0m in �[96m�[1mpaddle.incubate.inference:1�[0m
2026-06-10T10:27:26.8715897Z /tmp/tmpa_cb1p80/paddle_incubate_inference__1.py:20:5: �[1m�[31merror:�(B�[m No overload
2026-06-10T10:27:26.8716923Z variant of �(B�[m�[1m"rand"�(B�[m matches argument types �(B�[m�[1m"list[int]"�(B�[m, �(B�[m�[1m"str"�(B�[m  �(B�[m�[33m[call-overload]�(B�[m
2026-06-10T10:27:26.8717763Z �[2;10m    x = paddle.rand([batch, hidd], dtype=dtype)�(B�[m
2026-06-10T10:27:26.8718347Z �[31m        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~�(B�[m
2026-06-10T10:27:26.8719131Z /tmp/tmpa_cb1p80/paddle_incubate_inference__1.py:20:5: �[34mnote:�(B�[m Possible overload variants:�(B�[m
2026-06-10T10:27:26.8722656Z /tmp/tmpa_cb1p80/paddle_incubate_inference__1.py:20:5: �[34mnote:�(B�[m     def rand(shape: Sequence[int | Tensor | None] | Tensor | Sequence[int] | Tensor, dtype: paddle.framework.dtype.dtype | type[unsignedinteger[_8Bit]] | type[signedinteger[_8Bit]] | type[signedinteger[_16Bit]] | type[signedinteger[_32Bit]] | type[signedinteger[_64Bit]] | <7 more items> | Literal['uint8', 'int8', 'int16', 'int32', 'int64', 'float32', 'float64', 'float16', 'bfloat16', 'complex64', 'complex128', 'bool'] | None = ..., name: str | None = ..., *, out: Tensor | None = ..., device: Place | str | None = ..., pin_memory: bool = ..., requires_grad: bool = ...) -> Tensor�(B�[m
2026-06-10T10:27:26.8727842Z /tmp/tmpa_cb1p80/paddle_incubate_inference__1.py:20:5: �[34mnote:�(B�[m     def rand(*size: int, out: Tensor | None = ..., dtype: paddle.framework.dtype.dtype | type[unsignedinteger[_8Bit]] | type[signedinteger[_8Bit]] | type[signedinteger[_16Bit]] | type[signedinteger[_32Bit]] | type[signedinteger[_64Bit]] | <7 more items> | Literal['uint8', 'int8', 'int16', 'int32', 'int64', 'float32', 'float64', 'float16', 'bfloat16', 'complex64', 'complex128', 'bool'] | None = ..., device: Place | str | None = ..., pin_memory: bool = ..., requires_grad: bool = ...) -> Tensor�(B�[m
2026-06-10T10:27:26.8730172Z 
2026-06-10T10:27:26.8730669Z �[91m�[1mTYPE CHECKING FAILED�[0m in �[96m�[1mpaddle.nn.functional.class_center_sample:code-example2�[0m
2026-06-10T10:27:26.8731803Z /tmp/tmpa_cb1p80/paddle_nn_functional_class_center_sample__code-example2.py:10:9: �[1m�[31merror:�(B�[m
2026-06-10T10:27:26.8732829Z No overload variant of �(B�[m�[1m"randint"�(B�[m matches argument types �(B�[m�[1m"int"�(B�[m, �(B�[m�[1m"int"�(B�[m,
2026-06-10T10:27:26.8733662Z �(B�[m�[1m"list[int]"�(B�[m, �(B�[m�[1m"str"�(B�[m  �(B�[m�[33m[call-overload]�(B�[m
2026-06-10T10:27:26.8734429Z �[2;10m    label = paddle.randint(low=0, high=int(num_classes.item()), size=[batc...�(B�[m
2026-06-10T10:27:26.8735160Z �[2;10m            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~...�(B�[m
2026-06-10T10:27:26.8736479Z /tmp/tmpa_cb1p80/paddle_nn_functional_class_center_sample__code-example2.py:10:9: �[34mnote:�(B�[m Error code �(B�[m�[1m"call-overload"�(B�[m not covered by �(B�[m�[1m"type: ignore[arg-type]"�(B�[m comment�(B�[m
2026-06-10T10:27:26.8738086Z /tmp/tmpa_cb1p80/paddle_nn_functional_class_center_sample__code-example2.py:10:9: �[34mnote:�(B�[m Possible overload variants:�(B�[m
2026-06-10T10:27:26.8742144Z /tmp/tmpa_cb1p80/paddle_nn_functional_class_center_sample__code-example2.py:10:9: �[34mnote:�(B�[m     def randint(low: int = ..., high: int | None = ..., size: Sequence[int | Tensor | None] | Tensor | Sequence[int] | Tensor = ..., dtype: paddle.framework.dtype.dtype | type[unsignedinteger[_8Bit]] | type[signedinteger[_8Bit]] | type[signedinteger[_16Bit]] | type[signedinteger[_32Bit]] | type[signedinteger[_64Bit]] | <7 more items> | Literal['uint8', 'int8', 'int16', 'int32', 'int64', 'float32', 'float64', 'float16', 'bfloat16', 'complex64', 'complex128', 'bool'] | None = ..., name: str | None = ..., *, out: Tensor | None = ..., device: Place | str | None = ..., pin_memory: bool = ..., requires_grad: bool = ...) -> Tensor�(B�[m
2026-06-10T10:27:26.8748397Z /tmp/tmpa_cb1p80/paddle_nn_functional_class_center_sample__code-example2.py:10:9: �[34mnote:�(B�[m     def randint(high: int, size: Sequence[int | Tensor | None] | Tensor | Sequence[int] | Tensor, dtype: paddle.framework.dtype.dtype | type[unsignedinteger[_8Bit]] | type[signedinteger[_8Bit]] | type[signedinteger[_16Bit]] | type[signedinteger[_32Bit]] | type[signedinteger[_64Bit]] | <7 more items> | Literal['uint8', 'int8', 'int16', 'int32', 'int64', 'float32', 'float64', 'float16', 'bfloat16', 'complex64', 'complex128', 'bool'] | None = ..., name: str | None = ..., *, out: Tensor | None = ..., device: Place | str | None = ..., pin_memory: bool = ..., requires_grad: bool = ...) -> Tensor�(B�[m
2026-06-10T10:27:26.8751181Z 
2026-06-10T10:27:26.8751583Z �[91m�[1mTYPE CHECKING FAILED�[0m in �[96m�[1mpaddle.vision.datasets.VOC2012:1�[0m
2026-06-10T10:27:26.8752415Z /tmp/tmpa_cb1p80/paddle_vision_datasets_VOC2012__1.py:31:22: �[1m�[31merror:�(B�[m Item
2026-06-10T10:27:26.8753277Z �(B�[m�[1m"Image"�(B�[m of �(B�[m�[1m"Tensor | Image | ndarray[tuple[int, ...], dtype[Any]]"�(B�[m has no
2026-06-10T10:27:26.8754000Z attribute �(B�[m�[1m"shape"�(B�[m  �(B�[m�[33m[union-attr]�(B�[m
2026-06-10T10:27:26.8754548Z �[2;10m        print(type(img), img.shape)�(B�[m
2026-06-10T10:27:26.8755018Z �[31m                         ^~~~~~~~~�(B�[m
2026-06-10T10:27:26.8755260Z 
2026-06-10T10:27:26.8755671Z �[91m�[1mTYPE CHECKING FAILED�[0m in �[96m�[1mpaddle.vision.datasets.DatasetFolder:1�[0m
2026-06-10T10:27:26.8756555Z /tmp/tmpa_cb1p80/paddle_vision_datasets_DatasetFolder__1.py:75:22: �[1m�[31merror:�(B�[m Item
2026-06-10T10:27:26.8757445Z �(B�[m�[1m"Image"�(B�[m of �(B�[m�[1m"Tensor | Image | ndarray[tuple[int, ...], dtype[Any]]"�(B�[m has no
2026-06-10T10:27:26.8758240Z attribute �(B�[m�[1m"shape"�(B�[m  �(B�[m�[33m[union-attr]�(B�[m
2026-06-10T10:27:26.8758798Z �[2;10m        print(type(img), img.shape, label)�(B�[m
2026-06-10T10:27:26.8759264Z �[31m                         ^~~~~~~~~�(B�[m
2026-06-10T10:27:26.8759517Z 
2026-06-10T10:27:26.8759927Z �[91m�[1mTYPE CHECKING FAILED�[0m in �[96m�[1mpaddle.vision.datasets.ImageFolder:1�[0m
2026-06-10T10:27:26.8760870Z /tmp/tmpa_cb1p80/paddle_vision_datasets_ImageFolder__1.py:69:22: �[1m�[31merror:�(B�[m Item
2026-06-10T10:27:26.8761805Z �(B�[m�[1m"Image"�(B�[m of �(B�[m�[1m"Tensor | Image | ndarray[tuple[int, ...], dtype[Any]]"�(B�[m has no
2026-06-10T10:27:26.8762529Z attribute �(B�[m�[1m"shape"�(B�[m  �(B�[m�[33m[union-attr]�(B�[m
2026-06-10T10:27:26.8763060Z �[2;10m        print(type(img), img.shape)�(B�[m
2026-06-10T10:27:26.8763508Z �[31m                         ^~~~~~~~~�(B�[m
2026-06-10T10:27:26.8763758Z 
2026-06-10T10:27:26.8764250Z �[91m�[1mTYPE CHECKING FAILED�[0m in �[96m�[1mpaddle.nn.functional.margin_cross_entropy:code-example2�[0m
2026-06-10T10:27:26.8765262Z /tmp/tmpa_cb1p80/paddle_nn_functional_margin_cross_entropy__code-example2.py:16:9: �[1m�[31merror:�(B�[m
2026-06-10T10:27:26.8766280Z No overload variant of �(B�[m�[1m"randint"�(B�[m matches argument types �(B�[m�[1m"int"�(B�[m, �(B�[m�[1m"int"�(B�[m,
2026-06-10T10:27:26.8767107Z �(B�[m�[1m"list[int]"�(B�[m, �(B�[m�[1m"str"�(B�[m  �(B�[m�[33m[call-overload]�(B�[m
2026-06-10T10:27:26.8767861Z �[2;10m    label = paddle.randint(low=0, high=int(num_classes.item()), size=[batc...�(B�[m
2026-06-10T10:27:26.8768670Z �[2;10m            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~...�(B�[m
2026-06-10T10:27:26.8769980Z /tmp/tmpa_cb1p80/paddle_nn_functional_margin_cross_entropy__code-example2.py:16:9: �[34mnote:�(B�[m Error code �(B�[m�[1m"call-overload"�(B�[m not covered by �(B�[m�[1m"type: ignore[arg-type]"�(B�[m comment�(B�[m
2026-06-10T10:27:26.8771518Z /tmp/tmpa_cb1p80/paddle_nn_functional_margin_cross_entropy__code-example2.py:16:9: �[34mnote:�(B�[m Possible overload variants:�(B�[m
2026-06-10T10:27:26.8775624Z /tmp/tmpa_cb1p80/paddle_nn_functional_margin_cross_entropy__code-example2.py:16:9: �[34mnote:�(B�[m     def randint(low: int = ..., high: int | None = ..., size: Sequence[int | Tensor | None] | Tensor | Sequence[int] | Tensor = ..., dtype: paddle.framework.dtype.dtype | type[unsignedinteger[_8Bit]] | type[signedinteger[_8Bit]] | type[signedinteger[_16Bit]] | type[signedinteger[_32Bit]] | type[signedinteger[_64Bit]] | <7 more items> | Literal['uint8', 'int8', 'int16', 'int32', 'int64', 'float32', 'float64', 'float16', 'bfloat16', 'complex64', 'complex128', 'bool'] | None = ..., name: str | None = ..., *, out: Tensor | None = ..., device: Place | str | None = ..., pin_memory: bool = ..., requires_grad: bool = ...) -> Tensor�(B�[m
2026-06-10T10:27:26.8781737Z /tmp/tmpa_cb1p80/paddle_nn_functional_margin_cross_entropy__code-example2.py:16:9: �[34mnote:�(B�[m     def randint(high: int, size: Sequence[int | Tensor | None] | Tensor | Sequence[int] | Tensor, dtype: paddle.framework.dtype.dtype | type[unsignedinteger[_8Bit]] | type[signedinteger[_8Bit]] | type[signedinteger[_16Bit]] | type[signedinteger[_32Bit]] | type[signedinteger[_64Bit]] | <7 more items> | Literal['uint8', 'int8', 'int16', 'int32', 'int64', 'float32', 'float64', 'float16', 'bfloat16', 'complex64', 'complex128', 'bool'] | None = ..., name: str | None = ..., *, out: Tensor | None = ..., device: Place | str | None = ..., pin_memory: bool = ..., requires_grad: bool = ...) -> Tensor�(B�[m
2026-06-10T10:27:26.8784497Z 
2026-06-10T10:27:26.8784862Z �[91m�[1mTYPE CHECKING FAILED�[0m in �[96m�[1mpaddle.audio.datasets.ESC50:1�[0m
2026-06-10T10:27:26.8785784Z /tmp/tmpa_cb1p80/paddle_audio_datasets_ESC50__1.py:4:10: �[1m�[31merror:�(B�[m Argument �(B�[m�[1m"mode"�(B�[m
2026-06-10T10:27:26.8786908Z to �(B�[m�[1m"ESC50"�(B�[m has incompatible type �(B�[m�[1m"str"�(B�[m; expected �(B�[m�[1m"Literal['train', 'dev']"�(B�[m 
2026-06-10T10:27:26.8787588Z �(B�[m�[33m[arg-type]�(B�[m
2026-06-10T10:27:26.8788017Z �[2;10m        mode=mode,�(B�[m
2026-06-10T10:27:26.8788383Z �[31m             ^~~~�(B�[m
2026-06-10T10:27:26.8788976Z /tmp/tmpa_cb1p80/paddle_audio_datasets_ESC50__1.py:13:10: �[1m�[31merror:�(B�[m Argument
2026-06-10T10:27:26.8789819Z �(B�[m�[1m"mode"�(B�[m to �(B�[m�[1m"ESC50"�(B�[m has incompatible type �(B�[m�[1m"str"�(B�[m; expected
2026-06-10T10:27:26.8790545Z �(B�[m�[1m"Literal['train', 'dev']"�(B�[m  �(B�[m�[33m[arg-type]�(B�[m
2026-06-10T10:27:26.8791170Z �[2;10m        mode=mode,�(B�[m
2026-06-10T10:27:26.8791536Z �[31m             ^~~~�(B�[m
2026-06-10T10:27:26.8791742Z 
2026-06-10T10:27:26.8792091Z �[91m�[1mTYPE CHECKING FAILED�[0m in �[96m�[1mpaddle.audio.datasets.TESS:1�[0m
2026-06-10T10:27:26.8792989Z /tmp/tmpa_cb1p80/paddle_audio_datasets_TESS__1.py:4:10: �[1m�[31merror:�(B�[m Argument �(B�[m�[1m"mode"�(B�[m
2026-06-10T10:27:26.8793985Z to �(B�[m�[1m"TESS"�(B�[m has incompatible type �(B�[m�[1m"str"�(B�[m; expected �(B�[m�[1m"Literal['train', 'dev']"�(B�[m 
2026-06-10T10:27:26.8794666Z �(B�[m�[33m[arg-type]�(B�[m
2026-06-10T10:27:26.8795024Z �[2;10m        mode=mode,�(B�[m
2026-06-10T10:27:26.8795373Z �[31m             ^~~~�(B�[m
2026-06-10T10:27:26.8796062Z /tmp/tmpa_cb1p80/paddle_audio_datasets_TESS__1.py:13:10: �[1m�[31merror:�(B�[m Argument �(B�[m�[1m"mode"�(B�[m
2026-06-10T10:27:26.8797052Z to �(B�[m�[1m"TESS"�(B�[m has incompatible type �(B�[m�[1m"str"�(B�[m; expected �(B�[m�[1m"Literal['train', 'dev']"�(B�[m 
2026-06-10T10:27:26.8797716Z �(B�[m�[33m[arg-type]�(B�[m
2026-06-10T10:27:26.8798137Z �[2;10m        mode=mode,�(B�[m
2026-06-10T10:27:26.8798501Z �[31m             ^~~~�(B�[m
2026-06-10T10:27:26.8798687Z 
2026-06-10T10:27:26.8799029Z �[91m�[1mTYPE CHECKING FAILED�[0m in �[96m�[1mpaddle.Tensor.new_zeros:1�[0m
2026-06-10T10:27:26.8799819Z /tmp/tmpa_cb1p80/paddle_Tensor_new_zeros__1.py:3:17: �[1m�[31merror:�(B�[m Argument 1 to
2026-06-10T10:27:26.8800747Z �(B�[m�[1m"new_zeros"�(B�[m of �(B�[m�[1m"AbstractTensor"�(B�[m has incompatible type �(B�[m�[1m"int"�(B�[m; expected
2026-06-10T10:27:26.8801777Z �(B�[m�[1m"Sequence[int | Tensor | None] | Tensor | Sequence[int] | Tensor"�(B�[m  �(B�[m�[33m[arg-type]�(B�[m
2026-06-10T10:27:26.8802567Z �[2;10m    y = x.new_zeros(3, 3)  # type: ignore[misc]�(B�[m
2026-06-10T10:27:26.8803038Z �[31m                    ^�(B�[m
2026-06-10T10:27:26.8804009Z /tmp/tmpa_cb1p80/paddle_Tensor_new_zeros__1.py:3:17: �[34mnote:�(B�[m Error code �(B�[m�[1m"arg-type"�(B�[m not covered by �(B�[m�[1m"type: ignore[misc]"�(B�[m comment�(B�[m
2026-06-10T10:27:26.8805140Z /tmp/tmpa_cb1p80/paddle_Tensor_new_zeros__1.py:3:20: �[1m�[31merror:�(B�[m Argument 2 to
2026-06-10T10:27:26.8806090Z �(B�[m�[1m"new_zeros"�(B�[m of �(B�[m�[1m"AbstractTensor"�(B�[m has incompatible type �(B�[m�[1m"Literal[3]"�(B�[m; expected
2026-06-10T10:27:26.8808311Z �(B�[m�[1m"paddle.framework.dtype.dtype | type[unsignedinteger[_8Bit]] | type[signedinteger[_8Bit]] | type[signedinteger[_16Bit]] | type[signedinteger[_32Bit]] | type[signedinteger[_64Bit]] | <7 more items> | Literal['uint8', 'int8', 'int16', 'int32', 'int64', 'float32', 'float64', 'float16', 'bfloat16', 'complex64', 'complex128', 'bool'] | None"�(B�[m
2026-06-10T10:27:26.8809948Z  �(B�[m�[33m[arg-type]�(B�[m
2026-06-10T10:27:26.8810394Z �[2;10m    y = x.new_zeros(3, 3)  # type: ignore[misc]�(B�[m
2026-06-10T10:27:26.8810850Z �[31m                       ^�(B�[m
2026-06-10T10:27:26.8811066Z 
2026-06-10T10:27:26.8811185Z >>> Mypy summary:
2026-06-10T10:27:26.8811651Z �[1m�[31mFound 22 errors in 16 files (checked 1952 source files)�(B�[m
2026-06-10T10:27:26.8812136Z >>> Mistakes found in type checking!
2026-06-10T10:27:26.8812728Z >>> Please recheck the type annotations. Run `tools/type_checking.py` to check the typing issues:
2026-06-10T10:27:26.8815865Z     $ python tools/type_checking.py paddle.Tensor.new_zeros paddle.amp.debugging.check_layer_numerics paddle.audio.datasets.ESC50 paddle.audio.datasets.TESS paddle.distribution.Uniform paddle.incubate.inference paddle.nn.functional.class_center_sample paddle.nn.functional.margin_cross_entropy paddle.vision.datasets.Cifar10 paddle.vision.datasets.Cifar100 paddle.vision.datasets.DatasetFolder paddle.vision.datasets.FashionMNIST paddle.vision.datasets.Flowers paddle.vision.datasets.ImageFolder paddle.vision.datasets.MNIST paddle.vision.datasets.VOC2012
2026-06-10T10:27:26.8819399Z >>> For more information: https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/dev_guides/style_guide_and_references/type_annotations_specification_cn.html
2026-06-10T10:27:27.0609374Z ===============================================================================

你顺带看看那个一大堆下载日志是谁输出的,如果可以的话(如果复杂的话就不要改了,毕竟涉及示例代码),不要让它在日志里输出这么多,真离谱

@ShigureNyako

Copy link
Copy Markdown
Contributor Author

已跟进 static-check,normal push 追加了修复提交 a93496b3bcc(未 force-push)。

处理内容:

  • 修复 sample code type checking 报出的 16 个 API 示例问题:img.shape 前补充 paddle.Tensor 类型收窄,dtype 示例改用 paddle.float32 / paddle.bfloat16Uniform 嵌套 list 示例改为 paddle.to_tensor,并清理/修正过期的 inline type: ignore
  • 保持示例运行输出不变,只补充类型检查所需的无输出断言或类型更明确的写法。

本地已过:

  • python3.10 -m py_compile(本次修改文件)
  • ruff check(本次修改文件)
  • git diff --check
  • pre-commit run --files ...

本地 tools/type_checking.py ... 因当前机器未安装可导入的 paddle wheel,无法完整复现;这次按 CI 提取出的 mypy 报错逐项修复。

@SigureMo SigureMo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

别改人家代码语义

  • 如果是我们类型上哪里有问题,就补全
  • 如果实在不行,就 ignore

感觉就 datasets 下的文件改的合理,其他的都重新 review 下吧

Comment thread python/paddle/base/dygraph/math_op_patch.py Outdated
Comment thread python/paddle/distribution/uniform.py
Comment thread python/paddle/amp/debugging.py
Comment thread python/paddle/vision/datasets/mnist.py
Comment thread python/paddle/vision/datasets/voc2012.py
Comment thread python/paddle/vision/datasets/mnist.py
Comment thread python/paddle/vision/datasets/cifar.py
@ShigureNyako

Copy link
Copy Markdown
Contributor Author

已按 review 调整,normal push 追加了 f201f26b640(未 force-push)。

处理内容:

  • datasets 下已确认可接受的 paddle.Tensor 类型收窄保留。
  • 其他 sample code 恢复原运行时语义:
    • new_zeros(3, 3) 恢复,只改为正确的 type: ignore[arg-type]
    • Uniform 恢复嵌套 Python list,只加 type: ignore[list-item]
    • 字符串 dtype 示例恢复,通过 Literal 补全类型;
    • distributed 示例恢复 dtype='int64',只把 ignore 改成实际的 call-overload

本地验证通过:

  • python3.10 -m py_compile(本次 6 个修改文件)
  • ruff check(本次 6 个修改文件)
  • git diff --check
  • pre-commit run --files ...

Comment thread python/paddle/amp/debugging.py Outdated
Comment thread python/paddle/incubate/jit/inference_decorator.py Outdated
@ShigureNyako

Copy link
Copy Markdown
Contributor Author

已继续按 review 调整,normal push 追加 f2f55f478aa(未 force-push):

  • check_layer_numerics / incubate.inference 的 dtype 示例不再用 Literal,恢复用户更友好的原写法;
  • 仅在触发 sample-code mypy call-overloadpaddle.rand(...) 行加 inline ignore。

本地验证通过:

  • python3.10 -m py_compile(本次 2 个修改文件)
  • ruff check(本次 2 个修改文件)
  • git diff --check
  • pre-commit run --files ...

@SigureMo

Copy link
Copy Markdown
Member

@ShigureNyako static-check 又挂了,自己想办法拉日志修复吧

@ShigureNyako

Copy link
Copy Markdown
Contributor Author

已跟进最新 Static-Check / Test,normal push 追加 18a4235b2ae(未 force-push)。

本次 fresh log 里剩余 3 个 sample-code type checking 问题,都是 inline type: ignore code 不匹配:

  • new_zeros(3, 3) 实际报 misc,已改为 # type: ignore[misc]
  • class_center_sample / margin_cross_entropypaddle.randint(... dtype='int64') 还会在 int(num_classes.item()) 上报 arg-type,已改为 # type: ignore[call-overload,arg-type]

只调整 ignore code,不改变示例运行语义。

本地验证通过:

  • python3.10 -m py_compile(本次 3 个修改文件)
  • ruff check(本次 3 个修改文件)
  • git diff --check
  • pre-commit run --files ...

@ShigureNyako

Copy link
Copy Markdown
Contributor Author

已继续跟进最新 Static-Check / Test 日志,normal push 追加 e5fda85ed68(未 force-push)。

原因是 new_zeros(3, 3) 这行在 mypy 下同时可能触发 miscarg-type,上一次只覆盖 misc 仍不够稳妥;现在改为:

# type: ignore[misc,arg-type]

只调整 inline ignore code,不改变示例运行语义。

本地验证通过:

  • python3.10 -m py_compile python/paddle/base/dygraph/math_op_patch.py
  • ruff check python/paddle/base/dygraph/math_op_patch.py
  • git diff --check
  • pre-commit run --files python/paddle/base/dygraph/math_op_patch.py

Comment thread python/paddle/base/dygraph/math_op_patch.py Outdated
Comment thread python/paddle/nn/functional/common.py Outdated
Comment thread python/paddle/nn/functional/loss.py Outdated
Co-authored-by: Nyakku Shigure <sigure.qaq@gmail.com>
@ShigureNyako

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@SigureMo SigureMo merged commit 00ece82 into PaddlePaddle:develop Jun 10, 2026
95 of 98 checks passed
@SigureMo SigureMo deleted the codestyle/py310-up045-up036-cleanup branch June 10, 2026 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants