Published: 2022-08-02.
PEP-604 (landed in Python 3.10) introduced a new short syntax for typing.Union
(as I predicted, but I messed up union with intersection, shame on me):
def greet(name: str) -> str | None:
if not name:
return None
return f"Hello, {name}"
You already can use it in older Python versions by adding from __future__ import annotations
, type checkers will understand you.