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.
A function signature is not shown when the function has a parameter
having ``inspect._empty`` as its default value because Signature class
validates function signatures on instantiation.
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.
Without this change, stringify(Optional[Union[int, str]]) returns
'Union[int, str, None]' rather than the expected 'Optional[...]'.
This change fixes that.
fixes: #7654
As a successor of sphinx.util.inspect.Singnature, this adds
signature() function behaves like `inspect.signature()`. It is
very similar to way of python's inspect module.
In addition, this also adds stringify_annotation() helper to
sphinx.util.inspect module. With these two functions, we can move
to python's Signature object to represent function signatures
perfectly. It's natural design for python developers than ever.
https://github.com/asottile/pyupgrade
> A tool to automatically upgrade syntax for newer versions of the
> language.
- Drop u str prefix
- Drop base object inheritance
- Drop args to super()
- Use set literals
- Use dict comprehension
- Use set comprehension
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.
Whilst working on the Reproducible Builds effort [0], we noticed
that sphinx could generate output that is not reproducible.
In particular, the rendering of `frozenset` objects in default
arguments and elsewhere is currently non-determinstic.
For example:
frozenset(['a', 'b', 'c'])
Might be rendered as any of:
frozenset({'a', 'b', 'c'})
frozenset({'a', 'c', 'b'})
frozenset({'b', 'a', 'c'})
frozenset({'b', 'c', 'a'})
frozenset({'c', 'a', 'b'})
frozenset({'c', 'b', 'a'})
Patch attached that sorts the contents of frozensets whilst rendering.
This is parallel to the `dict` and `set` type logic
[0] https://reproducible-builds.org/
Whilst working on the Reproducible Builds effort [0], we noticed
that sphinx could generate output that is not reproducible.
In particular, the rendering of `set` objects in default arguments
and elsewhere is currently non-determinstic. For example:
class A_Class(object):
a_set = {'a', 'b', 'c'}
Might be rendered as any of:
{'a', 'b', 'c'}
{'a', 'c', 'b'}
{'b', 'a', 'c'}
{'b', 'c', 'a'}
{'c', 'a', 'b'}
{'c', 'b', 'a'}
Patch attached that sorts the contents of sets whilst rendering.
This is parallel to the `dict` key sorting.
This was originally filed in Debian as #895553 [1].
[0] https://reproducible-builds.org/
[1] https://bugs.debian.org/895553
Signed-off-by: Chris Lamb <lamby@debian.org>
This improves handling of wrapped functions and bound methods.
It turns out that we no longer need to hack in support for
functools.partial; inspect.signature handles this automatically. Added
a test to make sure this didn't/doesn't regress.
The fallback implemented in #2731 cannot return `obj.__dict__[name]`
if the `__dict__` method has been redefined in such a way that it
raises an exception when trying to access it.
This commit adds a try-except block to work around this.