使い方
- インストールコマンドをコピーし、自分の環境へ導入する前にソースを確認します。
- 必要なツール、認証情報、対応環境を原文で確認します。
- 入力と成果物を指定し、出力を資料と照合します。
npx skills add https://github.com/alexander-danilenko/cortex-ai-skills --skill python開始前の確認
- 導入にはモデル契約、API枠、ファイルへのアクセス許可は含まれません。
- スター数や導入数は活動の指標であり、独立した品質・安全性試験ではありません。
見出し、例、コード、表、リンク、参照画像を含む原文を表示しています。
Python
House conventions for Python 3.11+. Apply them to code you are writing or changing — don't refactor untouched files to match unless asked.
Conventions
- Type every public signature and keep
mypy --strictgreen. Types on internals are optional; types at the boundary are what stop a caller passing the wrong thing. - Built-in generics and `X | None` —
list[str],dict[str, int],str | None.typing.ListandOptional[str]are the pre-3.10 spelling and only cost an import. - `Protocol` over ABC inheritance. Structural typing lets any correctly-shaped object satisfy the contract — including a test double — with no inheritance tree to maintain.
- Dataclasses for data,
slots=Trueandfrozen=Truewhere they fit. They generate__init__,__repr__, and__eq__correctly; a hand-written__init__is where field drift starts. Pydantic is for validation and (de)serialisation at a boundary, not for plain records. - `pathlib`, not `os.path`. Operator joins can't silently produce a wrong path from a stray separator.
- Never a mutable default argument.
def f(items=[])shares one list across every call — a bug that only appears on the second call. Default toNoneand build inside. - `asyncio.TaskGroup` over bare `gather` (3.11+): it cancels siblings on failure and reports via
ExceptionGroup, so a crashed task can't leave the rest running detached. Useasync with asyncio.timeout(n)for deadlines. - Hold a reference to every `create_task`. The event loop only keeps a weak reference, so a fire-and-forget task can be garbage-collected mid-execution and simply vanish — no error, no result. Keep them in a
setand discard on completion:
_tasks: set[asyncio.Task[None]] = set()
def spawn(coro: Coroutine[None, None, None]) -> None:
task = asyncio.create_task(coro)
_tasks.add(task)
task.add_done_callback(_tasks.discard)- Never a bare `except:` — it swallows
KeyboardInterruptandSystemExit. Catch what you can actually handle. - Google-style docstrings on public functions and classes, carrying intent rather than a restatement of the signature. The
documentationskill has the full rule. - pytest: fixtures for setup, `parametrize` for cases. A loop inside one test reports a single failure and hides which case broke;
parametrizenames each one. - Poetry and `pyproject.toml` for packaging, ruff for lint and format, and a
py.typedmarker on any package whose types consumers should see. Use asrc/layout — it stops tests from importing the working directory instead of the installed package, which is how a broken package still passes its own suite.
Tooling baseline
strict = true covers most of it; these add the checks that catch real bugs rather than style. --strict-markers matters more than it looks: without it a typo'd @pytest.mark.integraton silently does nothing and the test runs where you thought it was excluded.
[tool.mypy]
strict = true
warn_unreachable = true
warn_redundant_casts = true
warn_unused_ignores = true
[[tool.mypy.overrides]]
module = "untyped_dep.*"
ignore_missing_imports = true
[tool.pytest.ini_options]
addopts = ["-ra", "--strict-markers", "--strict-config"]


