question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pipe operand for type unions causes type annotation errors

See original GitHub issue

Problem 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:

  1. Parse code with type unions using the pipe operand
  2. ???
  3. Profit

System Information

pdoc: 8.1.0
Python: 3.9.9
Platform: macOS-12.0.1-arm64-arm-64bit

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mhilscommented, Jan 6, 2022

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. 😉

0reactions
bczsalbacommented, Jan 6, 2022

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.

🚀

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found