python-foundational

Pratiques exemplaires fondamentales en Python, idiomes et principes de base de la qualité du code - Présenté par microsoft/hve-core

npx skills add https://github.com/microsoft/hve-core --skill python-foundational

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: PascalCase classes, snake_case functions/variables, UPPER_SNAKE_CASE constants, _ 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 with for files, locks, DB connections.
  • Prefer dataclass / NamedTuple / Enum for data holders.
  • Use pathlib over os.path; timezone-aware datetime when relevant.
  • Use * keyword-only arguments for multi-optional functions.
  • Never use mutable defaults or global/nonlocal unless 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 TypeVar for generics.
  • Avoid Any except in thin wrappers.

5. Error Handling

  • Raise specific exceptions; never bare except: (broad except 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, or pickle on 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

FileCoversPurpose
design-principles.mdSection 9Rationale and examples for the design principles
code-style-patterns.mdSections 1–5Concrete code examples for style, idioms, type safety, class design, and error handling

Severity Rubric

SeverityDefinition
HighCauses incorrect behavior, data loss, or security exposure at runtime
MediumDegrades maintainability, readability, or violates a project convention with no immediate runtime impact
LowCosmetic, stylistic, or minor improvement opportunity

Troubleshooting

SymptomCheck
Skill not loadedConfirm the diff contains .py files. The agent selects skills by matching file types in the changed files against skill descriptions.
No findings generatedVerify 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 miscalibratedCompare against the Severity Rubric above. High requires runtime impact; medium is maintainability-only.

Contributing

Follow these conventions when extending this skill:

  • Checklist items belong in SKILL.md. Each bullet is a single, actionable check an agent or reviewer can apply to a diff. Keep bullets concise: one sentence, no code.
  • Reference files live in references/ and provide examples or rationale for the covered checklist items. Each reference file covers a contiguous range of sections. Update the References table when adding a new file.
  • Before adding a new checklist item, confirm it does not duplicate an existing bullet in any section. Place it in the section that matches its primary concern. If it spans concerns, prefer the more specific section.
  • Name new reference files after the topic they cover (e.g., async-patterns.md). Include a frontmatter description that states which sections the file supports. Add a row to the References table in SKILL.md.
  • Checklist items and examples must be portable across codebases. Use generic module names and describe anti-patterns by their behavior, not by specific directory or file names.

Plus de skills de microsoft

oss-growth
microsoft
Persona de growth hacker OSS
official
microsoft-foundry
microsoft
Déployer, évaluer et gérer les agents Foundry de bout en bout : build Docker, push ACR, création d’agent hébergé/par prompt, démarrage de conteneur, évaluation par lots, évaluation continue, workflows d’optimisation de prompt, agent.yaml, curation de jeux de données à partir de traces. UTILISER POUR : déployer un agent vers Foundry, agent hébergé, créer un agent, invoquer un agent, évaluer un agent, exécuter une évaluation par lots, évaluation continue, surveillance continue, statut d’évaluation continue, optimiser un prompt, améliorer un prompt, optimiseur de prompt, optimiser les instructions d’un agent, améliorer un agent...
officialdevelopmentdevops
azure-ai
microsoft
Utiliser pour Azure AI : Recherche, Parole, OpenAI, Intelligence documentaire. Aide pour la recherche, la recherche vectorielle/hybride, la reconnaissance vocale, la synthèse vocale, la transcription, l'OCR. QUAND : Recherche AI, recherche par requête, recherche vectorielle, recherche hybride, recherche sémantique, reconnaissance vocale, synthèse vocale, transcrire, OCR, convertir du texte en parole.
officialdevelopmentapi
azure-deploy
microsoft
Exécutez les déploiements Azure pour les applications DÉJÀ PRÉPARÉES disposant de fichiers .azure/deployment-plan.md et d'infrastructure existants. N'utilisez PAS cette compétence lorsque l'utilisateur demande de CRÉER une nouvelle application — utilisez plutôt azure-prepare. Cette compétence exécute les commandes azd up, azd deploy, terraform apply et az deployment avec une récupération d'erreur intégrée. Nécessite .azure/deployment-plan.md de azure-prepare et un état validé de azure-validate. QUAND : "exécuter azd up", "exécuter azd deploy", "exécuter le déploiement",...
officialdevopsaws
azure-storage
microsoft
Services Azure Storage incluant Blob Storage, File Shares, Queue Storage, Table Storage et Data Lake. Répond aux questions sur les niveaux d'accès au stockage (chaud, froid, froid, archive), quand utiliser chaque niveau et comparaison des niveaux. Fournit du stockage d'objets, des partages de fichiers SMB, de la messagerie asynchrone, du NoSQL clé-valeur et de l'analyse de big data. Inclut la gestion du cycle de vie. À UTILISER POUR : stockage blob, partages de fichiers, stockage de files d'attente, stockage de tables, data lake, téléchargement de fichiers, téléchargement de blobs, comptes de stockage, niveaux d'accès,...
officialdevelopmentdatabase
azure-diagnostics
microsoft
Déboguer les problèmes de production Azure à l'aide d'AppLens, Azure Monitor, l'état des ressources et un triage sécurisé. QUAND : déboguer des problèmes de production, résoudre les problèmes d'App Service, CPU élevé d'App Service, échec de déploiement d'App Service, résoudre les problèmes de Container Apps, résoudre les problèmes de Functions, résoudre les problèmes d'AKS, kubectl ne peut pas se connecter, échecs kube-system/CoreDNS, pod en attente, crashloop, nœud non prêt, échecs de mise à niveau, analyser les logs, KQL, insights, échecs de pull d'image, problèmes de démarrage à froid, échecs de sonde de santé,...
officialdevopsdevelopment
azure-prepare
microsoft
Préparer les applications Azure pour le déploiement (infra Bicep/Terraform, azure.yaml, Dockerfiles). Utiliser pour créer/moderniser ou créer+déployer ; pas pour la migration cross-cloud (utiliser azure-cloud-migrate). NE PAS UTILISER POUR : les applications copilot-sdk (utiliser azure-hosted-copilot-sdk). QUAND : "créer une application", "construire une application web", "créer une API", "créer une API HTTP serverless", "créer un frontend", "créer un backend", "construire un service", "moderniser une application", "mettre à jour une application", "ajouter une authentification", "ajouter un cache", "héberger sur Azure", "créer et...
officialdevelopmentdevops
azure-validate
microsoft
Validation pré-déploiement pour la préparation Azure. Effectuez des vérifications approfondies sur la configuration, l'infrastructure (Bicep ou Terraform), les attributions de rôles RBAC, les autorisations d'identité managée et les prérequis avant le déploiement. QUAND : valider mon application, vérifier l'état de préparation au déploiement, exécuter des contrôles préalables, vérifier la configuration, vérifier si prêt à déployer, valider azure.yaml, valider Bicep, tester avant le déploiement, résoudre les erreurs de déploiement, valider Azure Functions, valider l'application de fonction, valider serverless...
officialdevopstesting