When I heard that Microsoft's checker for Python pyright supports the latest specifications and scanned the README, I hadn't watched it before. PEP 604 (Complementary syntax for Union []) was listed, so I took a look. By the way, I will write about PEP-612 in the next article.
and ʻissubclass ()
|
that's all.
The sample in PEP is self-explanatory, so I won't explain it.
# in place of
# def f(list: List[Union[int, str]], param: Optional[int]) -> Union[float, str]
def f(list: List[int | str], param: int | None) -> float | str:
pass
f([1, "abc"], None)
assert str | int == Union[str,int]
assert str | int | float == Union[str, int, float]
assert isinstance("", int | str)
assert issubclass(bool, int | float)
List [int | str]
isn't very beneficial ...Recommended Posts