-
Notifications
You must be signed in to change notification settings - Fork 133
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
Type alias definition not shown #224
Comments
I don't quite understand the issue you're describing. At the moment, an attribute is documented like |
Yeah, and for type aliases, having
appear like that in the docs as well as the source code, rather than
|
but as I say, I'm not sure how you'd do this without directives, because there are some aliases
where we can't assume they're type aliases |
this section of the mypy docs may be useful |
I should add that it gets more complicated when a public alias refers to a private one, like
where it doesn't make sense to show |
^^^ replying to my own message, I think the last message is not an issue. Having a private type alias as a generic parameter, as above, is to be avoided, as if the definition of |
+1 for this feature. For example TensorFlow doc do it correctly. Here is the documentation for the type alias https://www.tensorflow.org/datasets/api_docs/python/tfds/typing/JsonValue |
+1 for this feature too, documenting Type Aliases can help a lot in modules that describes a bunch of types at their beginning, that are used in later functions and classes. Type Hinting is in itself a formalized way to document the code 🔎 Example of current behaviourExample of code using both a traditional type alias ( # Do not use the type keyword, as values are used dynamically
# in the code too (not only the type declarations)
Keys = Literal["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
type Mappings = dict[Literal["default", "reversed"], dict[Keys, str]]
type PuzzleInput = list[str] Here is what the rendered autoapi doc looks like Observation:
Hovering (type alias) Keys: type[Literal['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']] Also, no link is provided to jump to the 🔥 What I would likeWhat would be perfect would to have, in the possible extent, the same experience as in an IDE when reading the doc:
DetailsFor the recordshere are excerpts from my extensions = [
"sphinx.ext.coverage",
"sphinx.ext.napoleon",
"sphinx.ext.intersphinx",
"sphinx.ext.autodoc",
"autoapi.extension",
# "sphinx.ext.autosummary",
"nbsphinx",
"myst_parser",
# "sphinxemoji.sphinxemoji",
# "sphinx_mdinclude",
"sphinxcontrib.youtube",
"sphinx_favicon",
] autoapi_generate_api_docs = True
autoapi_dirs = ["../../advent_of_code"]
autoapi_type = "python"
# autoapi_keep_files = True
# autoapi_template_dir = "_autoapi_templates"
autoapi_options = [
"members",
"undoc-members",
"show-inheritance",
# "show-module-summary", # does not look good
"special-members",
"imported-members",
]
autoapi_python_class_content = "class"
autoapi_member_order = "bysource"
autodoc_typehints = "signature" # "description"
autodoc_typehints_format = "short"
# autodoc_typehints_format = "fully-qualified"
autodoc_inherit_docstrings = False
napoleon_google_docstring = False
napoleon_numpy_docstring = True
napoleon_use_param = False
napoleon_use_ivar = True
# Do not show fully qualified paths to classes and functions
add_module_names = False
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
# Numpy seems broken
"python": ("https://docs.python.org/3.12/", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"xarray": ("https://xarray.pydata.org/en/stable/", None),
} |
note that when I wrote this, the |
AutoAPI isn't going to support implicit type alias definitions without contributions from someone else. Detection of implicit type aliases is too complex, and not very well defined as far as I can tell. |
that seems like an overwhelmingly pragmatic approach, I approve (I'm OP with a different account) |
@AWhetter I'm finding that I can't get "type alias expansion" to occur if I use |
I like the way this library doesn't expand type aliases at usage site. It makes the docs more readable, conveys the meaning in the type alias names, and also works with docstrings that reference type aliases.
However, it only works if the aliases show their definition, otherwise users have to look at the source code to know what type a type alias actually refers to. I realise this may be difficult in Python, cos a type alias uses the same syntax as a variable (except where it also uses items from the
typing
module such asUnion
). In rust, for example, this would be easier cos it starts with the keywordtype
. Would sphinx need some kind of specific directive, akin to:param:
e.g.:type:
for this to be possible?A similar problem occurs with
TypeVar
. Don't know if you want a separate ticket for thatThe text was updated successfully, but these errors were encountered: