Autoattribute directive should check the existence of instance attribute
that is defined inside __init__() but not having comments before
accessing it.
The special members are not treated as "attributes". So they're not
handled by DataDocumenter. This moves the detection to the earlier
step of filter_members().
When multiple singledispatch decorators are stacked, the first typehints
are copied to the subsequent definitions unexpectedly.
Now autodoc generates a dummy function not to affect typehints to
subsequent functions.
Add new tests to exercise the new autodoc_typehint_undoc option. Where
an existing test would have a meaningful behavior change with the new
option set to False, that test is copied, the new option is set to False
in the copy, and the assertions reflect the new expected behavior.
The new test test_autodoc_typehints_description_with_documented_init
illustrates the problem reported in #7329, and the new test
test_autodoc_typehints_description_with_documented_init_no_undoc
illustrates that this issue no longer occurs when the new
autodoc_typehint_undoc option is set to False.
This generates `:canonical:` option for `:py:class:` directive if the
target class is imported from other module. It allows users to refer it
using both the new name (imported name) and the original name (canonical
name).
It helps a library that implements some class in private module (like
`_io.StringIO`), and publish it as public module (like `io.StringIO`).
Add a new extension `sphinx.ext.autodoc.preserve_defaults`.
It preserves the default argument values of function signatures in source code
and keep them not evaluated for readability. This is an experimental
extension and it will be integrated into autodoc core in Sphinx-4.0.
Unintentionally, uninitialized attributes defined at superclasses are
recognized as undocumented in the filtering step. Therefore, they are
filtered if `:undoc-members:` option given.
autodoc crashed when a decorator in mocked module takes arguments
because mock system returns the first argument for the decorator as a
decorated object.
This changes the approach for mocking decorators that remembers
arguments for each decoration, and fetch the latest argument on
generating document.
As a well-known idiom, mypy recommends to use ellipsis ("...") for
default argument values as a elided style. This allows to write the
style and helps to document it with copying the default argument
values from actual implementation.
Note: This does not copy the default argument value when the argument
of overloaded function has its own default value.
The default values for overloaded functions are rendered as string
literal unexpectedly because autodoc extracts code snippets from
the source code, not actual value (ex. int, ellipsis, and so on).
This introduces a simple wrapper class; `DefaultValue` to render these
code snippets like actual values, not string literals.
An empty `__all__` should be represented as "there is no public items".
But autodoc considers all items on the module are public. This changes
the behavior to correct one.
To control the visibility of variables, ModuleDocumenter have to load
docstring of them on `get_object_members()` phase. This reimplements
it and `get_module_members()` helper to fetch docstring on earlier
phase (as ClassDocumenter does).
autodata and autoattribute directives does not show right-hand value of
the variable if its docstring contains ``:meta hide-value:`` in
info-field-list.
Deprecate `no_docstring` argument for `Documenter.add_content()` again.
At the first trial (#8533), it changes the behavior of
`autodoc-process-docstring` event; it is emitted unexpectedly for an
alias of class. But it brings an incompatible change to extensions.
Hence it was partially reverted at #8581.
This keeps not calling the event for an alias of class. To do that,
now `Documenter.get_doc()` can return None value.
To support instance attributes on super class, get_class_members() scans
the instance attributes defined at super classes using ModuleAnalyzer.
It allows to generate document for them when users gives :
inherited-members: option.
To avoid filtering __slots__ attributes having docstring at
filter_members(), this passes docstring captured at get_class_members()
to the filter_members() via ObjectMember.
So far, autodoc obtains type annotations of instance attributes by
ModuleAnalyzer directly. As a result, autodoc_type_aliases are ignored
for these variables.
This goes to merge type annotations from the class itself and
ModuleAnalyzer's, and get type annotations using `typing.get_type_hints()`
to apply autodoc_type_aliases.
So far, autoattribute uses "given class name" to fetch comments of
uninitialized instance attributes. But pycode expects to use "real"
class name on searching attribute comments.
This adds UninitializedInstanceAttributeMixin to handle it simply.
A custom type defined by typing.NewType was rendered as a function
because the generated type is a function having special attributes.
This renders it as a variable.
Note: The module name where the NewType object defined is lost on
generating it. So it is hard to make cross-reference for these custom
types.
Keep imports alphabetically sorted and their order homogeneous across
Python source files.
The isort project has more feature and is more active than the
flake8-import-order plugin.
Most issues caught were simply import ordering from the same module.
Where imports were purposefully placed out of order, tag with
isort:skip.
Usually we use "Any" type for the type annotation which takes any kinds
of types, instead of "object" class. So this replaces "object" to "Any"
in our example.
In #7651, autodoc stops to undecorate the functions on getting the
signature from the callables. But some kinds of decorators conceals
the correct signature because they pass through their arguments via
`(*args, **kwargs)`.
This restarts to undecorate the functions again as before #7651.