
python-foundational
β Officialβ 1,245by microsoft Β· part of microsoft/hve-core
Foundational Python best practices, idioms, and code quality fundamentals
This is the playbook your agent receives when the skill activates β you don't need to read it to use the skill, but it's here to audit before installing.
Python Foundational Coding Standards Skill
Overview
Foundational Python excellence that every diff must satisfy. This skill is loaded first for any .py change. All higher-order skills build on it.
This content is a skill rather than an instructions file for three reasons: skills are distributed through the CLI plugin and VS Code extension without requiring consumers to copy files into their repo; new language skills can be added without modifying the review agent itself; and skills are loaded on demand, keeping the context window small when the diff contains no Python.
Core Checklist
1. Readability & Style
- Use Python naming:
PascalCaseclasses,snake_casefunctions/variables,UPPER_SNAKE_CASEconstants,_private members. - Group imports: stdlib β third-party β local (blank line between groups, no trailing whitespace).
2. Pythonic Idioms
- Prefer comprehensions for simple transforms; use explicit loops for complex logic/side-effects.
- Always use
withfor files, locks, DB connections. - Prefer
dataclass/NamedTuple/Enumfor data holders. - Use
pathliboveros.path; timezone-awaredatetimewhen relevant. - Use
*keyword-only arguments for multi-optional functions. - Never use mutable defaults or
global/nonlocalunless strictly required.
3. Function & Class Design
- Keep functions small and single-responsibility.
- Add docstrings to all public APIs (follow repo style).
- Document unavoidable side-effects.
- Follow codebaseβs class-member ordering (if defined).
4. Type Safety Foundations
- Add type hints to all public APIs, module vars, and class attributes.
- Use PEP 695 (3.12+) or
TypeVarfor generics. - Avoid
Anyexcept in thin wrappers.
5. Error Handling
- Raise specific exceptions; never bare
except:(broadexcept Exception:only at app boundaries with logging). - No silent failures or generic error messages.
- Provide context, expected state, and guidance in every exception.
6. Anti-Patterns to Avoid
- Never use
eval,exec, orpickleon untrusted data. - Never hard-code secrets.
7. Maintainability
- Prefer self-documenting code; comments only for "why".
- Use structured logging instead of
print. - Flag overly long/complex functions that resist testing.
8. Architectural Fit
- Align with existing patterns; do not re-implement shared functionality or bypass established layers.
- Place code in the correct module/package.
9. Design Principles
- Eliminate duplication: extract repeated logic into a shared helper so fixes propagate automatically.
- Prefer the simplest implementation that satisfies current requirements. Introduce abstractions only when a second concrete use case appears.
- Limit change breadth: every modified line should trace to the stated purpose of the change.
- Before flagging seemingly unused code, verify it is not a protocol implementation, framework hook, public API, or entry point invoked externally.
- Match solution complexity to problem complexity. A duplicated function warrants a shared helper, not an event-driven architecture.
References
| File | Covers | Purpose |
|---|---|---|
| design-principles.md | Section 9 | Rationale and examples for the design principles |
| code-style-patterns.md | Sections 1β5 | Concrete code examples for style, idioms, type safety, class design, and error handling |
Severity Rubric
| Severity | Definition |
|---|---|
| High | Causes incorrect behavior, data loss, or security exposure at runtime |
| Medium | Degrades maintainability, readability, or violates a project convention with no immediate runtime impact |
| Low | Cosmetic, stylistic, or minor improvement opportunity |
npx skills add microsoft/hve-core --skill "python-foundational" --full-depthRun this in your project β your agent picks the skill up automatically.
Troubleshooting
| Symptom | Check |
|---|---|
| Skill not loaded | Confirm the diff contains .py files. The agent selects skills by matching file types in the changed files against skill descriptions. |
| No findings generated | Verify the Skills Loaded footer in the review output lists python-foundational. If listed but no findings appear, the diff may already satisfy the checklist. |
| Severity seems miscalibrated | Compare against the Severity Rubric above. High requires runtime impact; medium is maintainability-only. |
Licensed under MITβ you can use, modify, and redistribute it under that license's terms.
View the full license file on GitHub β