python-foundational

작성자: microsoft

파이썬 기초 모범 사례, 관용구 및 코드 품질 기본 사항 - 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.

microsoft의 다른 스킬

oss-growth
microsoft
OSS 성장 해커 페르소나
official
microsoft-foundry
microsoft
Foundry 에이전트를 엔드투엔드로 배포, 평가 및 관리: Docker 빌드, ACR 푸시, 호스팅/프롬프트 에이전트 생성, 컨테이너 시작, 배치 평가, 지속적 평가, 프롬프트 최적화 워크플로, agent.yaml, 트레이스에서 데이터셋 큐레이션. 용도: Foundry에 에이전트 배포, 호스팅 에이전트, 에이전트 생성, 에이전트 호출, 에이전트 평가, 배치 평가 실행, 지속적 평가, 지속적 모니터링, 지속적 평가 상태, 프롬프트 최적화, 프롬프트 개선, 프롬프트 최적화 도구, 에이전트 지침 최적화, 에이전트 개선...
officialdevelopmentdevops
azure-ai
microsoft
Azure AI: Search, Speech, OpenAI, Document Intelligence에 사용됩니다. 검색, 벡터/하이브리드 검색, 음성-텍스트 변환, 텍스트-음성 변환, 전사, OCR을 지원합니다. 사용 시점: AI Search, 쿼리 검색, 벡터 검색, 하이브리드 검색, 의미 검색, 음성-텍스트 변환, 텍스트-음성 변환, 전사, OCR, 텍스트를 음성으로 변환.
officialdevelopmentapi
azure-deploy
microsoft
이미 준비된 애플리케이션에 대해 기존 .azure/deployment-plan.md 및 인프라 파일이 있는 경우 Azure 배포를 실행합니다. 사용자가 새 애플리케이션 생성을 요청할 때는 이 스킬을 사용하지 말고 azure-prepare를 사용하세요. 이 스킬은 azd up, azd deploy, terraform apply, az deployment 명령을 내장된 오류 복구 기능과 함께 실행합니다. azure-prepare의 .azure/deployment-plan.md와 azure-validate의 검증 상태가 필요합니다. 사용 시점: "run azd up", "run azd deploy", "execute deployment",...
officialdevopsaws
azure-storage
microsoft
Azure Storage Services는 Blob Storage, File Shares, Queue Storage, Table Storage, Data Lake를 포함합니다. 스토리지 액세스 계층(hot, cool, cold, archive), 각 계층 사용 시기 및 계층 비교에 대한 질문에 답변합니다. 객체 스토리지, SMB 파일 공유, 비동기 메시징, NoSQL 키-값, 빅데이터 분석을 제공합니다. 수명 주기 관리를 포함합니다. 사용 용도: blob 스토리지, 파일 공유, 큐 스토리지, 테이블 스토리지, 데이터 레이크, 파일 업로드, blob 다운로드, 스토리지 계정, 액세스 계층,...
officialdevelopmentdatabase
azure-diagnostics
microsoft
Azure에서 AppLens, Azure Monitor, 리소스 상태 및 안전한 트라이지를 사용하여 Azure 프로덕션 문제를 디버그합니다. 사용 시기: 프로덕션 문제 디버그, 앱 서비스 문제 해결, 앱 서비스 높은 CPU, 앱 서비스 배포 실패, 컨테이너 앱 문제 해결, 함수 문제 해결, AKS 문제 해결, kubectl 연결 불가, kube-system/CoreDNS 오류, pod 보류 중, crashloop, 노드 준비 안 됨, 업그레이드 실패, 로그 분석, KQL, 인사이트, 이미지 풀 실패, 콜드 스타트 문제, 상태 프로브 실패,...
officialdevopsdevelopment
azure-prepare
microsoft
Azure 앱을 배포용으로 준비합니다(인프라 Bicep/Terraform, azure.yaml, Dockerfiles). 생성/현대화 또는 생성+배포에 사용하며, 크로스 클라우드 마이그레이션에는 사용하지 않습니다(azure-cloud-migrate 사용). 다음에는 사용하지 마십시오: copilot-sdk 앱(azure-hosted-copilot-sdk 사용). 사용 시점: "앱 생성", "웹 앱 빌드", "API 생성", "서버리스 HTTP API 생성", "프론트엔드 생성", "백엔드 생성", "서비스 빌드", "애플리케이션 현대화", "애플리케이션 업데이트", "인증 추가", "캐싱 추가", "Azure에 호스팅", "생성 및...
officialdevelopmentdevops
azure-validate
microsoft
Azure 배포 전 준비 상태 검증. 구성, 인프라(Bicep 또는 Terraform), RBAC 역할 할당, 관리 ID 권한, 사전 요구 사항에 대한 심층 점검을 실행합니다. 사용 시점: 내 앱 검증, 배포 준비 상태 확인, 사전 점검 실행, 구성 확인, 배포 가능 여부 확인, azure.yaml 검증, Bicep 검증, 배포 전 테스트, 배포 오류 문제 해결, Azure Functions 검증, 함수 앱 검증, 서버리스 검증...
officialdevopstesting