Hacker News new | ask | show | jobs
by Rotareti 2310 days ago
I wish there was a union operator for typing as well to replace `Union[str, int]` with just `[str|int]`.
3 comments

PEP 604 (draft) proposes this:

  def f(list: List[int | str], param: int | None) -> float | str:
      pass

  f([1, "abc"], None)
https://www.python.org/dev/peps/pep-0604/
Naively, couldn’t your just overload `or` to make that work?
Did you mean `str | int`?