Skip to content

Commit

Permalink
fix: not recognizing yield as a sphinx field name (#254)
Browse files Browse the repository at this point in the history
* fix: not recognizing  as sphinx field name

* test: for recognizing  as sphinx field name
  • Loading branch information
weibullguy committed Jul 11, 2023
1 parent 5c9744e commit 19c14f0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/docformatter/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
REST_REGEX = r"((\.{2}|`{2}) ?[\w.~-]+(:{2}|`{2})?[\w ]*?|`[\w.~]+`)"
"""Regular expression to use for finding reST directives."""

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

URL_PATTERNS = (
Expand Down
14 changes: 14 additions & 0 deletions tests/_data/string_files/format_sphinx.toml
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,17 @@ outstring='''"""CC.
c c :math:`[0, 1]`.
"""'''

[issue_253]
instring='''"""
My test fixture.
:param caplog: Pytest caplog fixture.
:yield: Until test complete, then run cleanup.
"""'''
outstring='''"""
My test fixture.
:param caplog: Pytest caplog fixture.
:yield: Until test complete, then run cleanup.
"""'''
39 changes: 39 additions & 0 deletions tests/formatter/test_format_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,42 @@ def test_format_docstring_sphinx_style_ignore_directive(
INDENTATION,
instring,
)

@pytest.mark.unit
@pytest.mark.parametrize(
"args",
[
[
"--wrap-descriptions",
"120",
"--wrap-summaries",
"120",
"--pre-summary-newline",
"--black",
"",
]
],
)
def test_format_docstring_sphinx_style_recognize_yield(
self,
test_args,
args,
):
"""Should identify `yield` as sphinx field name.
See issue #253.
"""
uut = Formatter(
test_args,
sys.stderr,
sys.stdin,
sys.stdout,
)

instring = self.TEST_STRINGS["issue_253"]["instring"]
outstring = self.TEST_STRINGS["issue_253"]["outstring"]

assert outstring == uut._do_format_docstring(
INDENTATION,
instring,
)

0 comments on commit 19c14f0

Please sign in to comment.