Commit Graph

158 Commits

Author SHA1 Message Date
Takeshi KOMIYA
f2c0dfe7c4 Close #6518: autodoc: Add autodoc_type_aliases
autodoc_type_aliases allows to keep user defined type alises not
evaluated in the generated document.
2020-10-03 16:03:35 +09:00
Takeshi KOMIYA
ec06f5571e Merge pull request #8142 from jcarrano/typing-generic-signatures
autodoc: fix constructor signatures for classes derived from typing.Generic
2020-10-03 01:23:36 +09:00
Takeshi KOMIYA
dfbe687db6 Merge branch '3.x' into 8103_cached_property 2020-09-13 11:07:33 +09:00
Juan Carrano
642686159f autodoc: Test the signature of typing.Generic subclasses.
This test is currently failing because typing.Generic.__new__ clobbers the
real signature.
2020-08-21 18:47:14 +02:00
Takeshi KOMIYA
088b049170 Fix #8103: autodoc: cached_property is not considered as a property
sphinx.util.inspect:isproperty() does not considers that
cached_property decorator that has been added since Python 3.8 is
a kind of properties.  This fixes it.
2020-08-13 23:16:59 +09:00
Takeshi KOMIYA
611fff975e Fix #8099: autodoc: NameError is raised when script uses TYPE_CHECKING
`typing.get_type_hints()` raises NameError when the target object
contains unresolavable type annotation (ex. TYPE_CHECKING).  This
handles the exception and use unresolved annotations for type hints.
2020-08-13 22:57:12 +09:00
Takeshi KOMIYA
88b2ec6c34 Fix #8041: autodoc: An ivar on super class is not shown unexpectedly
An annotated instance variable on super class is not documented when
derived class has also other annotated instance variables because
`obj.__annotations__` is overrided by derived class's type hints.

To get annotations of the target class correctly, this scans MRO to
get all of annotated instance variables.
2020-08-08 00:21:29 +09:00
Takeshi KOMIYA
c0157cf074 refactor: test: Rename target.enum to target.enums
Using "enum" for module name bothers me on debugging errors because
it sometimes raises ImportError.
2020-08-03 02:30:30 +09:00
Takeshi KOMIYA
5d301b44b9 Fix #8032: autodoc: A typehint for inherited ivars is not shown
This tries to import the parent object for the instance attribute
to get type annotations for the variable.
2020-08-02 18:27:03 +09:00
Takeshi KOMIYA
488a173904 Fix #1362: autodoc: Support private class attributes
So far, autodoc treats a "private" class attribute as a mere attribute.
But its name is mangled by python interpreter. This make it unmangled
name to be documented expectedly.
2020-07-18 03:39:38 +09:00
Takeshi KOMIYA
916cd4c844 Fix #7901: autodoc: annotations for overloaded functions are not resolved
So far, type annotations for overloaded functions are not resolved
because they are obtained from AST directly.  This tries to evaluate
them using a context of its function or method.
2020-07-11 12:49:24 +09:00
Takeshi KOMIYA
659846b805 Fix #7812: autodoc: crashed when given name is conflicted
Note: this partially reverts #7594 to avoid errors.
2020-07-04 20:48:02 +09:00
Takeshi KOMIYA
d77622ba79 Fix #7807: autodoc: wrong signature is shown for the function using contextmanager 2020-06-14 01:31:18 +09:00
Takeshi KOMIYA
8bd5f8b214 autodoc: Support TypeVar (refs: #7722) 2020-06-06 12:45:20 +09:00
Takeshi KOMIYA
49de4ab1a1 Support overloaded constructors (__call__, __init__ and __new__) 2020-06-02 00:44:07 +09:00
Takeshi KOMIYA
fb2f777079 Close #3610: autodoc: Support overloaded functions 2020-05-31 23:59:32 +09:00
Takeshi KOMIYA
3c5a9442c2 Merge branch '3.x' into 4422_support_GenericAlias 2020-05-31 14:49:13 +09:00
Takeshi KOMIYA
e20f29e325 Add sphinx.util.inspect:isgenericalias() 2020-05-30 21:06:54 +09:00
Takeshi KOMIYA
800dcf0f0a Close #2106: autodoc: Support multiple signatures on docstring 2020-05-30 15:40:21 +09:00
Eric Wieser
d229b120ad Fix autoclass signature parsing
This fixes:
* Signatures defined by __new__
* Signatures defined by metaclasses
* Signatures defined by builtin base classes

All of these changes bring the sphinx docs inline with the behavior of `inspect.signature`.

Note that this changes autodoc to output `.. py:class: MyClass()` with parentheses even if no user-defined __init__ is present.
This is quite deliberate, as if no user-defined `__init__` is present the default is `object.__init__`, which indeed does not take arguments.
2020-05-28 08:36:56 +01:00
Takeshi KOMIYA
a5e3b4a43d Fix #3673: autodoc: bysource order does not work for a module having __all__ 2020-05-23 21:52:11 +09:00
Takeshi KOMIYA
3a81ffa79a Fix #7650: autodoc: undecorated signature is shown for decorated functions 2020-05-11 01:11:12 +09:00
Kjell Braden
db72c18cf9 add testcase for complex typehintsext.autodoc.typehints 2020-05-10 20:46:29 +09:00
Takeshi KOMIYA
24fe05f14f refactor: autodoc: class processors on autofunction is no longer needed 2020-05-07 01:55:33 +09:00
Takeshi KOMIYA
54bb1f3e62 refactor: test: Pass language_level to cython explicitly 2020-05-04 00:23:06 +09:00
Takeshi KOMIYA
9256daaa77 Merge branch '3.x' into 6857_enum_classmethod 2020-05-02 01:48:01 +09:00
Takeshi KOMIYA
25fc47e6b7 Fix #7559: autodoc: misdetects a sync function is async 2020-05-01 22:05:45 +09:00
Takeshi KOMIYA
d612ef8f0b Fix #6857: autodoc: failed to detect a classmethod on Enum class 2020-04-30 22:54:49 +09:00
Takeshi KOMIYA
767864b0f1 Close #7143: autodoc: Support final classes and methods 2020-04-28 01:24:41 +09:00
Takeshi KOMIYA
7888600f96 Merge pull request #7564 from eric-wieser/fix-missing-__annotations__
autodoc: Fix a logic error that causes annotations not to be shown for descriptors
2020-04-27 21:54:17 +09:00
Eric Wieser
b7ce4a4c13 Fix a logic error that causes annotations not to be shown for descriptors
This `if not self._datadescriptor` was originally here before type annotations were supported, to prevent showing `descr4 = <_Descriptor ...>` in the docs.

When type annotations were added, the support for appending `:type:` was put in the wrong place.
It should have been outside this if, not within it.
2020-04-27 12:57:39 +01:00
Takeshi KOMIYA
c9e4945623 Merge pull request #7473 from eric-wieser/meta-public
Add support for :meta public:
2020-04-23 02:15:42 +09:00
Takeshi KOMIYA
ffb1ca3aaa test: Add a docstring to avoid an error on py39a5+ 2020-04-18 20:28:31 +09:00
Eric Wieser
0d7451c23d Add support for :meta public:
A common use case for this is a class like `namedtuple`, which has a public `_replace` method that is so-named in order not to conflict with arbitrary user-provided attributes.

Rejected spellings include:
* `:meta not-private:`
* `:meta private: False`
2020-04-14 08:41:45 +01:00
Takeshi KOMIYA
231d75b0d0 Merge branch '2.x' into 3.0.x 2020-04-05 23:03:35 +09:00
Takeshi KOMIYA
360efdefec Fix #7355: autodoc: a signature of cython-function is not recognized well 2020-03-31 21:14:08 +09:00
Takeshi KOMIYA
dd70d9faac Fix #7331: autodoc: a cython-method is not recognized as a method 2020-03-22 23:13:49 +09:00
Takeshi KOMIYA
5c396b6325 Fix #7331: autodoc: a cython-function is not recognized as a function 2020-03-22 23:13:49 +09:00
Antony Lee
f9048cf18e Handle singledispatch functions with rewritten signatures.
If a singledispatch function has its `__signature__` rewritten, autodoc
fails to annotate that signature because `func.__annotations__` is not
consulted.  Instead, directly assign to `__signature__` instead.
2020-03-14 22:52:45 +01:00
Takeshi KOMIYA
8f7cc26b20 autodoc: Support singledispatch methods 2020-03-07 17:50:10 +09:00
Takeshi KOMIYA
961b4d1545 Close #2815: autodoc: Support singledispatch functions 2020-03-07 17:50:10 +09:00
Takeshi KOMIYA
34057601f4 Close #7165: autodoc: Support Annotated type (PEP-593) 2020-03-03 00:14:24 +09:00
Terence D. Honles
90de551d4c Fix: autodoc: __wrapped__ functions are not documented correctly
Functions that are decorated with `@lru_cache` or other `functools`
decorators may not even be detected as a function. This results in the
documentation not having the `()` or even trying to render the function
signature.

This change updates the `sphinx.util.inspect` code to unwrap
`__wrapped__` functions before determining if they can be documented.

`@lru_cache` and its associated test is an example of a decorated
function that is incorrectly identified as an attribute rather than a
module level function and when rendering the signature (upon changing
`isattributedescriptor`) the decorated function is still incorrectly
identified as a C function.

This change also renames the newly introduced `unwrap` as `unwrap_all`
because it is different than the prexisting Python supplied
`inspect.unwrap`.

See `update_wrapper` "Changed in version 3.4" for more background:
https://docs.python.org/3/library/functools.html#functools.update_wrapper
2020-02-27 16:27:41 -08:00
Takeshi KOMIYA
754d04f80d Merge branch '2.4.x' into 3.x 2020-02-22 19:22:31 +09:00
Takeshi KOMIYA
2fec37219f Fix #7189: autodoc: classmethod coroutines are not detected 2020-02-22 00:49:45 +09:00
Takeshi KOMIYA
954db2bd27 Merge branch '2.0' 2020-02-16 21:42:20 +09:00
Takeshi KOMIYA
b80c7cd234 Merge pull request #7152 from gpotter2/elipsispatch
Fix #7146: support (...) in type hint comments (V2)
2020-02-16 20:35:40 +09:00
Takeshi KOMIYA
cd8f3a78d9 Fix #7156: autodoc: separator for keyword only arguments is not shown 2020-02-16 01:37:23 +09:00
gpotter2
51b80ab121 Fix #7146 2020-02-14 16:12:12 +00:00
Takeshi KOMIYA
c5f0025ed9 Merge branch 'master' into 5637 2020-02-12 01:42:05 +09:00