
The python-best-practices skill guides developers in writing type-safe, maintainable Python code by applying immutable data structures, discriminated unions, and domain-specific types to prevent invalid states at type-check time. It's for Python developers who want to follow functional programming patterns and enforce correctness through the type system rather than runtime checks. The skill solves the problem of catching logic errors early and avoiding mutation-related bugs by making illegal application states unrepresentable in the code.
$ npx -y skills add 0xbigboss/claude-code --skill python-best-practices --agent claude-codeInstalls into .claude/skills of the current project.
Follows type-first, functional, and error handling patterns from CLAUDE.md. This skill covers language-specific idioms only.
Use Python's type system to prevent invalid states at type-check time.
Frozen dataclasses for immutable domain models:
from dataclasses import dataclass
from datetime import datetime
@dataclass(frozen=True)
class User:
id: str
email: str
name: str
created_at: datetime
# Frozen dataclasses are immutable — no accidental mutation
Discriminated unions with Literal:
from dataclasses import dataclass
from typing import Literal
@dataclass
class Success:
status: Literal["success"] = "success"
data: str
@dataclass
class Failure:
status: Literal["error"] = "error"
error: Exception
RequestState = Success | Failure
def handle_state(state: RequestState) -> None:
match state:
case Success(data=data):
render(data)
case Failure(error=err):
show_error(err)
NewType for domain primitives:
from typing import NewType
Sponsors