Skip to content

Commit f8830f9

Browse files
sethahsoumith
authored andcommitted
use regex in kwarg parser (#8061)
1 parent 9fc0ba3 commit f8830f9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

torch/_torch_docs.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Adds docstrings to functions defined in the torch._C"""
22

3+
import re
4+
35
import torch._C
46
from torch._C import _add_docstr as add_docstr
57

@@ -14,8 +16,9 @@ def parse_kwargs(desc):
1416
'weight (Tensor): a weight tensor\n Some optional description'
1517
}
1618
"""
17-
# Split by indents. Assumes each arg starts on a new line with 4 spaces.
18-
kwargs = [section.strip() for section in desc.split('\n ')]
19+
# Split on exactly 4 spaces after a newline
20+
regx = re.compile("\n\s{4}(?!\s)")
21+
kwargs = [section.strip() for section in regx.split(desc)]
1922
kwargs = [section for section in kwargs if len(section) > 0]
2023
return {desc.split(' ')[0]: desc for desc in kwargs}
2124

0 commit comments

Comments
 (0)