Skip to content

Commit e5129d9

Browse files
committed
pylint fixes
1 parent 9b333eb commit e5129d9

File tree

9 files changed

+213
-79
lines changed

9 files changed

+213
-79
lines changed

PyDocSmith/common.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"attribute",
1111
"key",
1212
"keyword",
13-
"note"
13+
"note",
1414
}
1515
RAISES_KEYWORDS = {"raises", "raise", "except", "exception"}
1616
DEPRECATION_KEYWORDS = {"deprecation", "deprecated"}
@@ -149,6 +149,7 @@ def __init__(
149149
self.snippet = snippet
150150
self.description = description
151151

152+
152153
class DocstringNote(DocstringMeta):
153154
"""DocstringNote symbolizing example metadata."""
154155

@@ -163,6 +164,7 @@ def __init__(
163164
self.snippet = snippet
164165
self.description = description
165166

167+
166168
class Docstring:
167169
"""Docstring object representation."""
168170

@@ -224,10 +226,8 @@ def examples(self) -> T.List[DocstringExample]:
224226
return [
225227
item for item in self.meta if isinstance(item, DocstringExample)
226228
]
227-
229+
228230
@property
229231
def notes(self) -> T.List[DocstringNote]:
230232
"""Return a list of information on function notes."""
231-
return [
232-
item for item in self.meta if isinstance(item, DocstringNote)
233-
]
233+
return [item for item in self.meta if isinstance(item, DocstringNote)]

PyDocSmith/epydoc.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
DocstringParam,
1313
DocstringRaises,
1414
DocstringReturns,
15-
DocstringExample,
16-
DocstringNote,
1715
DocstringStyle,
1816
ParseError,
1917
RenderingStyle,

PyDocSmith/google.py

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
YIELDS_KEYWORDS,
1616
Docstring,
1717
DocstringExample,
18-
DocstringNote,
1918
DocstringMeta,
19+
DocstringNote,
2020
DocstringParam,
2121
DocstringRaises,
2222
DocstringReturns,
@@ -105,27 +105,33 @@ def _build_meta(self, text: str, title: str) -> DocstringMeta:
105105
"""
106106

107107
section = self.sections[title]
108-
pattern = r'^[\*_a-zA-Z\d]'
108+
pattern = r"^[\*_a-zA-Z\d]"
109109
if text.strip() == "":
110-
return
110+
return None
111111

112112
if (
113113
section.type == SectionType.SINGULAR_OR_MULTIPLE
114114
and not MULTIPLE_PATTERN.match(text)
115115
) or section.type == SectionType.SINGULAR:
116-
text = re.sub(r'^-\s', '', text)
117-
#to validate if the text starts with a valid character in the function signature
116+
text = re.sub(r"^-\s", "", text)
117+
# to validate if the text starts with
118+
# a valid character in the function signature
118119
valid_start_text_for_param = re.match(pattern, text)
119120

120-
#TODO: make better comparison for Examples
121+
# TODO: make better comparison for Examples
121122
if not valid_start_text_for_param:
122-
ignore_for_these_type = ["Example", "Examples", "Note", "Notes", "Returns", "Yields"]
123+
ignore_for_these_type = [
124+
"Example",
125+
"Examples",
126+
"Note",
127+
"Notes",
128+
]
123129
if not section.title in ignore_for_these_type:
124-
return
130+
return None
125131
return self._build_single_meta(section, text)
126132

127133
if ":" not in text:
128-
return
134+
return None
129135

130136
# Split spec and description
131137
before, desc = text.split(":", 1)
@@ -135,17 +141,17 @@ def _build_meta(self, text: str, title: str) -> DocstringMeta:
135141
first_line, rest = desc.split("\n", 1)
136142
desc = first_line + "\n" + inspect.cleandoc(rest)
137143
desc = desc.strip("\n")
138-
139-
before = re.sub(r'^-\s', '', before)
140-
144+
145+
before = re.sub(r"^-\s", "", before)
146+
141147
valid_start_text_for_param = re.match(pattern, before)
142148
if before and not valid_start_text_for_param:
143-
return
144-
145-
desc = re.sub(r'^-\s', '', desc)
149+
return None
150+
151+
desc = re.sub(r"^-\s", "", desc)
146152
valid_start_text_for_param = re.match(pattern, before)
147153
if desc and not valid_start_text_for_param:
148-
return
154+
return None
149155
return self._build_multi_meta(section, before, desc)
150156

151157
@staticmethod
@@ -276,7 +282,7 @@ def parse(self, text: str) -> Docstring:
276282
# Clear Any Unknown Meta
277283
# Ref: https://github.com/SigularityX-ai/PyDocSmith/issues/29
278284
meta_details = meta_chunk[start:end]
279-
unknown_meta = re.search(r"\n\S", meta_details)
285+
# unknown_meta = re.search(r"\n\S", meta_details)
280286
# if unknown_meta is not None:
281287
# meta_details = meta_details[: unknown_meta.start()]
282288

@@ -309,7 +315,7 @@ def parse(self, text: str) -> Docstring:
309315
if not c_matches:
310316
ret.meta.append(self._build_meta(part, title))
311317
continue
312-
318+
313319
if not c_matches:
314320
raise ParseError(f'No specification for "{title}": "{chunk}"')
315321
c_splits = []
@@ -378,12 +384,15 @@ def process_one(
378384
[head] + one.description.splitlines()
379385
)
380386
parts.append(body)
381-
elif isinstance(one, DocstringReturns) and one.description and not one.type_name:
387+
elif (
388+
isinstance(one, DocstringReturns)
389+
and one.description
390+
and not one.type_name
391+
):
382392
(first, *rest) = one.description.splitlines()
383393
if rendering_style == RenderingStyle.COMPACT and first == "None":
384394
index_of_returns = parts.index("Returns:")
385395
parts.pop(index_of_returns)
386-
pass
387396
else:
388397
body = f"\n{indent}{indent}".join([head + first] + rest)
389398
parts.append(body)

PyDocSmith/numpydoc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
Docstring,
1414
DocstringDeprecated,
1515
DocstringExample,
16-
DocstringNote,
1716
DocstringMeta,
17+
DocstringNote,
1818
DocstringParam,
1919
DocstringRaises,
2020
DocstringReturns,
@@ -263,6 +263,7 @@ def parse(self, text: str) -> T.Iterable[DocstringMeta]:
263263
description="\n".join(description_lines),
264264
)
265265

266+
266267
class NotesSection(Section):
267268
"""Parser for numpydoc notes sections.
268269

PyDocSmith/parser.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
DocstringStyle.EPYDOC: epydoc,
2020
}
2121

22+
2223
def detect_docstring_style(docstring) -> DocstringStyle:
2324
"""
2425
Attempt to detect the docstring style based on simple heuristics.
@@ -27,15 +28,20 @@ def detect_docstring_style(docstring) -> DocstringStyle:
2728
docstring (str): The docstring to analyze.
2829
2930
Returns:
30-
str: The detected style ('REST', 'GOOGLE', 'NUMPYDOC', 'EPYDOC', or 'UNKNOWN').
31+
str: The detected style ('REST', 'GOOGLE',
32+
'NUMPYDOC', 'EPYDOC', or 'UNKNOWN').
3133
"""
3234
if "@param" in docstring or "@return" in docstring:
3335
return DocstringStyle.EPYDOC
34-
elif ":param:" in docstring or ":return:" in docstring or ":returns:" in docstring:
36+
if (
37+
":param:" in docstring
38+
or ":return:" in docstring
39+
or ":returns:" in docstring
40+
):
3541
return DocstringStyle.REST
36-
elif "Args:" in docstring or "Returns:" in docstring:
42+
if "Args:" in docstring or "Returns:" in docstring:
3743
return DocstringStyle.GOOGLE
38-
elif "Parameters" in docstring or "Returns" in docstring:
44+
if "Parameters" in docstring or "Returns" in docstring:
3945
return DocstringStyle.NUMPYDOC
4046
return None
4147

@@ -49,14 +55,14 @@ def parse(text: str, style: DocstringStyle = DocstringStyle.AUTO) -> Docstring:
4955
"""
5056
if style != DocstringStyle.AUTO:
5157
return _STYLE_MAP[style].parse(text)
52-
58+
5359
doc_string_style = detect_docstring_style(text)
5460

5561
if doc_string_style is not None:
5662
try:
5763
return _STYLE_MAP[doc_string_style].parse(text)
58-
except ParseError:
59-
raise ParseError(f"Failed to parse docstring with style {doc_string_style}")
64+
except ParseError as ex:
65+
raise ex
6066

6167
exc: T.Optional[Exception] = None
6268
rets = []

0 commit comments

Comments
 (0)