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
[RFE] Support union types specification using | (vertical bar/pipe) #1874
Comments
From the docs:
So this feature is already available using this syntax: def foo(foo):
"""
Bla blu
:type foo: str or int or None
""" Instead of multiplying the possible syntaxes for this, why don't we try to adhere to PEP 484 and the def foo(foo):
"""
Bla blu
:type foo: Union[str, int, None]
""" |
A lot of time has passed since I filed this issue. I don't remember whether I specifically wanted the pipe syntax or whether it was just an example... I certainly didn't know about that PEP and that module didn't exist at that time as far as I know... As well as the paragraph in the documentation that you have mentioned... And that PyCharm's syntax was, for sure, the only syntax I knew... Maybe it was a mistake to suggest a particular implementation... Now, it's enough for me that there is a support for union types in Sphinx already... |
The pipe syntax is now in the standards-track PEP 604. I'm personally less interested in sphinx supporting type specification using pipes, but more so about the type annotations in the output using the pipe notation, saving the space taken by writing out the often-verbose would become this: |
@ErikBjare Please check the latest Sphinx out with Python-3.10. The union types using pipes are displayed as-is. |
…list Close #1874: py domain: Support union types using `|` in info-field-list
Please add a support for specifying multiple types acceptable for a parameter/attribute/variable.
Use case:
Imagine that there is a function that accepts both
bytes
andstr
. The docstring would look like:Such a syntax is already supported by e.g. PyCharm.
The text was updated successfully, but these errors were encountered: