File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed
roots/test-ext-autodoc/target Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ def _prepare_docstrings(
8888) -> list [list [str ]] | None :
8989 """Add content from docstrings, attribute documentation and user."""
9090 # add content from attribute documentation
91- if props .obj_type not in {'data' , 'attribute' } and props .parts :
91+ if props .obj_type not in {'data' , 'attribute' , 'type' } and props .parts :
9292 key = ('.' .join (props .parent_names ), props .name )
9393 try :
9494 # make a copy of docstring for attributes to avoid cache
@@ -298,6 +298,20 @@ def _get_docstring_lines(
298298 return []
299299 return [prepare_docstring (docstring , tab_width )]
300300
301+ if props .obj_type == 'type' :
302+ try :
303+ analyzer = ModuleAnalyzer .for_module (props .module_name )
304+ analyzer .analyze ()
305+ except PycodeError :
306+ return None
307+
308+ key = ('' , props .name )
309+ if key in analyzer .attr_docs :
310+ if comment := list (analyzer .attr_docs [key ]):
311+ return [comment ]
312+
313+ return None
314+
301315 docstring = getdoc (
302316 obj ,
303317 allow_inherited = inherit_docstrings ,
Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ class Foo:
2222type Pep695Alias = Foo
2323"""This is PEP695 type alias."""
2424
25+ type Pep695AliasUndocumented = Foo
26+
2527TypeAliasTypeExplicit = TypeAliasType ('TypeAliasTypeExplicit' , Foo ) # NoQA: UP040
2628"""This is an explicitly constructed typing.TypeAlias."""
2729
Original file line number Diff line number Diff line change @@ -2292,6 +2292,12 @@ def test_autodoc_pep695_type_alias() -> None:
22922292 ' This is PEP695 type alias of PEP695 alias.' ,
22932293 '' ,
22942294 '' ,
2295+ # Undocumented alias should not inherit any documentation
2296+ '.. py:type:: Pep695AliasUndocumented' ,
2297+ ' :module: target.pep695' ,
2298+ ' :canonical: ~target.pep695.Foo' ,
2299+ '' ,
2300+ '' ,
22952301 '.. py:type:: Pep695AliasUnion' ,
22962302 ' :module: target.pep695' ,
22972303 ' :canonical: str | int' ,
You can’t perform that action at this time.
0 commit comments