示例工程 11-protocols-generics-overloads
11-protocols-generics-overloads/05-typeis-narrowing/typeguard_case.py.txt
from typing import TypeGuard
def is_str_list(value: int | list[str]) -> TypeGuard[list[str]]:
return isinstance(value, list)
def use(value: int | list[str]) -> int:
if not is_str_list(value):
return value + 1
return len(value)