스킬 python-typing-patterns
🐍
python-typing-patterns
낮은 위험 ⚡
스크립트 포함⚙️
외부 명령어
应用 Python 类型提示以实现更安全的代码
또한 다음에서 사용할 수 있습니다: 0xDarkMatter
Python 类型提示可以提高代码质量并在开发时捕获错误。本技能提供使用类型注解、泛型、协议以及 mypy 和 pyright 等类型检查器的模式和示例。
지원: Claude Codex Code(CC)
1
스킬 ZIP 다운로드
2
Claude에서 업로드
설정 → 기능 → 스킬 → 스킬 업로드로 이동
3
토글을 켜고 사용 시작
테스트해 보기
"python-typing-patterns" 사용 중입니다. Add type annotations to this function: def process(data, multiplier): return [x * multiplier for x in data]
예상 결과:
- def process(data: list[float], multiplier: float) -> list[float]:
- return [x * multiplier for x in data]
보안 감사
낮은 위험v3 • 1/10/2026
This skill provides documentation and patterns for Python type hints. It includes a shell script that runs mypy and pyright type checkers on specified targets. No network calls, no credential access, no data exfiltration. All capabilities match stated purpose.
9
스캔된 파일
1,963
분석된 줄 수
3
발견 사항
3
총 감사 수
낮은 위험 문제 (1)
External command execution in type checker script
The check-types.sh script executes mypy and pyright type checkers using subprocess calls. Lines 67 and 99 invoke these tools directly. This is necessary for the stated purpose of running type checks, but any script that executes external processes carries inherent risk. An attacker could potentially exploit this if the target path could be manipulated to execute arbitrary code.
위험 요인
⚡ 스크립트 포함 (1)
⚙️ 외부 명령어 (2)
감사자: claude 감사 이력 보기 →
품질 점수
82
아키텍처
100
유지보수성
81
콘텐츠
23
커뮤니티
88
보안
70
사양 준수
만들 수 있는 것
为代码添加类型提示
学习用于变量、函数和类的现代 Python 类型注解模式。
设计类型安全的 API
使用 Protocol 和泛型创建灵活、文档完善的 API。
配置类型检查器
在 CI 流水线中设置 strict 模式的 mypy 和 pyright。
이 프롬프트를 사용해 보세요
基础注解
Write a Python function that takes a list of strings and returns a dictionary mapping each string to its length. Use modern Python type annotations.
泛型函数
Create a generic Stack class in Python that works with any type T. Include push, pop, and peek methods.
Protocol 模式
Define a Protocol called Serializable that requires a to_dict method. Show how a regular class can satisfy this Protocol without explicit inheritance.
类型收窄
Write a function that accepts str | int | list[str] and returns different types based on which branch is true. Use isinstance for type narrowing.
모범 사례
- 使用现代 Python 3.10+ 的联合语法(X | Y)而非 Union[X, Y]
- 对于结构化类型和鸭子类型,优先使用 Protocol 而非 ABC
- 在 mypy 或 pyright 中启用 strict 模式以捕获更多类型错误
피하기
- 使用 Any 来消除所有类型检查器错误
- 忘记为第三方库安装类型存根
- 混合使用隐式 Optional[X] 和显式 X | None 语法
자주 묻는 질문
What Python versions support these type patterns?
基础模式适用于 Python 3.10+。Self 和 TypeVarTuple 需要 Python 3.11+。TypeIs 需要 Python 3.13+。
How strict should my type checking be?
首先在 pyright 中使用标准模式或在 mypy 中使用基本设置。随着代码库完全类型化,逐步启用 strict 模式。
Can I use this skill with existing untyped code?
可以。类型检查器可以分析混合类型化和未类型化的代码。对没有存根的第三方库使用 ignore_missing_imports。
Is my data safe when running type checkers?
类型检查器仅读取和解析 Python 源代码文件。它们不会执行代码或访问网络、环境变量或凭据。
Why do I get false positives with mypy or pyright?
为第三方包安装类型存根。谨慎使用 # type: ignore 注释。启用 reportMissingTypeStubs 以查找缺失的存根。
How does this compare to Pyre or other type checkers?
mypy 和 pyright 是使用最广泛的类型检查器。Pyre 更快,但需要 Python 3.7+。本技能专注于 mypy 和 pyright,因为它们拥有最好的文档和生态系统支持。