pytorch/torch/utils/tensorboard
Sergii Dymchenko f51f6aa387 Fix non-existing parameters in docstrings (#90505)
Continuation after https://github.com/pytorch/pytorch/pull/90163.

Here is a script I used to find all the non-existing arguments in the docstrings (the script can give false positives in presence of *args/**kwargs or decorators):

_Edit:_
I've realized that the indentation is wrong for the last `break` in the script, so the script only gives output for a function if the first docstring argument is wrong. I'll create a separate PR if I find more issues with corrected script.

``` python
import ast
import os
import docstring_parser

for root, dirs, files in os.walk('.'):
    for name in files:
        if root.startswith("./.git/") or root.startswith("./third_party/"):
            continue
        if name.endswith(".py"):
            full_name = os.path.join(root, name)
            with open(full_name, "r") as source:
                tree = ast.parse(source.read())
                for node in ast.walk(tree):
                    if isinstance(node, ast.FunctionDef):
                        all_node_args = node.args.args
                        if node.args.vararg is not None:
                            all_node_args.append(node.args.vararg)
                        if node.args.kwarg is not None:
                            all_node_args.append(node.args.kwarg)
                        if node.args.posonlyargs is not None:
                            all_node_args.extend(node.args.posonlyargs)
                        if node.args.kwonlyargs is not None:
                            all_node_args.extend(node.args.kwonlyargs)
                        args = [a.arg for a in all_node_args]
                        docstring = docstring_parser.parse(ast.get_docstring(node))
                        doc_args = [a.arg_name for a in docstring.params]
                        clean_doc_args = []
                        for a in doc_args:
                            clean_a = ""
                            for c in a.split()[0]:
                                if c.isalnum() or c == '_':
                                    clean_a += c
                            if clean_a:
                                clean_doc_args.append(clean_a)
                        doc_args = clean_doc_args
                        for a in doc_args:
                            if a not in args:
                                print(full_name, node.lineno, args, doc_args)
                            break

```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/90505
Approved by: https://github.com/malfet, https://github.com/ZainRizvi
2022-12-09 21:43:09 +00:00
..
__init__.py black formatting for utils/tensorboard (#76396) 2022-04-28 00:21:58 +00:00
_caffe2_graph.py Fix docstring inconsistencies: string -> str, boolean -> bool (#82410) 2022-07-28 21:29:57 +00:00
_convert_np.py black formatting for utils/tensorboard (#76396) 2022-04-28 00:21:58 +00:00
_embedding.py Remove deprecated call to tf.io.gfile.get_filesystem (#89832) 2022-12-08 08:53:27 +00:00
_onnx_graph.py black formatting for utils/tensorboard (#76396) 2022-04-28 00:21:58 +00:00
_proto_graph.py black formatting for utils/tensorboard (#76396) 2022-04-28 00:21:58 +00:00
_pytorch_graph.py Fix use-dict-literal lint (#83718) 2022-08-24 00:26:46 +00:00
_utils.py Fix non-existing parameters in docstrings (#90505) 2022-12-09 21:43:09 +00:00
summary.py Avoid overflow in tensorboard image summary (#90423) 2022-12-08 08:31:52 +00:00
writer.py Remove deprecated call to tf.io.gfile.get_filesystem (#89832) 2022-12-08 08:53:27 +00:00