Commit Graph

136 Commits

Author SHA1 Message Date
pbudzyns
7348ba8d60 add more extendable options and tests 2021-01-25 13:15:13 +01:00
pbudzyns
0a85b4148e add more extendable options and tests 2021-01-25 12:54:08 +01:00
Takeshi KOMIYA
5ce72f465b Merge branch '3.x' 2021-01-22 22:52:32 +09:00
Takeshi KOMIYA
d88166e84b Close #8514: autodoc: Default values of overloads are taken from actual implementation
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.
2021-01-17 02:32:50 +09:00
Takeshi KOMIYA
425cd1af02 Fix #8693: autodoc: Default values for overloads are rendered as string
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.
2021-01-17 02:30:20 +09:00
Takeshi KOMIYA
4b452338f9 Merge branch '3.x' 2021-01-01 13:57:19 +09:00
Takeshi KOMIYA
7ecf6b88aa Merge branch '3.4.x' into 3.x 2021-01-01 13:56:19 +09:00
Takeshi KOMIYA
f996859420 A happy new year!
.. note::

   $ find sphinx tests LICENSE doc/conf.py -type f -exec sed -i '' -e 's/2007\-20../2007-2021/' {} \;
   $ git co sphinx/locale/**/*.js sphinx/templates/epub3/mimetype
2021-01-01 13:40:48 +09:00
Takeshi KOMIYA
a122397b4b Merge branch '3.x' 2020-12-29 18:37:45 +09:00
Takeshi KOMIYA
9e9e486e65 Close #8022: autodoc: Allow to hide the value of the variables via metadata
autodata and autoattribute directives does not show right-hand value of
the variable if its docstring contains ``:meta hide-value:`` in
info-field-list.
2020-12-27 12:46:03 +09:00
Takeshi KOMIYA
70bb2262d6 Fix #8567: autodoc: Instance attributes are incorrectly added to Parent class
The instance attributes on subclasses are shown on the document of
parent class unexpectedly because of autodoc modifies `__annotations__`
in place.  This fix creates a copy of `__annotations__` attribute and
attach it to the subclass.
2020-12-22 02:38:31 +09:00
Takeshi KOMIYA
a7a77d154b Merge branch '3.x' 2020-12-20 21:33:57 +09:00
Takeshi KOMIYA
dd1615c59d
Merge pull request #8543 from tk0miya/8534_autoattribute_alias_derived
Fix #8534: autoattribute failed to document a commented attribute in alias dervied class
2020-12-17 22:35:35 +09:00
Takeshi KOMIYA
9721327989 Fix #8545: autodoc: a __slots__ attribute is not documented even having docstring
To avoid filtering __slots__ attributes having docstring at
filter_members(), this passes docstring captured at get_class_members()
to the filter_members() via ObjectMember.
2020-12-17 22:19:28 +09:00
Takeshi KOMIYA
0dbbf1dd54 Fix #8534: autoattribute failed to document a commented attribute in alias dervied class 2020-12-17 22:13:20 +09:00
Takeshi KOMIYA
55c110f609 Fix #8541: autodoc_type_aliases doesn't work for the instance attrs
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.
2020-12-17 01:07:54 +09:00
Takeshi KOMIYA
caa1d1f3c2 Fix #8534: autoattribute failed to document a commented attribute in alias class
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.
2020-12-16 02:43:31 +09:00
Takeshi KOMIYA
2c98e909bf Merge branch '3.x' 2020-12-14 02:02:29 +09:00
Takeshi KOMIYA
0b074c9e48 Merge commit 'a82b06f2abb1226d82b18e3f85bdf19be7b9eb3f' 2020-12-14 01:58:23 +09:00
Jon Dufresne
850512090a Remove duplicate test in test_ext_autodoc.py
Duplicate since c6bd84a614.
2020-12-12 06:28:23 -08:00
Takeshi KOMIYA
bb63f03034 Fix #8503: autoattribute could not create document for a GenericAlias 2020-11-29 12:24:10 +09:00
Timo Ludwig
ccfd98dc07
Fix #8493: Use restify() in autodoc to reference alias attributes 2020-11-28 12:12:02 +01:00
Takeshi KOMIYA
a00d62c445 Merge branch '3.x' 2020-11-22 16:04:07 +09:00
Takeshi KOMIYA
9eb96d5c79 Fix #8460: autodata directive does not display the detail of TypeVars
The details are only shown when automodule directive is used.  This
allows to document them via other auto* directives.
2020-11-22 13:57:48 +09:00
Takeshi KOMIYA
24a329eebe
Merge pull request #8465 from tk0miya/8460_NewType
Fix #8460: autodoc: Support custom types defined by typing.NewType
2020-11-22 13:47:39 +09:00
Takeshi KOMIYA
b4d4d4e808 refactor: Rename example class 2020-11-22 03:06:03 +09:00
Takeshi KOMIYA
6973888294 Support NewType as a class attribute 2020-11-21 23:56:16 +09:00
Takeshi KOMIYA
93d6c212f7 Fix #8460: autodoc: Support custom types defined by typing.NewType
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.
2020-11-21 23:04:42 +09:00
Takeshi KOMIYA
3a4ae2092a Merge branch '3.x' 2020-11-21 01:01:36 +09:00
Takeshi KOMIYA
21a3bd4127 refactor: Fix flake8 violations under tests/ directory 2020-11-15 17:15:40 +09:00
Takeshi KOMIYA
279e547860 Merge branch '3.x' 2020-11-12 02:50:43 +09:00
François Freitag
0949735210
Sort imports with isort
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.
2020-11-11 13:19:05 +01:00
Takeshi KOMIYA
6d5e43a0ff Drop code for supporting py35 2020-11-06 01:36:04 +09:00
Takeshi KOMIYA
218de39462 Fix testcases for singledispatch are sometimes failed
They are sometimes failed with python3.5 because the order of singledispatch
functions is not stable on python 3.5.  This uses comparision via "in"
keyword to check the signature of singledispatch functions stably.
2020-11-04 23:19:27 +09:00
Matthias Geier
82c83ed478 autodoc: Add test for single-string __slots__ 2020-10-25 10:27:43 +01:00
Takeshi KOMIYA
6dbe28a632 Fix #7786: autodoc: can't detect overloaded methods defined in other file 2020-10-05 22:49:05 +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
740be7f2a5 autodoc: blacklist typing.Generic.__new__
When documenting classes derived from typing.Generic (essentially all classes in the
typing module) the constructor signature would show an unhelpful (*args, **kwds).

typing.Generic has a __new__ method which was picked up by sphinx. With this patch it
is skipped and constructor signatures for generic classes are shown as they should.
2020-08-21 18:47:50 +02: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
610ab926a4 fix 2020-07-16 23:59:26 +09:00
Takeshi KOMIYA
9b74e6cd67 autodoc: the signature of base function will be shown for decorated functions 2020-07-05 03:08:27 +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
e860903cd8 Fix #7844: autodoc: Failed to detect module when relative module name given 2020-06-22 01:53:09 +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
c1fd36cc9c Close #4422: autodoc: Support GenericAlias 2020-05-30 21:53:42 +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
a1293e2825
Merge pull request #7709 from tk0miya/refactor_test_ext_autodoc
refactor: test: Separate tests for autofunction
2020-05-23 02:38:53 +09:00
Takeshi KOMIYA
f13e05a01b refactor: test: Separate tests for autofunction 2020-05-22 23:41:45 +09:00
Takeshi KOMIYA
c5f7ded772
Merge branch '3.x' into 7668_wront_retann 2020-05-22 23:15:47 +09:00
Takeshi KOMIYA
38a21d7dac Fix #7676: autodoc: typo in the default value of autodoc_member_order 2020-05-17 01:47:32 +09:00
Takeshi KOMIYA
fcfdc19624 refactor: autodoc: Remove magic mock from singledispatch processing 2020-05-16 22:55:24 +09:00
Jakob Lykke Andersen
97accc931d
Merge pull request #7663 from jakobandersen/astext
Fix astext() for two Sphinx nodes
2020-05-16 10:09:22 +02:00
Takeshi KOMIYA
dff45a11b7 Fix #7668: autodoc: wrong retann value is passed to autodoc-proccess-signature 2020-05-16 14:51:18 +09:00
Jakob Lykke Andersen
41971382f8 ... and don't break tests. 2020-05-14 19:41:17 +02:00
Takeshi KOMIYA
3a81ffa79a Fix #7650: autodoc: undecorated signature is shown for decorated functions 2020-05-11 01:11:12 +09:00
Takeshi KOMIYA
caddd3a547 Fix test_ext_autodoc: Set testroot to testcases 2020-05-11 00:37:36 +09:00
Takeshi KOMIYA
29829bd451
Merge pull request #7623 from tk0miya/7362_autofunction_for_builtins
Fix #7362: autodoc: does not render correct signatures for built-in functions
2020-05-09 18:46:13 +09:00
Takeshi KOMIYA
6c65327be7
Merge pull request #7624 from tk0miya/refactor_autodoc2
refactor: autodoc: class processors on autofunction is no longer needed
2020-05-09 18:10:55 +09:00
Takeshi KOMIYA
92e0007179 Fix autodoc: does not render correct signatures for built-in methods 2020-05-09 17:38:28 +09:00
Takeshi KOMIYA
815abf0fea Fix #7362: autodoc: does not render correct signatures for built-in functions 2020-05-09 16:37:03 +09:00
Takeshi KOMIYA
560ccf83ae Fix #7551: autodoc: failed to import nested class 2020-05-07 02:02:02 +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
eef7e4cdd5 test: Rename test_autodoc.py to test_ext_autodoc.py 2020-05-06 13:55:45 +09:00
Takeshi KOMIYA
2ca76d2366 test: Merge test_ext_autodoc.py and test_autodoc.py 2020-05-06 13:47:15 +09:00
Takeshi KOMIYA
eaf495c3c4 A happy new year! 2020-01-01 14:27:43 +09:00
Takeshi KOMIYA
90bf81bd37 test: Use get_doctree() to load doctree files 2019-02-17 20:27:48 +09:00
Takeshi KOMIYA
76e9f57c2e Merge branch '1.8' 2019-01-02 16:16:25 +09:00
Takeshi KOMIYA
1b1ebd2c75 A happy new year! 2019-01-02 16:00:30 +09:00
Jon Dufresne
bade33c7e4 Remove unnecessary encoding cookie from Python source files
In Python 3, the default encoding of source files is utf-8. The encoding
cookie is now unnecessary and redundant so remove it. For more details,
see the docs:

https://docs.python.org/3/howto/unicode.html#the-string-type

> The default encoding for Python source code is UTF-8, so you can
> simply include a Unicode character in a string literal ...

Includes a fix for the flake8 header checks to stop expecting an
encoding cookie.
2018-12-16 12:22:12 -08:00
Takeshi KOMIYA
abcb5bd5ec The default setting for master_doc is changed to 'index' 2018-09-04 01:14:16 +09:00
Takeshi KOMIYA
f7027049b1 Fix flake8 violations 2018-02-19 23:20:56 +09:00
Sergey B Kirpichev
b1c100ca3b autodoc: make full reference for classes, aliased with "alias of"
We do this here only if class belongs to the different module.

Closes sphinx-doc/sphinx#2437
2018-01-13 00:19:19 +03:00
Takeshi KOMIYA
2426cedb8b A happy new year! 2018-01-01 01:06:58 +09:00
Takeshi KOMIYA
c57e47e042 Year++ 2017-03-26 11:49:34 +09:00
shimizukawa
baaef9146d pytest: remove deprecated with_app decorator functions 2017-01-06 01:14:47 +09:00
Takeshi KOMIYA
e15216c568 Fix sphinx.ext.autodoc crashes if target code imports * from mock modules by autodoc_mock_imports 2016-08-09 12:20:11 +09:00