Python 3 类型注解(Type Hints)与静态检查利器应用
一、现代 Python 类型示范
from typing import Optional, List, Dict
def fetch_user_posts(user_id: int, limit: int = 10) -> Optional[List[Dict[str, str]]]:
if user_id <= 0:
return None
return [{"title": "示例笔记", "slug": "sample"}]