from typing import Union, Optional, Any, Callable

# Union：可以是多种类型之一
def process(value: Union[int, str]) -> str:
    return str(value)

# Python 3.10+ 简写（推荐）
def process(value: int | str) -> str:
    ...

# Optional：可以是某类型，也可以是 None（常用！）
def find_user(name: str) -> Optional[dict]:
    # 找到返回dict，找不到返回None
    ...

# Any：任意类型（尽量少用，等于没注解）
def debug(data: Any) -> None:
    print(data)

# Callable：可调用对象（函数）
def run_twice(func: Callable[[int], str], x: int) -> None:
    print(func(x))
    print(func(x))
# ⚠️ Optional[str] 等价于 str | None