Agent skill
Python
Python coding standards, best practices, type hints, and testing patterns. Use when writing or reviewing Python code, implementing tests, or discussing Python language features.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/testing/python-bendrucker-claude
SKILL.md
Python
- Use the latest Python language features appropriate for the project's minimum supported version.
Package Management
- Use
uvfor dependency management and package execution instead of virtual environments. - Run scripts with
uv run <script>. - Add dependencies with
uv add <package>.
Documentation
When users ask about Python standard library modules, use WebFetch to get the latest official documentation from docs.python.org.
Example:
- For
asyncio:https://docs.python.org/3/library/asyncio.html - For
typing:https://docs.python.org/3/library/typing.html - For
pathlib:https://docs.python.org/3/library/pathlib.html
Pattern: https://docs.python.org/3/library/<module>.html
Type Hints
- Always use type hints for function signatures, class attributes, and variables where the type is not immediately obvious.
- Avoid using
Anytype. Use specific types,TypeVar, or protocols instead. - Avoid using
# type: ignorecomments except in rare cases, mainly in test code. - Use
from __future__ import annotationsfor forward references and cleaner type hints. - Prefer
list[T],dict[K, V],set[T],tuple[T, ...]overtyping.List,typing.Dict, etc. (Python 3.9+).
Example:
from __future__ import annotations
def process_items(items: list[str], max_count: int | None = None) -> dict[str, int]:
"""Process items and return a count dictionary."""
result: dict[str, int] = {}
for item in items[:max_count]:
result[item] = result.get(item, 0) + 1
return result
Tests
Write parametrized tests using pytest:
import pytest
@pytest.mark.parametrize(
("input_value", "expected"),
[
("hello", "HELLO"),
("world", "WORLD"),
("", ""),
],
)
def test_uppercase(input_value: str, expected: str) -> None:
assert my_function(input_value) == expected
- Use descriptive parameter names in test cases.
- Type hint test functions with
-> None. - Group related tests in classes when appropriate.
- Use fixtures for shared setup and teardown.
Code Style
- Follow PEP 8 conventions.
- Use f-strings for string formatting.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?