Pipe operand for type unions causes type annotation errors
See original GitHub issueProblem Description
Natively since Python 3.9, but using from __future__ import annotations
on some version prior you can use syntax like str | int
instead of Union[str, int]
. This is supported by type parsers and python alike, but pdoc seems to not like it that much. While the website builds to a certain point, it doesn’t complete the full generation.
Steps to reproduce the behavior:
- Parse code with type unions using the pipe operand
- ???
- Profit
System Information
pdoc: 8.1.0
Python: 3.9.9
Platform: macOS-12.0.1-arm64-arm-64bit
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (7 by maintainers)
Top Results From Across the Web
3.10 union operator ( | ) doesn't work in subscripts ... - GitHub
CallableAliasTest raises just the "not a valid type" error. If this isn't a bug, and there is some reason for the | operator...
Read more >New union shorthand giving "unsupported operand type(s) for ...
python - New union shorthand giving "unsupported operand type(s) for |: 'str' and 'type'" - Stack Overflow. Stack Overflow for Teams – Start ......
Read more >Python 3.10 - Simplifies Unions in Type Annotations
The focus of this tutorial is to talk about PEP 604, which makes writing union types easier when adding type annotation (AKA: type...
Read more >Type Errors - Pyre
If strict mode is turned on, Pyre will error when a function argument is either annotated with a return type that contains typing.Any...
Read more >any, let, unions, and enums | Mastering TypeScript
Finally, we will discuss enums, which are a mechanism to replace magic strings, or magic numbers, with human-readable values. The any type. We...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the kind words! There is no way to silence certain warnings. For pytermgui, I only get a handful of real and easily fixable ones on Python 3.10. On Linux you can pipe stderr through grep, e.g.
pdoc [...] 2> >(grep -v IDManager)
to ignore IDManager-related warnings. 😉That definitely could be, the only reason I know about it being a thing is I wanted to make pytermgui not rely on 3.9 / 3.10, and that seemed like a better way than rewriting all those annotations. Mypy and pylint both support the syntax in this way (as long as the
__future__
import is present), so I didn’t really think about it that way. 😃If that is the case, however then it’s no problem for pdoc not to support it, however is there any way to silence certain warnings? I honestly did not know about
_IDManager
being a problem until you pointed that out, as I get about 2 terminal heights worth of the same warning. I know I could just use 3.10, so if it’s not an already existing feature I don’t think it’s worth adding for this little functionality.Thank you for the tip at the end though, to be honest I wrote that part of the code ages ago and added the PEP 563 backport months later, so I never recognized the two being redundant together.
Thanks for your help! I would consider the issue to be resolved, but I’ll leave the closing up to you just in case you wanna do something related to this.
🚀