Skip to content

Commit 8f6c624

Browse files
committed
Correctly handle True/False/None in doctools.make_sphinx_links
1 parent f219f3f commit 8f6c624

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

domdf_python_tools/doctools.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,14 @@ def make_sphinx_links(input_string: str, builtins_list: Optional[Sequence[str]]
147147

148148
working_string = f"{input_string}"
149149

150-
for builtin in {x for x in builtins_list if not x.startswith("__") and x != "None"}:
151-
working_string = working_string.replace(f"``{builtin}``", f":class:`{builtin}`")
150+
for builtin in builtins_list:
151+
if builtin.startswith("__"):
152+
continue
153+
154+
if builtin in {"None", "False", "None"}:
155+
working_string = working_string.replace(f"``{builtin}``", f":py:obj:`{builtin}`")
156+
else:
157+
working_string = working_string.replace(f"``{builtin}``", f":class:`{builtin}`")
152158

153159
return working_string
154160

tests/test_doctools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,15 @@ def test_still_callable():
318318
def test_make_sphinx_links():
319319

320320
original = """
321-
This is a docstring that contains references to ``str``, ``int``, and ``float``
321+
This is a docstring that contains references to ``str``, ``int``, ``float`` and ``None``,
322322
but lacks proper references to them when rendered in Sphinx.
323323
324324
:return: pi
325325
:rtype: float
326326
"""
327327

328328
sphinx = """
329-
This is a docstring that contains references to :class:`str`, :class:`int`, and :class:`float`
329+
This is a docstring that contains references to :class:`str`, :class:`int`, :class:`float` and :py:obj:`None`,
330330
but lacks proper references to them when rendered in Sphinx.
331331
332332
:return: pi

0 commit comments

Comments
 (0)