Skip to content

Commit

Permalink
fix: sphinx style wrapping fields with parentheses
Browse files Browse the repository at this point in the history
  • Loading branch information
weibullguy committed Jun 6, 2023
1 parent de84bd2 commit e782ecf
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
project = "docformatter"
copyright = "2022-2023, Steven Myint"
author = "Steven Myint"
release = "1.7.2-rc7"
release = "1.7.2-rc8"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "docformatter"
version = "1.7.2-rc7"
version = "1.7.2-rc8"
description = "Formats docstrings to follow PEP 257"
authors = ["Steven Myint"]
maintainers = [
Expand Down
2 changes: 1 addition & 1 deletion src/docformatter/__pkginfo__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
# SOFTWARE.
"""Package information for docformatter."""

__version__ = "1.7.2-rc7"
__version__ = "1.7.2-rc8"
4 changes: 2 additions & 2 deletions src/docformatter/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
REST_REGEX = r"((\.{2}|`{2}) ?[\w.~-]+(:{2}|`{2})?[\w ]*?|`[\w.~]+`)"
"""Regular expression to use for finding reST directives."""

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

URL_PATTERNS = (
Expand Down Expand Up @@ -482,7 +482,7 @@ def do_wrap_field_lists( # noqa: PLR0913
).strip()

if len(f"{_field_name} {_field_body}") <= (wrap_length - len(indentation)):
if _field_body.startswith("`!"):
if _field_body.startswith("`"):
_field = f"{_field_name}{_field_body}"
else:
_field = f"{_field_name} {_field_body}"
Expand Down
49 changes: 47 additions & 2 deletions tests/test_format_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -1796,7 +1796,7 @@ def test_format_docstring_sphinx_style(
):
"""Wrap sphinx style parameter lists.
See requirement docformatter_10.4.2
See requirement docformatter_10.4.2 and issue #230.
"""
uut = Formatter(
test_args,
Expand Down Expand Up @@ -1844,6 +1844,31 @@ def test_format_docstring_sphinx_style(
)
)

# Issue #230 required adding parenthesis to the SPHINX_REGEX.
assert (
(
'''\
"""CC.
:math:`-`
:param d: blabla
:param list(str) l: more blabla.
"""\
'''
)
== uut._do_format_docstring(
INDENTATION,
'''\
"""CC.
:math:`-`
:param d: blabla
:param list(str) l: more blabla.
"""\
''',
)
)

@pytest.mark.unit
@pytest.mark.parametrize(
"args",
Expand Down Expand Up @@ -2098,7 +2123,7 @@ def test_format_docstring_sphinx_style_field_body_not_a_link(
):
"""Should not add a space after the field name when the body is not a link.
See issue #229.
See issue #229 and issue #230.
"""
uut = Formatter(
test_args,
Expand Down Expand Up @@ -2127,6 +2152,26 @@ def test_format_docstring_sphinx_style_field_body_not_a_link(
)
)

assert (
(
'''\
"""CC.
:math:`-`
"""\
'''
)
== uut._do_format_docstring(
INDENTATION,
'''\
"""CC.
:math: `-`
"""\
''',
)
)


class TestFormatStyleOptions:
"""Class for testing format_docstring() when requesting style options."""
Expand Down

0 comments on commit e782ecf

Please sign in to comment.