| 1 |
# CLAUDE.md |
| 2 |
|
| 3 |
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 |
|
| 5 |
## Orientation |
| 6 |
|
| 7 |
`bidict` is a mature, dependency-free bidirectional mapping library |
| 8 |
for Python (>=3.11, CPython + PyPy). |
| 9 |
The public API is small; |
| 10 |
the value is in the carefully-factored, fully type-hinted implementation. |
| 11 |
Optimize for correctness, API stability, and long-term maintainability |
| 12 |
over cleverness. |
| 13 |
There are **zero runtime dependencies** (standard library only) — |
| 14 |
do not add any. |
| 15 |
|
| 16 |
## Canonical docs (imported so their content is in-session) |
| 17 |
|
| 18 |
These human-facing docs are the single source of truth. |
| 19 |
When the underlying facts change, |
| 20 |
update *them* rather than duplicating anything here: |
| 21 |
|
| 22 |
- Contributor workflow — |
| 23 |
dev environment, running tests and checks, single-test invocation, |
| 24 |
the property-based (Hypothesis) testing approach, |
| 25 |
code style and lint, commit conventions, |
| 26 |
the Semantic Line Breaks prose convention, |
| 27 |
and the fact that doctests in modules and `docs/*.rst` run as tests: |
| 28 |
@CONTRIBUTING.rst |
| 29 |
- Architecture, code structure, |
| 30 |
and the guided "code review nav" reading order through the source: |
| 31 |
@docs/learning-from-bidict.rst |
| 32 |
- Extending bidict — |
| 33 |
custom subclasses, `on_dup` policies, dynamic inverse-class generation: |
| 34 |
@docs/extending.rst |
| 35 |
|
| 36 |
## Working in this codebase (Claude-specific notes) |
| 37 |
|
| 38 |
- Run dev tooling through the Nix dev shell, not the bare `.venv`: |
| 39 |
prefix commands with `nix develop --command bash -c '...'` |
| 40 |
(or work from within a `nix develop` shell). |
| 41 |
`prek`, `tox`, and the docs build are provided only by the Nix shell, |
| 42 |
so invoking them outside it fails with "command not found" — |
| 43 |
even though `pytest` and `ty` happen to also be in `.venv`, |
| 44 |
which makes it easy to forget. |
| 45 |
The committed `.envrc` (`use flake`) does not help here, |
| 46 |
because direnv has no hook in the non-interactive subshells |
| 47 |
spawned for these tool calls. |
| 48 |
- SemBr ([Semantic Line Breaks](https://sembr.org), see CONTRIBUTING.rst) |
| 49 |
applies to prose in Markdown and reStructuredText documents only |
| 50 |
(this file, `CONTRIBUTING.rst`, `docs/*.rst`): |
| 51 |
one sentence per line, breaking at clause boundaries, |
| 52 |
don't reflow paragraphs to fill columns. |
| 53 |
It does *not* apply to code, code comments, docstrings, or commit messages. |
| 54 |
- Follow the "Code review nav" banner comments |
| 55 |
at the top and bottom of each key file |
| 56 |
(start in `bidict/__init__.py`); |
| 57 |
they define the author's intended reading order. |
| 58 |
`_base.py`'s `BidictBase` is the heart of the library. |
| 59 |
- `_base.py` holds the subtle machinery, |
| 60 |
each piece explained in inline comments — |
| 61 |
**read those comments before editing** the relevant code. |
| 62 |
The landmarks to be careful around: |
| 63 |
- a bidict and its `.inverse` **share** the same two backing dicts |
| 64 |
(`_fwdm`/`_invm`, swapped), |
| 65 |
so mutations through either are visible in both; |
| 66 |
- the `inverse` property's strong-ref/weakref pair, |
| 67 |
which exposes the inverse without creating a reference cycle; |
| 68 |
- `_ensure_inv_cls`/`_make_inv_cls`, |
| 69 |
which synthesize a distinct inverse class |
| 70 |
when the forward and inverse backing types differ |
| 71 |
(intentionally corecursive with `__init_subclass__`); |
| 72 |
- the `_dedup` → `_write` mutation path, |
| 73 |
which records "unwrites" |
| 74 |
so a failing bulk `_update` rolls back atomically. |
| 75 |
- Every source file carries the MPL-2.0 header — |
| 76 |
include it on new files. |
| 77 |
Public API changes must be reflected in `CHANGELOG.rst` |
| 78 |
and the relevant `docs/*.rst`. |