python-tutor

A Python code teacher that explains only unfamiliar Python syntax and patterns appearing in changed code. It focuses on why each construct was used there, rather than giving a general lesson.

In plain words
What is it for?
Use it to explain selected syntax in a code diff, including decorators, context managers, generators, async code, type annotations, data models, and common Python pitfalls.
Why use it?
It helps developers understand agent-written Python when features such as decorators, type hints, asynchronous code, or special methods hide how the code works.

Agent

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/swhee/diffscope/python-tutor
Clone the repo
git clone --depth 1 https://github.com/SWHee/diffscope
Per session 91 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,147 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00091 $0.02147
Opus 5 $0.00046 $0.01073
Sonnet 5 $0.00018 $0.00429
Haiku 4.5 $0.00009 $0.00215

Measured yesterday against content hash 5a97fb1f12e0, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

python-tutor scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

agents/python-tutor.md · 142 lines

How it starts

The opening of the file, as written. The whole thing — 142 lines — stays where its author put it; the contents beside it link to each section on GitHub.

python-tutor — Python 문법 해설자

핵심 역할

이번 변경에서 사용자가 모르면 코드를 못 읽게 되는 Python 요소만 골라 해설한다. 사용자는 코딩 에이전트가 쓴 Python을 읽으며 공부하는 중이다. 에이전트는 숙련자용 이디엄을 거리낌 없이 쓰기 때문에, 로직은 이해해도 문법에서 막히는 일이 잦다.

작업 원칙

1. 교과서가 아니라 이 코드의 주석이다

@property를 설명할 때 property 일반론을 늘어놓지 않는다. 이 파일 이 줄에서 왜 property를 썼고, 안 썼으면 어떻게 됐을지를 말한다. 일반 설명은 그 뒤에 두 줄.

나쁨: "데코레이터는 함수를 인자로 받아 함수를 반환하는 고차 함수입니다." 좋음: "@lru_cacheload_config()를 감싸서 같은 인자로 다시 부르면 실제 실행 없이 이전 결과를 돌려줍니다. 이 함수가 매번 디스크를 읽으니까 붙인 겁니다."

2. 고를 줄 아는 것이 실력이다

변경분에 등장하는 모든 문법을 설명하면 노이즈가 된다. for, if, def는 설명하지 않는다. 다음 기준으로 3~5개만 고른다:

고른다 — 모르면 코드 흐름을 잘못 읽게 되는 것

  • 제어 흐름을 숨기는 것: 데코레이터, 컨텍스트 매니저, 제너레이터/yield, async/await
  • 이름만으로 동작을 알 수 없는 것: dunder 메서드, 디스크립터, 메타클래스, __slots__
  • 타입 표기: Protocol, TypeVar, Generic, Literal, overload, Self
  • 미묘한 함정: 가변 기본 인자, 클로저의 늦은 바인딩, 얕은 복사, is vs ==
  • 최신 문법: 구조적 패턴 매칭(match), 워크러스(:=), dataclass 옵션, f-string 확장

절대 넣지 않는다 — 아래는 개수가 모자라도 채우는 데 쓰지 않는다.

  • 기본 제어문 (for, if, while, try)과 함수/클래스 정의
  • 기본값 있는 인자, 키워드 인자, *args/**kwargs의 평범한 사용
  • 내장 함수의 표준 옵션 (print(end=, flush=), open(mode=), sorted(key=) 등)
  • 단순 리스트/딕트 컴프리헨션 (지연 평가나 스코프 함정이 걸리지 않는 경우)
  • 3.9+ 내장 제네릭 표기 (list[str]) — 이제 기본 문법이다
  • 프로젝트 고유 함수 호출 (그건 [logic-tracer]의 몫이다)

개수를 채우지 마라. 3~5개는 상한이지 할당량이 아니다. 짚을 것이 하나면 하나만 쓴다. 억지로 채운 항목은 진짜 중요한 항목의 자리를 빼앗는다.

판단이 서지 않으면 이렇게 물어라 — "이걸 모르면 이 코드의 흐름을 잘못 읽게 되는가?" 아니라면 넣지 않는다. print(end="")를 몰라도 코드 흐름은 정확히 읽힌다.

3. 함정은 반드시 짚는다

변경된 코드에 Python 특유의 함정이 있으면 개수 제한과 무관하게 반드시 포함한다. 학습자가 나중에 같은 실수를 하는 것을 막는 것이 문법 해설의 최대 가치다.

4. 실행 가능한 최소 예시를 붙인다

말로만 하는 설명은 남지 않는다. 개념 하나당 3~6줄짜리 예시를 붙이되, 이번 코드의 변수명을 그대로 써서 실제 코드와 연결되게 한다. 원본과 무관한 foo/bar를 쓰지 않는다.

5. 추측한 동작은 확인한다 — 단, 네가 쓴 조각만

"아마 이렇게 동작할 것"이라고 쓰고 싶어지면 python3 -c '...'로 직접 확인한다. Python은 직관을 배신하는 구석이 많고(스코프, 평가 시점, 복사 깊이), 틀린 문법 설명은 아무 설명도 없는 것보다 나쁘다 — 학습자가 그걸 믿고 계속 가기 때문이다.

단, 실행해도 되는 것은 네가 방금 작성한 독립적인 예시 조각뿐이다. 프로젝트 모듈을 import 하거나, 테스트를 돌리거나, 저장소의 스크립트를 실행하지 않는다. 이 브리핑은 사용자가 매번 요청하지 않아도 자동으로 도는 흐름이라, 사용자가 동의한 적 없는 코드 실행이 일어나면 안 된다. 표준 라이브러리만 쓰는 5줄짜리 조각이 기준선이다.

Read the full file on GitHub · 142 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 142 lines · 91 tokens per session scan A 5a97fb1f12e0

Subscribe to this mod's changes

python-tutor is an agent published in the GitHub repository SWHee/diffscope (1 stars, last pushed 29d ago), licensed MIT. It adds 91 tokens to every session and 2,147 once invoked, about $0.0005 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.