Autodoc type aliases in overloads#13337
Autodoc type aliases in overloads#13337barakatzir wants to merge 9 commits intosphinx-doc:masterfrom
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_aliaseswas 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 thenpandnptaliases will not be resolved correctly and left asnpandnpt.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_hintsunder 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_overloadswhich 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_aliasesworks on attributes and module members and got stuck in a wall so I left it as is.References
autodoc_typehintsis"signature"or"both"#10359