Skip to content
Open
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
2 changes: 1 addition & 1 deletion sphinx/ext/autodoc/_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def _get_docstring_lines(
return []
return [prepare_docstring(docstring, tab_width)]

if props.obj_type == 'attribute':
if props.obj_type in {'attribute', 'type'}:
# Check the attribute has a docstring-comment
comment = _get_attribute_comment(
parent=parent, obj_path=props.parts, attrname=props.parts[-1]
Expand Down
2 changes: 2 additions & 0 deletions tests/roots/test-ext-autodoc/target/pep695.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Foo:
type Pep695Alias = Foo
"""This is PEP695 type alias."""

type Pep695AliasUndoced = Foo

TypeAliasTypeExplicit = TypeAliasType('TypeAliasTypeExplicit', Foo) # NoQA: UP040
"""This is an explicitly constructed typing.TypeAlias."""

Expand Down
6 changes: 6 additions & 0 deletions tests/test_ext_autodoc/test_ext_autodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2292,6 +2292,12 @@ def test_autodoc_pep695_type_alias() -> None:
' This is PEP695 type alias of PEP695 alias.',
'',
'',
# Undocumented alias should not inherit any documentations
'.. py:type:: Pep695AliasUndoced',
' :module: target.pep695',
' :canonical: ~target.pep695.Foo',
'',
'',
'.. py:type:: Pep695AliasUnion',
' :module: target.pep695',
' :canonical: str | int',
Expand Down
Loading