You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
If automodule is applied to a module which defines a documented complex type alias, the type annotations on all attributes later in the module will be ignored.
To Reproduce
Apply automodule to a module like the following:
import typing
Alias = typing.Union[int, float]
"""a type alias"""
class Foo:
"""blah"""
bar: object
"""an attribute"""
The generated documentation will not list any type for the attribute bar. Removing the definition of Alias causes the type of bar to be correctly rendered.
Expected behavior
The presence of a type alias definition should not affect the display of type information for unrelated members.
Your project
Here is a tiny example project: example3.zip
Environment info
OS: macOS 10.14.6
Python version: 3.8.0
Sphinx version: 3.2.1 (also reproduced on the current 3.x branch)
Sphinx extensions: sphinx.ext.autodoc
Additional context
The reason for the bug is that autodoc.GenericAliasDocumenter.add_directive_header and autodoc.TypeVarDocumenter.add_directive_header use the line self.options.annotation = SUPPRESS to suppress the printing of the usual type information. Unfortunately, the self.options object can be shared across multiple documenters created as part of the same automodule directive, so mutating the options for one documenter affects all the others. One way to fix this is to change autodoc.Documenter.__init__ to make a copy of the Options object, using the line self.options = Options(directive.genopt). Making this change causes the bug described above to disappear.
Thanks to @altendky for helping me debug this problem.
The text was updated successfully, but these errors were encountered:
The annotation option is shared between auto directives unexpectedly.
It causes supression of type annotations for objects after
GenericAlias definition.
Describe the bug
If
automodule
is applied to a module which defines a documented complex type alias, the type annotations on all attributes later in the module will be ignored.To Reproduce
Apply
automodule
to a module like the following:The generated documentation will not list any type for the attribute
bar
. Removing the definition ofAlias
causes the type ofbar
to be correctly rendered.Expected behavior
The presence of a type alias definition should not affect the display of type information for unrelated members.
Your project
Here is a tiny example project: example3.zip
Environment info
sphinx.ext.autodoc
Additional context
The reason for the bug is that
autodoc.GenericAliasDocumenter.add_directive_header
andautodoc.TypeVarDocumenter.add_directive_header
use the lineself.options.annotation = SUPPRESS
to suppress the printing of the usual type information. Unfortunately, theself.options
object can be shared across multiple documenters created as part of the sameautomodule
directive, so mutating the options for one documenter affects all the others. One way to fix this is to changeautodoc.Documenter.__init__
to make a copy of theOptions
object, using the lineself.options = Options(directive.genopt)
. Making this change causes the bug described above to disappear.Thanks to @altendky for helping me debug this problem.
The text was updated successfully, but these errors were encountered: