Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Contributors
* Szymon Karpinski -- intersphinx improvements
* \T. Powers -- HTML output improvements
* Taku Shimizu -- epub3 builder
* Tamika Nomara -- bug fixes
* Thomas Lamb -- linkcheck builder
* Thomas Waldmann -- apidoc module fixes
* Till Hoffmann -- doctest option to exit after first failed test
Expand Down
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ Bugs fixed
Patch by Jeremy Maitin-Shepard.
* #13939: LaTeX: page break can separate admonition title from contents.
Patch by Jean-François B.
* #14004: Fix :confval:`autodoc_type_aliases` when they appear in PEP 604
union syntax (``Alias | Type``).
Patch by Tamika Nomara.


Testing
Expand Down
8 changes: 8 additions & 0 deletions sphinx/util/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,14 @@ def __hash__(self) -> int:
def __repr__(self) -> str:
return f'{self.__class__.__name__}({self.name!r})'

def __or__(self, other: Any) -> Any:
# When evaluating type hints, our forward ref can appear in type expressions,
# i.e. `Alias | None`. This means it needs to support ``__or__`` and ``__ror__``.
return typing.Union[self, other] # NoQA: UP007

def __ror__(self, other: Any) -> Any:
return typing.Union[other, self] # NoQA: UP007


class TypeAliasModule:
"""Pseudo module class for :confval:`autodoc_type_aliases`."""
Expand Down
8 changes: 8 additions & 0 deletions tests/test_util/test_util_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ def test_TypeAliasForwardRef():
sig_str = stringify_annotation(alias, 'fully-qualified-except-typing')
assert sig_str == "TypeAliasForwardRef('example') | None"

alias = alias | None
sig_str = stringify_annotation(alias, 'fully-qualified-except-typing')
assert sig_str == "TypeAliasForwardRef('example') | None"

alias = None | alias # NoQA: RUF036
sig_str = stringify_annotation(alias, 'fully-qualified-except-typing')
assert sig_str == "None | TypeAliasForwardRef('example')"


def test_TypeAliasNamespace() -> None:
import logging.config
Expand Down
Loading