[Dosc] Add missing docstring for some nn.functional apis#78405
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
There was a problem hiding this comment.
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_signatureto also patch matching symbols underpaddle.nn.functional. - Add an
Examplesblock to theallclosedocstring 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 | |||
There was a problem hiding this comment.
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.
| 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. |
| if inspect.isfunction(func): | ||
| func.__doc__ = docstr | ||
| elif inspect.ismethod(func): | ||
| func.__self__.__doc__ = docstr |
There was a problem hiding this comment.
第一次看这代码,给 __self__ 塞 __doc__ 是什么语义?
There was a problem hiding this comment.
是 func.__func__ 吧?可以单独提个 PR 看看效果
There was a problem hiding this comment.
刚刚试了一下不能直接修改属性
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 对象不能被直接修改属性
| """ | ||
| 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]: |
There was a problem hiding this comment.
是不是在 paddle/phi/ops/yaml/python_api_info.yaml 里的都有可能有这个问题?
There was a problem hiding this comment.
是的,里面的 nn.functional.* 现在都没有 docstring
nn.functional apis
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
PR Category
User Experience
PR Types
Docs
Description
fix missing docstring for nn.functional apis
find in PaddlePaddle/docs#7873 (review)
是否引起精度变化
否