Skip to content

Commit 19c14f0

Browse files
authored
fix: not recognizing yield as a sphinx field name (#254)
* fix: not recognizing as sphinx field name * test: for recognizing as sphinx field name
1 parent 5c9744e commit 19c14f0

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

src/docformatter/syntax.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
REST_REGEX = r"((\.{2}|`{2}) ?[\w.~-]+(:{2}|`{2})?[\w ]*?|`[\w.~]+`)"
6060
"""Regular expression to use for finding reST directives."""
6161

62-
SPHINX_REGEX = r":(param|raises|return|rtype|type)[a-zA-Z0-9_\-.() ]*:"
62+
SPHINX_REGEX = r":(param|raises|return|rtype|type|yield)[a-zA-Z0-9_\-.() ]*:"
6363
"""Regular expression to use for finding Sphinx-style field lists."""
6464

6565
URL_PATTERNS = (

tests/_data/string_files/format_sphinx.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,17 @@ outstring='''"""CC.
236236
237237
c c :math:`[0, 1]`.
238238
"""'''
239+
240+
[issue_253]
241+
instring='''"""
242+
My test fixture.
243+
244+
:param caplog: Pytest caplog fixture.
245+
:yield: Until test complete, then run cleanup.
246+
"""'''
247+
outstring='''"""
248+
My test fixture.
249+
250+
:param caplog: Pytest caplog fixture.
251+
:yield: Until test complete, then run cleanup.
252+
"""'''

tests/formatter/test_format_sphinx.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,3 +433,42 @@ def test_format_docstring_sphinx_style_ignore_directive(
433433
INDENTATION,
434434
instring,
435435
)
436+
437+
@pytest.mark.unit
438+
@pytest.mark.parametrize(
439+
"args",
440+
[
441+
[
442+
"--wrap-descriptions",
443+
"120",
444+
"--wrap-summaries",
445+
"120",
446+
"--pre-summary-newline",
447+
"--black",
448+
"",
449+
]
450+
],
451+
)
452+
def test_format_docstring_sphinx_style_recognize_yield(
453+
self,
454+
test_args,
455+
args,
456+
):
457+
"""Should identify `yield` as sphinx field name.
458+
459+
See issue #253.
460+
"""
461+
uut = Formatter(
462+
test_args,
463+
sys.stderr,
464+
sys.stdin,
465+
sys.stdout,
466+
)
467+
468+
instring = self.TEST_STRINGS["issue_253"]["instring"]
469+
outstring = self.TEST_STRINGS["issue_253"]["outstring"]
470+
471+
assert outstring == uut._do_format_docstring(
472+
INDENTATION,
473+
instring,
474+
)

0 commit comments

Comments
 (0)