python-guidelines
Python Guidelines
Integrate into existing code. Don't append to it.
Simple is better than complex. Flat is better than nested. Errors should never pass silently. Unless explicitly silenced. If the implementation is hard to explain, it's a bad idea.
-- The Zen of Python (PEP 20)
Code Philosophy
- Match existing naming, importing, and signature patterns. Use existing utilities and data structures.
- Functions have a single purpose. Don't hardcode behavior that makes them less general.
- No trivial wrappers for 2 lines or less. Inline it.
- Inline single-use variables at the usage site.
- No try/except unless critical. Let errors surface.
- No duplicate code.
- Functions handle their own input validation. No if-else checks in main.
- Use pathlib, not os.path.
- Consider API and time costs for MongoDB/Gemini/OpenAI/Claude/Voyage.
Don't do this:
# Generate comment report only if requested
if include_comments:
comment_report = generate_comments_report(start_date, end_date, team, verbose)
else:
comment_report = ""
print(" Skipping comment analysis (disabled)")
Do this:
comment_report = generate_comments_report(start_date, end_date, team, verbose) if include_comments else ""
Ask yourself: "Am I adding code, or integrating into what exists?"
Simplicity Over Abstraction
YAGNI: You Aren't Gonna Need It.
Don't build for hypothetical future requirements. Add complexity only when the current task demands it.
Avoid:
- Abstract base classes for a single implementation
- Configuration options nobody asked for
- Error handling for impossible scenarios
- Wrapper classes around a single function
- Dependency injection when direct calls work
- Generic type parameters for one concrete type
Three similar lines of code is better than a premature abstraction. Refactor when the third real use case appears, not before.
But simplicity does not mean chaos. Always maintain:
- Clear function names that describe what they do
- Logical grouping of related code into modules
- Consistent naming conventions across the project
- Clean separation between I/O and logic
- Explicit parameters over global state or side effects
Ask yourself: "Is this abstraction solving a problem I have right now, or one I'm imagining?"
Environment
- Package manager: uv (NOT pip)
- Virtual env:
source .venv/bin/activateoruv run python -c "..." - 3rd party packages: Find source with
python -c "import pkg; print(pkg.__file__)", then Read.
Testing Discipline
Never assume anything. Run python -c "..." to verify hypotheses about code behavior, package functions, or data structures before suggesting a plan or exiting plan mode.
Ask yourself: "Did I verify this with python -c before building on it?"
Google-Style Docstrings
- Summary: Imperative mood ("Calculate", not "Calculates")
- Args: All parameters with types and descriptions. No default values. Indent 4 spaces.
- Types:
int | strunions, uppercase shapes(N, M), lowercase builtinslist/dict/tuple, capitalizeAny/Path - Optional:
name (type, optional): Description - Returns: Always
(type)in parentheses. Never tuple types. Separate named values for multiple returns. - Sections: Examples (>>>), Notes, References (plaintext only). Section titles at 0 indent.
- Omit: "Returns:" if nothing returned, "Args:" if no args, "Raises:" unless critical
- Classes: Attributes section only, omit Methods/Args. Don't convert single-line to multiline.
__init__: Args only. No Examples/Notes/Methods/References.- Tests: Single-line docstrings only.
- Erase default values from existing arg descriptions. Optionally include minimal Examples.
Ask yourself: "Would a new developer understand this function from the docstring alone?"
Reference Files
For deeper guidance, see the reference files in references/:
zen-of-python.md-- Full Zen of Python (PEP 20) with annotationsgoogle-style-guide.md-- Curated sections: exceptions, defaults, imports, naming, commentsidiomatic-patterns.md-- 18 Python idioms with before/after code exampleseffective-python-tips.md-- Key tips from "Effective Python" by Brett Slatkin, organized by category
More from fcakyon/claude-codex-settings
paper-search-usage
This skill should be used when user asks to "search for papers", "find research papers", "search arXiv", "search PubMed", "find academic papers", "search IEEE", "search Scopus", or "look up scientific literature".
91setup
This skill should be used when the user asks "how to setup GitHub CLI", "configure gh", "gh auth not working", "GitHub CLI connection failed", "gh CLI error", or needs help with GitHub authentication.
53tavily-usage
This skill should be used when user asks to "search the web", "fetch content from URL", "extract page content", "use Tavily search", "scrape this website", "get information from this link", or "web search for X".
48linear-usage
This skill should be used when user asks about "Linear issues", "issue tracking best practices", "sprint planning", "Linear project management", or "creating Linear issues".
37plugin-structure
This skill should be used when the user asks to "create a plugin", "scaffold a plugin", "understand plugin structure", "organize plugin components", "set up plugin.json", "use ${CLAUDE_PLUGIN_ROOT}", "add commands/agents/skills/hooks", "configure auto-discovery", or needs guidance on plugin directory layout, manifest configuration, component organization, file naming conventions, or Claude Code plugin architecture best practices.
29hook-development
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.
29