Skip to content

Commit

Permalink
fix: adding space in :meth: role with no link
Browse files Browse the repository at this point in the history
  • Loading branch information
weibullguy committed Jun 5, 2023
1 parent 38ac9fd commit de84bd2
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 6 deletions.
4 changes: 3 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# type: ignore
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
"""Configuration file for the Sphinx documentation builder."""

project = "docformatter"
copyright = "2022-2023, Steven Myint"
author = "Steven Myint"
release = "1.7.2-rc6"
release = "1.7.2-rc7"

# -- 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-rc6"
version = "1.7.2-rc7"
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-rc6"
__version__ = "1.7.2-rc7"
11 changes: 8 additions & 3 deletions src/docformatter/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,14 @@ def do_wrap_field_lists( # noqa: PLR0913
text,
field_idx,
_idx,
)
if len(f"{_field_name}{_field_body}") <= (wrap_length - len(indentation)):
lines.append(f"{indentation}{_field_name}{_field_body}")
).strip()

if len(f"{_field_name} {_field_body}") <= (wrap_length - len(indentation)):
if _field_body.startswith("`!"):
_field = f"{_field_name}{_field_body}"
else:
_field = f"{_field_name} {_field_body}"
lines.append(f"{indentation}{_field}")
else:
lines.extend(
_do_wrap_field(_field_name, _field_body, indentation, wrap_length)
Expand Down
49 changes: 49 additions & 0 deletions tests/test_format_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -2078,6 +2078,55 @@ def test_format_docstring_sphinx_style_field_name_included_wrap_length(
)
)

@pytest.mark.unit
@pytest.mark.parametrize(
"args",
[
[
"--wrap-descriptions",
"88",
"--wrap-summaries",
"88",
"",
]
],
)
def test_format_docstring_sphinx_style_field_body_not_a_link(
self,
test_args,
args,
):
"""Should not add a space after the field name when the body is not a link.
See issue #229.
"""
uut = Formatter(
test_args,
sys.stderr,
sys.stdin,
sys.stdout,
)

assert (
(
'''\
"""CC.
:meth:`!X`
"""\
'''
)
== uut._do_format_docstring(
INDENTATION,
'''\
"""CC.
:meth:`!X`
"""\
''',
)
)


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

0 comments on commit de84bd2

Please sign in to comment.