The Canon / synthesis

Nine roots on one diagram

The roots are not a list of decisions but a connected graph. Half of what looks like a Python oddity stands not on one root but on an edge between two.

The contents page shows the roots in reading order — linearly, because reading is linear. In fact they form a graph: some decisions follow from earlier ones, some constrain later ones. A solid arrow means “this follows”, a dashed one means “this ties your hands”.

The boxes are clickable — they lead to the root's page. On a narrow screen the diagram scrolls sideways.

1The edges in words

The diagram is useless without text: the content here is in the edges, not the nodes.

1R1 → R3A value is an object on the heap, not a bit field on the stack. So someone has to decide when an object is no longer needed. The memory model is not a separate decision but an obligation taken on together with the object model.
2R1 → R2A class is an object too, and a namespace is an ordinary dict. Hence attribute lookup cannot be an offset into a structure, as in C++ — it is a walk through dictionaries at the moment of access, cached by an inline cache right in the bytecode (lesson 23).
3R2 → R4Protocols are the only exception to the attribute lookup procedure: dunders are read directly from the type's slot. The exception was made for speed, and it is exactly what explains why a dunder on an instance does not work.
4R4 → R5Iteration is a special case of a protocol, taken to the limit: generators grew out of __iter__ and __next__, and await grew out of generators.
5R2 → R7A module is an object with a namespace dictionary, sitting in sys.modules. So an import is not linking but execution with the result cached — the nine phases of compilation taken apart in lesson 22.
6R3 → R6The key edge of the whole graph. The reference count sticks out of the public C API: every extension does Py_INCREF without a lock. Removing the GIL means breaking the whole compiled world. Hence the twenty years that free-threading took.
7R1 → R6Every number is an object with a header: a million integers take 36 MB instead of 8. Scientific computing had no choice but to move beyond the language's boundary — that is how the C API got its main load and its main client.
8R2 → R8A type is determined at the moment of access and can change between two lines. So there can be no sound static inference — not because mypy is unfinished, but by the construction of the language.
9R2 → R9The key order of dict was an implementation detail in 3.6 and became a guarantee in 3.7 — not because it was planned that way, but because code already relied on it. The canonical case of the transition 🔧 → 🔒.
10R3 → R9Half of all Python code ever written relies on deterministic destruction by reference count. Formally it is still a 🔧 detail, and it can be neither removed nor promised.
11R6 → R9The extension ABI is the reason free-threading was made a separate build rather than a flag. The behaviour cannot be switched: wheels are built for a specific ABI.
12R8 → R9Types stayed optional precisely because making them mandatory would have required breakage. PEP 563 did not become the default for exactly this reason.

2Three things visible only on the graph

The GIL has no root of its own. It stands on edge 6: the reference count plus the public C API. Neither of them requires the GIL on its own. That is why the question “why hasn't the GIL been removed” is ill-posed — what had to be removed was not the GIL but one of the two decisions under it, and both had already grown into the ecosystem.

R9 is not a root but a sink. Edges go into it and none come out. It is not a decision about the language; it is a rule about how the other decisions are made. That is why it has no chapters.

R2 is the most heavily loaded node. Four edges come out of it: protocols, import, the absence of types, the promise of key order. Dynamic attribute resolution pays for both all of the language's expressiveness and most of its limitations. If you remember one root, remember this one.

How to check that the graph has sunk in. Take any well-known Python oddity and name the edge it stands on. “Why len(x) and not x.len()” — edge 3. “Why numpy parallelizes with threads and my loop does not” — edges 6 and 7. “Why mypy lets bugs through” — edge 8. “Why you can rely on dictionary order but not on set order” — edge 9. If the edge comes to mind without thinking, the canon has worked.

Written by · The Python Canon