Skip to content

[Dosc] Add missing docstring for some nn.functional apis#78405

Merged
SigureMo merged 1 commit into
PaddlePaddle:developfrom
StatefulDust:fix_doc
Mar 21, 2026
Merged

[Dosc] Add missing docstring for some nn.functional apis#78405
SigureMo merged 1 commit into
PaddlePaddle:developfrom
StatefulDust:fix_doc

Conversation

@ooooo-create
Copy link
Copy Markdown
Contributor

@ooooo-create ooooo-create commented Mar 20, 2026

PR Category

User Experience

PR Types

Docs

Description

fix missing docstring for nn.functional apis
find in PaddlePaddle/docs#7873 (review)

是否引起精度变化

Copilot AI review requested due to automatic review settings March 20, 2026 07:38
@paddle-bot
Copy link
Copy Markdown

paddle-bot Bot commented Mar 20, 2026

你的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.

Copy link
Copy Markdown
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 improves Paddle’s Python API documentation injection by ensuring docstrings/signatures added via python/paddle/_paddle_docs.py also apply to paddle.nn.functional APIs, and by filling in a missing Examples section for paddle.allclose.

Changes:

  • Extend add_doc_and_signature to also patch matching symbols under paddle.nn.functional.
  • Add an Examples block to the allclose docstring content in _paddle_docs.py.

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

@@ -47,7 +47,7 @@ def add_doc_and_signature(func_name: str, docstr: str, func_def: str) -> None:
Add docstr for function (paddle.*) and method (paddle.Tensor.*) if method exists
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

The add_doc_and_signature docstring still says it only adds docstrings for paddle.* and paddle.Tensor.*, but the loop now also updates paddle.nn.functional.*. Please update the docstring to reflect the new behavior to avoid misleading future readers.

Suggested change
Add docstr for function (paddle.*) and method (paddle.Tensor.*) if method exists
Add docstr for functions (paddle.* and paddle.nn.functional.*) and methods (paddle.Tensor.*) if they exist.

Copilot uses AI. Check for mistakes.
@ooooo-create ooooo-create changed the title fix missing docstring for nn.functional apis fix missing docstring for some nn.functional apis Mar 20, 2026
if inspect.isfunction(func):
func.__doc__ = docstr
elif inspect.ismethod(func):
func.__self__.__doc__ = docstr
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.

第一次看这代码,给 __self____doc__ 是什么语义?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

还没有理解呐

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.

func.__func__ 吧?可以单独提个 PR 看看效果

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

okok

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

刚刚试了一下不能直接修改属性

class MyTensor:
    def acos(self):
        pass

x = MyTensor()
func = x.acos
func.__doc__ = "1"

# Traceback (most recent call last):
#   File "/home/ooooo/Projects/Paddle/1.py", line 7, in <module>
#     func.__doc__ = "1"
#     ^^^^^^^^^^^^
# AttributeError: attribute '__doc__' of 'method' objects is not writable

bound method 对象不能被直接修改属性

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.

func.__func__,不是 func

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

哦哦,可以啦!

"""
python_api_sig = _parse_function_signature(func_name, func_def)
for module in [paddle, paddle.Tensor]:
for module in [paddle, paddle.Tensor, paddle.nn.functional]:
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.

是不是在 paddle/phi/ops/yaml/python_api_info.yaml 里的都有可能有这个问题?

Copy link
Copy Markdown
Contributor Author

@ooooo-create ooooo-create Mar 20, 2026

Choose a reason for hiding this comment

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

是的,里面的 nn.functional.* 现在都没有 docstring

@SigureMo SigureMo changed the title fix missing docstring for some nn.functional apis [Dosc] Add missing docstring for some nn.functional apis Mar 20, 2026
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@             Coverage Diff             @@
##             develop    #78405   +/-   ##
===========================================
  Coverage           ?   100.00%           
===========================================
  Files              ?         1           
  Lines              ?         1           
  Branches           ?         0           
===========================================
  Hits               ?         1           
  Misses             ?         0           
  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.

@SigureMo SigureMo merged commit 0a8dc07 into PaddlePaddle:develop Mar 21, 2026
107 of 112 checks passed
@ooooo-create ooooo-create added the HappyOpenSource 快乐开源活动issue与PR label Apr 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers HappyOpenSource 快乐开源活动issue与PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants