Skip to content

[CodeStyle][Xdoctest][8,12,15,16,18-20,22-26,29-40,42,43,45-48,50,51,60-65,75,80,82,83,85-87,89-94,99-141,143,145,147-167,169-187,207-220,257,258,260-275,277-313,315-325][API Compatibility] Update shape output format in documentation examples#76574

Merged
SigureMo merged 5 commits intoPaddlePaddle:developfrom
LittleHeroZZZX:apis/size
Nov 26, 2025

Conversation

@LittleHeroZZZX
Copy link
Contributor

@LittleHeroZZZX LittleHeroZZZX commented Nov 24, 2025

PR Category

User Experience

PR Types

Docs

Description

#76361 后,Paddle 的 shape 类型从 List 变成 paddle.Size。

本 PR 扫描了 Python 目录下含有 .shape 语句的 sample 代码,并将输出的 List 修改为 Paddle.Size

@paddle-bot
Copy link

paddle-bot bot commented Nov 24, 2025

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@fa5e056). Learn more about missing BASE report.

Files with missing lines Patch % Lines
python/paddle/nn/layer/norm.py 0.00% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (87.50%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop   #76574   +/-   ##
==========================================
  Coverage           ?   87.50%           
==========================================
  Files              ?        5           
  Lines              ?        8           
  Branches           ?        0           
==========================================
  Hits               ?        7           
  Misses             ?        1           
  Partials           ?        0           

☔ View full report in Codecov by Sentry.
📢 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.

paddle.Size([3, 3])
>>> print(H_y_x1_x2.shape)
[3, 4]
paddle.Size([3, 4]
Copy link
Contributor

Choose a reason for hiding this comment

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

有些后面没有括号

Copy link
Contributor Author

Choose a reason for hiding this comment

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

先不 Review,替换脚本还不够完善,并且也没按照 #76545 的要求修改为 pycon

@LittleHeroZZZX LittleHeroZZZX changed the title [API Compatibility] Update shape output format in documentation examples [CodeStyle][Xdoctest][8,12,15,16,18,19,20,22,23,24,25,26,29,30,31,32,34,35,36,38,39,40,42,43,45,46,47,48,50,51,60,61,62,63,64,65,75,80,82,83,85,86,87,89,90,91,92,93,94,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,143,145,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,207,208,209,210,211,212,213,214,215,216,217,218,219,220,257,258,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,315,316,317,318,319,320,321,322,323,324,325][API Compatibility] Update shape output format in documentation examples Nov 25, 2025
Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

有几处因为 magic trailing comma 的存在格式化的不太好看,麻烦删掉这些 comma 后重新格式化下(ruff format .

>>> x2 = paddle.randn([3, ])
>>> x1 = paddle.randn(
... [
... 3,
Copy link
Member

Choose a reason for hiding this comment

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

这个格式化后太难看了,麻烦把后面的 , 删掉,这样格式化后的就正常了

... )
>>> x2 = paddle.randn(
... [
... 3,
Copy link
Member

Choose a reason for hiding this comment

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

同上

... [
... 4,
... ]
... )
Copy link
Member

Choose a reason for hiding this comment

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

同上

>>> rsample = rv.rsample([3, ])
>>> rsample = rv.rsample(
... [
... 3,
Copy link
Member

Choose a reason for hiding this comment

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

同上

... paddle.nn.functional.sigmoid(
... rv.rsample(
... [
... 1000,
Copy link
Member

Choose a reason for hiding this comment

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

同上

... paddle.nn.functional.sigmoid(
... rv.rsample(
... [
... 1000,
Copy link
Member

Choose a reason for hiding this comment

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

同上

... )
>>> seq_lens = paddle.to_tensor(
... [
... seq_len,
Copy link
Member

Choose a reason for hiding this comment

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

同上

... [
... [
... 0,
... 1,
Copy link
Member

Choose a reason for hiding this comment

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

这里也是,辛苦删掉 1 后面的这个 , 再格式化下

@SigureMo
Copy link
Member

SigureMo commented Nov 25, 2025

另外辛苦在 pyproject.toml 里修改一下 line-length 吧,因为这是第一个大 PR,能反映出来整体 format 的一些问题,现在看起来明显有不少不必要的折行,我们可以把 line-length 调大些

 [tool.ruff.format]
 # Prevent change to double quotes by some users use ruff format
 quote-style = "preserve"
 docstring-code-format = true
+docstring-code-line-length = 120

辛苦调整后跑一次 ruff format . 全量格式化下~

cc. @ooooo-create 如果后续有其他 PR,需要先等这个 PR merge

@LittleHeroZZZX
Copy link
Contributor Author

辛苦在 pyproject.toml 里修改一下 line-length

Done. static check 还没过,应该存在一些正确性问题,明天再改

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates documentation examples across the Paddle codebase to reflect a change in the shape output format. Following PR #76361, the .shape attribute now returns paddle.Size([...]) instead of a plain list [...]. The changes ensure that documentation examples accurately reflect this new output format.

Key Changes:

  • Updated shape output format in documentation from [3, 2, 4] to paddle.Size([3, 2, 4])
  • Changed code block type from python to pycon to match the doctest format
  • Added docstring-code-line-length = 120 to pyproject.toml for better formatting control
  • Minor code style improvements (spacing, line breaks) for better readability

Reviewed changes

Copilot reviewed 81 out of 81 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pyproject.toml Added docstring code line length configuration (120 characters)
test/legacy_test/nets.py Reformatted multi-line function calls to single lines
python/paddle/vision/transforms/transforms.py Updated shape outputs and changed code blocks to pycon format
python/paddle/vision/transforms/functional.py Updated shape outputs to paddle.Size format
python/paddle/vision/ops.py Updated shape outputs in vision operation examples
python/paddle/vision/models/*.py Updated shape outputs for VGG, ResNet, MobileNet, and other model examples
python/paddle/tensor/*.py Updated shape outputs in tensor manipulation, math, linalg, and creation functions
python/paddle/nn/layer/*.py Updated shape outputs in pooling, conv, norm, RNN, and transformer layer examples
python/paddle/nn/functional/*.py Updated shape outputs in functional API examples
python/paddle/sparse/*.py Updated shape outputs in sparse tensor examples
python/paddle/signal.py Updated shape outputs in signal processing examples
python/paddle/incubate/*.py Updated shape outputs in incubator module examples
python/paddle/distribution/*.py Updated shape outputs in distribution examples
python/paddle/autograd/autograd.py Updated shape outputs in autograd examples

The changes are consistent and appropriate throughout the codebase. All documentation examples now correctly reflect the new paddle.Size output format, ensuring users have accurate expectations when running code examples.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@SigureMo SigureMo changed the title [CodeStyle][Xdoctest][8,12,15,16,18,19,20,22,23,24,25,26,29,30,31,32,34,35,36,38,39,40,42,43,45,46,47,48,50,51,60,61,62,63,64,65,75,80,82,83,85,86,87,89,90,91,92,93,94,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,143,145,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,207,208,209,210,211,212,213,214,215,216,217,218,219,220,257,258,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,315,316,317,318,319,320,321,322,323,324,325][API Compatibility] Update shape output format in documentation examples [CodeStyle][Xdoctest][8,12,15,16,18-20,22-26,29-32,34-36,38-40,42,43,45-48,50,51,60-65,75,80,82,83,85-87,89-94,99-141,143,145,147-167,169-187,207-220,257,258,260-275,277-313,315-325][API Compatibility] Update shape output format in documentation examples Nov 25, 2025
@SigureMo SigureMo merged commit c769ecb into PaddlePaddle:develop Nov 26, 2025
83 of 88 checks passed
@SigureMo SigureMo changed the title [CodeStyle][Xdoctest][8,12,15,16,18-20,22-26,29-32,34-36,38-40,42,43,45-48,50,51,60-65,75,80,82,83,85-87,89-94,99-141,143,145,147-167,169-187,207-220,257,258,260-275,277-313,315-325][API Compatibility] Update shape output format in documentation examples [CodeStyle][Xdoctest][8,12,15,16,18-20,22-26,29-36,38-40,42,43,45-48,50,51,60-65,75,80,82,83,85-87,89-94,99-141,143,145,147-167,169-187,207-220,257,258,260-275,277-313,315-325][API Compatibility] Update shape output format in documentation examples Jan 12, 2026
@SigureMo SigureMo changed the title [CodeStyle][Xdoctest][8,12,15,16,18-20,22-26,29-36,38-40,42,43,45-48,50,51,60-65,75,80,82,83,85-87,89-94,99-141,143,145,147-167,169-187,207-220,257,258,260-275,277-313,315-325][API Compatibility] Update shape output format in documentation examples [CodeStyle][Xdoctest][8,12,15,16,18-20,22-26,29-40,42,43,45-48,50,51,60-65,75,80,82,83,85-87,89-94,99-141,143,145,147-167,169-187,207-220,257,258,260-275,277-313,315-325][API Compatibility] Update shape output format in documentation examples Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants