python-time-space-complexity
AGENTS.md19 starsChanged 43 days agoMITView on GitHub
This file contains instructions for AI agents (like Amp, Claude, etc.) working on this repository. Before creating ANY git commit, you MUST: - All ruff linting must pass - All pyright type checks must pass (0 errors) - All pytest tests must pass (no failures; the suite grows over time, so check for zero failures rather than a fixed count) Reusable project workflows live in .agents/skills/. Agents with native Agent Skills support should load the matching skill before starting this…
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 33,398 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository6 other files it gives its agents.
- docs/llms.txtllms.txt
- documenting-complexity-modulesSkill
- evaluating-skill-recallSkill
- testing-complexity-claimsSkill
- updating-python-supportSkill
- python-complexitySkill
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
58 rules. About 0 are common, 29 are distinctive, and 29 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈29
Distinctive · estimate
This author's own choices. Worth a look.
29
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 11
Run make check (lint + types + tests)
- Distinctive: line 15
All ruff linting must pass
- Distinctive: line 16
All pyright type checks must pass (0 errors)
- Distinctive: line 17
All pytest tests must pass (no failures.
- Distinctive: line 27
Do NOT commit if checks fail
- Distinctive: line 115
Keep anything a later reader needs to re-derive the result:
- Distinctive: line 131
No unused imports (enforced by ruff)
- Very specific: line 133
All checks must pass: make lint
- Distinctive: line 139
Use admonitions for important notes:
- Distinctive: line 146
Use imperative mood: "Add", "Fix", "Update", not "Added", "Fixed"
- Very specific: line 175
Run make lint - all linting must pass
- Very specific: line 176
Run make types - all type checks must pass
- Very specific: line 177
Run make test - all tests must pass
- Distinctive: line 178
Never commit broken code
- Distinctive: line 182
Must test documentation structure, live coverage, and project files
- Distinctive: line 199
Run another interpreter only for the tests whose claim is about that version - a version-gated skip, a bound that moves at a release, an …
- Very specific: line 207
Keep those environments outside the worktree, and delete them afterwards.
- Very specific: line 230
Create markdown file in /docs
- Very specific: line 231
Update navigation in mkdocs.yml
- Very specific: line 232
Run make audit to check live documentation coverage
- Very specific: line 233
Run make serve to preview
- Very specific: line 234
Run make check to verify
- Very specific: line 235
Commit with message: Add: Topic name documentation
- Very specific: line 245
Only single-underscore modules such as _thread and python -m entry points (json.__main__) are outside the audit.
- Very specific: line 267
When you edit docs/<path>.md, check for docs/*/<path>.md:
- Distinctive: line 274
If you cannot make a faithful translation, say so and leave the page stale rather than guessing - a stale flag is recoverable, a wrong …
- Very specific: line 277
Never hand-edit
source_sha: Use --update-hashes, and only after the translation actually matches the new English text. - Very specific: line 308
Every page here is a complexity claim, so a wrong one is the worst defect this repo can ship - and make check cannot see it.
- Distinctive: line 312
Before writing a claim, decide which of four kinds it is.
- Very specific: line 350
Every skip decided while a test runs - pytest.skip(), a module-level skip - starts with platform: , version: or missing <capability>: , and …
- Very specific: line 361
Every English page with a fenced python block needs a test module that names it, as docs/<path>.md, in the opening paragraph of its …
- Very specific: line 406
Test files: tests/test_<module>_complexity.py for a stdlib module's table and its kind-A claims, tests/test_builtin_claims.py for kind-A …
- Very specific: line 418
Run make format (auto-fixes issues)
- Very specific: line 419
Verify no new issues with make lint
- Very specific: line 420
Run make test to ensure nothing broke
- Very specific: line 426
Commit without running make check
- Very specific: line 427
Commit if make lint fails
- Distinctive: line 432
Create unnecessary files in root directory
- Distinctive: line 445
Write a page, test docstring or skill as a record of what changed - state what is true, not what it used to say (see Write Forward)
- Distinctive: line 449
Always run quality checks before committing
- Distinctive: line 450
Keep commits focused and minimal
- Distinctive: line 451
Write clear commit messages
- Distinctive: line 453
Update documentation when changing functionality
- Distinctive: line 454
Test a complexity claim that goes beyond the page's table, before trusting it
- Distinctive: line 455
Test locally before pushing
- Distinctive: line 461
Check the error message carefully
- Distinctive: line 464
Verify all tests pass before committing
- Very specific: line 467
Run make format (auto-fixes most issues)
- Very specific: line 470
Verify with make lint again
- Very specific: line 473
Do NOT use --force push
- Distinctive: line 479
Before every commit, verify:
- Distinctive: line 530
If you need guidance:
- Distinctive: line 531
Check CONTRIBUTING.md for contribution guidelines
- Distinctive: line 532
Check README.md for project overview
- Distinctive: line 533
Check PERFORMANCE.md before changing how CSS, fonts or scripts are delivered
- Very specific: line 535
Check SEO.md before changing hreflang, canonical URLs or robots.txt
- Very specific: line 536
Check ACCESSIBILITY.md before changing any colour, heading level, or lang attribute
- Distinctive: line 543
Enforcement: All commits checked automatically
≈ “Common” is an estimate: at least 1 in 5 of the 43,423 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AI Agent Guidelines
This file contains instructions for AI agents (like Amp, Claude, etc.) working on this repository.
Core Rules
Pre-Commit Verification (MANDATORY)
Before creating ANY git commit, you MUST:
- Run
make check(lint + types + tests)make check- All ruff linting must pass
- All pyright type checks must pass (0 errors)
- All pytest tests must pass (no failures; the suite grows over time, so check for zero failures rather than a fixed count)
- Verify output shows:
All checks passed! 0 errors, 0 warnings, 0 informations ====== N passed ====== - Do NOT commit if checks fail
Example Pre-Commit Workflow
# Make changes
# ...
# Run quality checks
make lint # Verify: All checks passed!
make format # Fix any formatting issues
make test # Verify: no failures
# Only then commit
git add .
git commit -m "Your message"Standard Commands
Development
make dev- Install with dev dependenciesmake serve- Start local server (http://localhost:8000)make build- Build static site
Quality Assurance
make lint- Check code quality (must pass before commit)make format- Format code automaticallymake types- Run pyright type checker (must pass before commit)make check- Run lint + types + tests (must pass before commit)make test- Run pytest (must pass before commit)
Maintenance
make clean- Remove build artifactsmake update- Update dependenciesmake help- Show all available commands
Project Structure
Key Directories
/docs- Documentation markdown files (site content, English)/docs/<locale>- Translations mirroring the English tree (e.g./docs/fi)/tests- Python test files/scripts- Utility scripts (templates)
Key Files
pyproject.toml- Project config, dependencies, tool settingsMakefile- Development commandsmkdocs.yml- Documentation site config (incl.i18nplugin locales)TRANSLATING.md- Translation workflow and per-locale glossariesACCESSIBILITY.md- WCAG 2.2 AA rules: colour tokens,lang, headingsPERFORMANCE.md- critical path, vendored fonts, and what was left aloneSEO.md- hreflang, canonical URLs, sitemaps,robots.txtscripts/validate_translations.py- Translation structure/staleness checker.python-version- the interpreter local commands use (the newest supported)uv.lock- Dependency lock file (reproducible builds)
Repository Skills
Reusable project workflows live in .agents/skills/. Agents with native Agent
Skills support should load the matching skill before starting this work:
documenting-complexity-modules- Use when adding a builtin or standard-library module page, or materially expanding one.testing-complexity-claims- Use when adding or changing complexity claims, auditing claim coverage, or creating module complexity tests.updating-python-support- Use when dropping an EOL Python version, adding a newly released Python version, or changing the supported Python range.evaluating-skill-recall- Use when adding or changing the skill evaluation's items, rerunning it, or adjudicating its results.
.agents/skills/ is the canonical source. Claude Code compatibility symlinks
live in .claude/skills/; edit the canonical skill rather than the symlink.
Code Style & Standards
Write Forward
Pages, test docstrings and skills are read by someone who was not here. They state what is true now. They are not a record of how they came to be written.
Cut anything that only means something against an earlier version:
- "was documented O(1)", "the page used to say", "the first draft claimed"
- "did not survive measurement", "found while running the tests on 3.12"
- which approach was tried first, which review comment turned out wrong, what the sentence replaced
Keep anything a later reader needs to re-derive the result:
- the bound, its size variables, and the version boundaries that move it
- what a test measured and at what sizes, so a future release fails it loudly
- the dimensions a test did not vary, so nobody reads it as covering them
- why a claim cannot be settled by running code
The test is direction, not length. "32x the depth costs x171 on 3.10 and x2.1 on 3.14" is evidence a later reader can re-run and a later release can break. "The page said O(1) per item" is a diff, and git already has it.
This binds test docstrings as tightly as it binds pages. A docstring may carry the whole measurement behind a row. It must not carry the row's history.
Python Code
- Line length: 100 characters (enforced by ruff)
- No unused imports (enforced by ruff)
- Format with
make formatbefore commit - All checks must pass:
make lint
Documentation (Markdown)
- Complexity tables required (Time, Space, Notes columns)
- Include code examples for operations
- Link to related operations
- Use admonitions for important notes:
!!! warning "Title" Content here
Commit Messages
- Use imperative mood: "Add", "Fix", "Update", not "Added", "Fixed"
- Format:
Type: Brief description - Types: Add, Fix, Update, Refactor, Docs, Test, Chore
- Example:
Add: List complexity documentation - Keep the message short. Say what was corrected or added and stop. Do
not narrate what the code or claim used to be, how the defect was found,
what was measured on the way, or which approaches were rejected — the
reader does not need it. What was measured belongs in the test and its
docstring, where it can be re-run; what the page used to say belongs
nowhere. Prefer a line or a few bullets:
The same applies to pull request descriptions.Fix: Correct three os space bounds and add the module's tests - os.walk is O(w + d), not O(d): queued entries are a term of their own - os.makedirs is O(n): it recurses once per path component - AI Agents MUST add Co-Authored-By trailer to identify the agent:
Replace "Amp amp@ampcode.com" with the actual AI agent name (Claude, Copilot, etc.) and email.Add: List complexity documentation Co-Authored-By: Amp <amp@ampcode.com>
Testing Requirements
Before Every Commit
- Run
make lint- all linting must pass - Run
make types- all type checks must pass - Run
make test- all tests must pass - Never commit broken code
Test Files Location
tests/test_documentation.py- Main test file- Must test documentation structure, live coverage, and project files
Running Tests
make lint # Run linting
make types # Run type checks
make test # Run all tests
make check # Run lint + types + tests (recommended before commit)Python Versions
make test uses the interpreter in .python-version, the newest supported
patch release. That is the default for local work. CI runs the suite on that
interpreter on Linux, macOS and Windows, and the timing tests on every supported
version, so do not reproduce the matrix by hand before a commit.
Run another interpreter only for the tests whose claim is about that version - a version-gated skip, a bound that moves at a release, an API added or removed:
UV_PROJECT_ENVIRONMENT=/tmp/py312 uv run --python 3.12.15 --frozen \
pytest tests/test_enum_complexity.py -k unhashableKeep those environments outside the worktree, and delete them afterwards. The
exception is a change to the supported range itself, where both new boundaries
have to be installed and run - see the updating-python-support skill.
Dependency Management
Adding Dependencies
# Add production dependency
uv add package-name
# Add dev dependency
uv add --dev package-nameDO NOT
- Manually edit pyproject.toml dependency lists
- Manual requirements.txt edits (uv manages this)
- Forget to commit uv.lock after adding dependencies
Common Workflows
Adding Documentation
- Create markdown file in
/docs - Update navigation in
mkdocs.yml - Run
make auditto check live documentation coverage - Run
make serveto preview - Run
make checkto verify - Commit with message:
Add: Topic name documentation
Coverage tests compare the current interpreter's builtins and standard library
with the current English documentation tree. make audit prints a readable
report without writing files, and fails unless builtins, stdlib modules and the
public API are all at 100%. make check runs it. Keep every navigation target,
including pages for removed modules and EOL Python versions. CI runs the audit
on Linux on every supported Python version: an API a later release removed is
checked only on the versions that still have it.
Only single-underscore modules such as _thread and python -m entry points
(json.__main__) are outside the audit. __future__, pydoc_data, the
sre_* shims (until 3.15 removed them), every encodings codec, idlelib, turtledemo and
antigravity are all in it. antigravity and idlelib.idle run a program on
import, so the audit reads their names from source instead of importing them. The generic codec classes
each encodings module repeats are not in the official API inventory, so they
land under needs-classification rather than as misses.
Local work and CI both run on Linux, so a module that only exists on another
platform - winreg, msvcrt, asyncio.windows_events - is reported under
import errors on every run. Import errors do not fail the audit: they are a
platform limit, not a coverage gap. Name those modules in the module's test
rationale. Any other inspection error (a timeout, a binding that raises) does
fail it, and a module that imports on Linux is a blocker when it has a miss.
Editing an English Page That Has Translations
English is the source of truth. Every translated page records the SHA-256 of
the English file it was made from, so any edit to an English page - even a
typo fix or whitespace change - marks its translations stale and fails
make check.
When you edit docs/<path>.md, check for docs/*/<path>.md:
- Make the English edit
- Mirror the same change into each existing translation
- Re-record the hashes:
uv run python scripts/validate_translations.py --update-hashes <locale> - Run
make check
If you cannot make a faithful translation, say so and leave the page stale rather than guessing - a stale flag is recoverable, a wrong translation is not.
Never hand-edit source_sha. Use --update-hashes, and only after the
translation actually matches the new English text. Editing the hash without
updating the content silently marks a wrong translation as current.
Translating
Full workflow, glossaries, and per-locale rules: TRANSLATING.md.
Contributor-facing summary: the i18n section of CONTRIBUTING.md.
Structural rules the validator enforces (scripts/validate_translations.py,
run as part of make check):
- Code blocks must match the English source byte for byte - do not translate comments, identifiers, or output inside fenced blocks
- Heading count and levels must match
- Table row counts must match
- Link targets must match
Also note:
- Headings are translated, which changes anchor slugs. Keep headings that are
Python identifiers (
## deque,## Counter) untranslated, or cross-page anchor links such ascollections.md#dequewill break. - Translations live in
docs/<locale>/, so thedocs/builtins/*.mdanddocs/stdlib/*.mdglobs intests/andscripts/audit_documentation.pydo not see them. This is intentional - do not "fix" it. - Missing pages fall back to English automatically. Partial translations are fine; never bulk-translate to fill gaps.
Adding or Changing a Complexity Claim
Every page here is a complexity claim, so a wrong one is the worst defect
this repo can ship - and make check cannot see it. A page can be green,
lint-clean and confidently wrong.
Before writing a claim, decide which of four kinds it is.
A. It says something the page's complexity table does not. These are the
explanatory clauses - "costs no more than a str key", "one lookup",
"formatting is the more expensive of the two". Every wrong claim found so far
has been one of these. Write a test. Prefer observation over timing: a
counting __eq__, a counting os.scandir, an identity check, a call
counter. Those need no tolerance and cannot flake. Where only a stopwatch
will do, compare two input sizes and assert on the ratio, with a threshold
far from both the behaviour you are asserting and the one you are excluding.
Note that a claim of this kind is often a sentence with no O(...) in it at
all. About a third of the wrong ones were. Do not filter by notation.
B. It restates a row of the page's own table. A # O(log n) beside
heappush. Covered by the module's complexity test file - which needs to
exist. Add one if it does not, rather than a test per annotation.
C. It cannot be settled by running code. Network round trips, an NSS backend, a module removed in a later Python, or a definitional choice such as which unit a bound is expressed in. Say so in the test file's docstring, next to the ones you did cover, and do not write a test that pretends otherwise.
D. Only another platform can settle it. A winreg, msvcrt or
os.startfile row. Guard the test with sys.platform, the way a
version-specific claim is guarded with sys.version_info. CI runs the suite on
Linux, macOS and Windows, so the test is verified on its own platform there;
locally it is a skip, so name the platform in the file's docstring.
A platform guard skips exactly the platforms its mechanism applies to, and its
reason names that mechanism ("macOS's PATH_MAX is 1,024 bytes"), never just the
platform ("Linux-only"). A test with no platform-specific subject has no guard:
it passes on all three or it is a bug. Before guarding a failure seen on one
machine, find the mechanism - a result from a checkout shared with another host
can come from pytest's rewritten-module cache in tests/__pycache__, which
records the other host's paths.
Every skip decided while a test runs - pytest.skip(), a module-level skip -
starts with platform: , version: or missing <capability>: , and a marker
that probes the environment uses the missing form too. tests/conftest.py
fails any other, and in CI fails a missing skip for a capability the runner
is not declared to lack. See that file for the list of capabilities.
Claims are not the only thing that breaks. Two of the three pages spot-checked
so far shipped examples that raised on the first line - one of them a
NameError introduced while adding annotations to it. Run a page's code
blocks, not just its numbers.
Every English page with a fenced python block needs a test module that names
it, as docs/<path>.md, in the opening paragraph of its docstring and defines
test_the_page_has_the_expected_blocks, pinning the block count.
tests/test_documented_examples_coverage.py fails a page without one; it does
not check that the module runs the blocks. tests/page_examples.py finds the
blocks, dedented, and runs each in its own interpreter and temporary working
directory, with stdin on the null device and a 120-second timeout. Run every
block as printed where you can. Where you cannot - a block that needs a server,
a file the reader supplies, another platform or runtime, or a billion
iterations - say why in the docstring and supply the file, compile the block,
or scale it down and assert the substitution changed it.
Things worth knowing before you rely on a test:
- A test pins what it asserts, not what the prose says. Its name is not an assertion either: one here claimed a comparison its body never made.
- Measure before you correct.
Decimal.quantize()cost tracks the digits the result keeps, not the operand's - the opposite of a plausible-sounding review comment that was accepted here without measuring. - Vary the input before you generalise.
most_common(k)was benchmarked on counts that rose in iteration order, the one shape that defeats the heap, and the docs told four languages that passing k never pays. On random or Zipf-like counts it wins by eight times. - Version differences hide in the middle of the range as readily as at its
ends, so the two boundaries are not a shortcut for reasoning about the set.
glob0/glob1deprecation warnings start in 3.13,iglob's recursive listings surviveclose()on 3.12 alone,value in EnumClassraises for an unhashable value on 3.12 while 3.11 and 3.13 do not, andprepare()may be called twice only from 3.14. CI runs the whole matrix, which is where a test meant to hold everywhere gets held to it; locally, run the version a claim is actually about. - Pick the framing with the widest gap, not the one that mirrors the sentence most directly. Four timing tests here had to be widened after the fact, each because it compared the smallest pair that demonstrated the claim - two 70ns operations, a 2x size step, a 2us baseline. The same fact usually has a framing that produces a far bigger ratio.
- A mutation check that does not apply proves nothing. Assert the
substitution changed the file: one here silently matched nothing after
ruff formatrewrapped the assertion, and "passed" as the original test. - The autofixer can rewrite the subject too.
ruff check --fixturnedtyping.List[int] is typing.List[int]intolist[int] is list[int], collapsing a memoization test into a tautology about one object. When a test contrasts two spellings, add a per-file ignore with the reason and assert the two forms are actually different objects.
Test files: tests/test_<module>_complexity.py for a stdlib module's table
and its kind-A claims, tests/test_builtin_claims.py for kind-A claims on
builtin pages, tests/test_complexity_caveats.py for claims that were wrong
once already.
Fixing Issues
- Identify the problem
- Make minimal changes
- Run
make checkto verify - Commit with message:
Fix: Description of fix
Code Cleanup
- Run
make format(auto-fixes issues) - Verify no new issues with
make lint - Run
make testto ensure nothing broke - Commit with message:
Refactor: Description
What NOT to Do
❌ DO NOT
- Commit without running
make check - Commit if
make lintfails - Commit if
make typesfails - Commit if
make testfails - Ignore test failures
- Manually edit lock files (use uv commands)
- Create unnecessary files in root directory
- Break existing tests without fixing them
- Edit an English page without updating its translations (see above)
- Hand-edit
source_shain a translation's front matter - Translate anything inside a fenced code block
- Reformat English tables cosmetically - it marks every translation stale
- Change a colour without measuring its contrast (see ACCESSIBILITY.md)
- Re-add
extra_css, hardcode the JS bundle's content hash, or dropcrossoriginfrom a font preload (see PERFORMANCE.md) - Emit a relative
hreflanghref, or addx-defaulttoextra.alternate(see SEO.md) - Dim text with
opacity- it fails contrast and SC 1.4.1 both - Skip a heading level (
##straight to####) - Write a page, test docstring or skill as a record of what changed - state what is true, not what it used to say (see Write Forward)
✓ DO
- Always run quality checks before committing
- Keep commits focused and minimal
- Write clear commit messages
- Add Co-Authored-By trailer for agent identification
- Update documentation when changing functionality
- Test a complexity claim that goes beyond the page's table, before trusting it
- Test locally before pushing
- Review your changes before committing
Emergency Procedures
If Tests Fail
- Check the error message carefully
- Fix the issue locally
- Run
make checkagain - Verify all tests pass before committing
If Code Quality Issues
- Run
make format(auto-fixes most issues) - Review remaining issues with
make lint - Fix manually if needed
- Verify with
make lintagain
If Git History is Broken
- Do NOT use
--forcepush - Contact a human maintainer
- Preserve commit history
Verification Checklist
Before every commit, verify:
make lintpasses (0 errors)make typespasses (0 errors)make testpasses (no failures)- No uncommitted changes
- Commit message is clear
- Changes are focused/minimal
- Documentation updated if needed
- New complexity claims tested, or recorded as untestable (see above)
- Edited code blocks actually run, and new tests pass on the pinned interpreter - plus the specific version a version-dependent claim is about
- Translations updated if an English page changed
- Accessibility rules honoured if colours/headings/
langchanged - No test files left uncommitted
- Nothing written reads as a diff against a previous version
Examples
Example: Good Commit
# Edit documentation
vim docs/stdlib/itertools.md
# Verify changes
make serve # View in browser
# Quality checks
make lint # All checks passed!
make types # 0 errors, 0 warnings, 0 informations
make test # no failures
# Commit
git add .
git commit -m "Add: itertools module complexity documentation"Example: Bad Commit (DO NOT DO)
# Edit documentation
vim docs/stdlib/itertools.md
# Directly commit WITHOUT checking
git add .
git commit -m "updated docs" # ❌ NO! Check first!Questions?
If you need guidance:
- Check CONTRIBUTING.md for contribution guidelines
- Check README.md for project overview
- Check PERFORMANCE.md before changing how CSS, fonts or scripts are delivered
- Check SEO.md before changing hreflang, canonical URLs or
robots.txt - Check ACCESSIBILITY.md before changing any colour, heading level, or
langattribute
Last Updated: January 2026
Status: Active guidelines - Follow these rules
Enforcement: All commits checked automatically
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

