-
-
Notifications
You must be signed in to change notification settings - Fork 196
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
Types with nested "|" (Union) are not formatted well #424
Comments
This seems to be an upstream bug in Python itself: >>> from typing import Iterable
>>> int | str | Iterable[int | str]
typing.Union[int, str, typing.Iterable[int | str]] as well as >>> import inspect
>>> inspect.formatannotation(int | str | Iterable[int | str])
'Union[int, str, Iterable[int | str]]' |
Interesting; I can reproduce your results above, but then also: >>> def f(a: int | str | Iterable[int | str] = 1):
>>> return a
>>> inspect.formatannotation(f.__annotations__)
"{'a': 'int | str | Iterable[int | str]'}" The difference might be related to the postponed evaluation of the annotation context? |
Actually, I'm curious: what would be the drawbacks of directly using the strings from |
The main drawback is that linking becomes much harder (how do we know that |
For the record, the problem here is that from collections.abc import Iterable # not from typing!
def function2(value: int | str | Iterable[int | str] = 1) -> None:
pass |
Amazing that you found this! It does make that |
For this program:
pdoc
produces the documentation:If feasible, it might be best to always use the more modern
... | ...
syntax and never theUnion[...]
syntax.The text was updated successfully, but these errors were encountered: