Skip to content

Commit 9289735

Browse files
committed
Handle weird return types safely in resolving (#159)
1 parent 8b570dc commit 9289735

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

docs/src/release_notes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ These release notes are based on
88
sphinx-codeautolink adheres to
99
`Semantic Versioning <https://semver.org>`_.
1010

11+
Unreleased
12+
----------
13+
- Fix regression in not handling malformed return types (:issue:`159`)
14+
1115
0.16.1 (2025-01-15)
1216
-------------------
1317
- Fix regression in not handling invalid return type hints (:issue:`158`)

src/sphinx_codeautolink/extension/resolve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def get_return_annotation(func: Callable) -> type | None:
120120
"""Determine the target of a function return type hint."""
121121
try:
122122
annotation = get_type_hints(func).get("return")
123-
except NameError as e:
123+
except (NameError, TypeError) as e:
124124
msg = f"Unable to follow return annotation of {get_name_for_debugging(func)}."
125125
raise CouldNotResolve(msg) from e
126126

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
numpy
2+
np.concatenate
3+
# split
4+
extensions = [
5+
"sphinx.ext.intersphinx",
6+
"sphinx_codeautolink",
7+
]
8+
intersphinx_mapping = {"numpy": ("https://numpy.org/doc/stable/", None)}
9+
codeautolink_warn_on_failed_resolve = False
10+
# split
11+
Test project
12+
============
13+
14+
.. code:: python
15+
16+
import numpy as np
17+
18+
np.concatenate().mean()

0 commit comments

Comments
 (0)