-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Autodoc type aliases in overloads #13337
base: master
Are you sure you want to change the base?
Autodoc type aliases in overloads #13337
Conversation
…type-aliases-in-overloads
…natures of functions and methods.
…ustomized in the 'autodoc-before-process-signature' and 'autodoc-process-signature' events.
It wasn't clear to me at first that the number in the CHANGES.rst reference the relevant issues (🤦🏼♂️). Fixed now. |
I chose to switch the overload signature handling from using |
@AA-Turner, did you get a chance to look at my PR? If it is not on par with the code standards I'm willing to fix it. If the subject I'm raising is a non-issue I can simply close the PR without opening an issue. |
Purpose
I noticed that in the autodoc extension, the
autodoc_type_aliases
was not respected in overload signatures.Even worse, it ruined type signature for import aliases (
import ... as ...
) in some cases.I couldn't find an open issue for this so I'll describe it shortly here (maybe I missed?):
For example, if I want to document
Then setting
autodoc_type_aliases = {'MyMap': 'mapster.MyMap'}
(just about any non-trivial mapping) will not be applied, and thenp
andnpt
aliases will not be resolved correctly and left asnp
andnpt
.I looked in the source code, and saw that the signature for overloads is obtained differently from non-overloaded callables. Usually callables use
typing.get_type_hints
under the hood while overloads use an AST variant of signature determination. I switched the overloads to use FunctionDocumenter and MethodDocumenter to obtain the signatures usingtyping.get_overloads
which returns the overloads as callables (a python>=3.11 feature).Since the Documenters are used to resolve the signatures this solves issue #10351. This customization can probably allow for a workaround for #10359.
This also partially solves #9813.
I tried briefly to fix also so
autodoc_type_aliases
works on attributes and module members and got stuck in a wall so I left it as is.References
autodoc_typehints
is"signature"
or"both"
#10359