Chapter 8 of 1121 min read
Where it differs from CPython
Every known place where an aython program behaves differently from CPython, why it does, and which test pins it down.
aython is held to printing exactly what CPython prints, but only inside its subset, and even there not everywhere. Each difference was chosen: most because matching CPython would have needed a big integer type, a Unicode string type, class objects or a cycle collector, and the rest because CPython itself gives no single answer to match. This chapter lists every difference the repository records: what CPython does, what aython does, why, and which corpus file pins it down, or why no file can.
There are three ways an aython program can behave differently from CPython, and the repository treats them differently.
| Kind of difference | What happens | How the repository pins it |
|---|---|---|
| Refused | The frontend stops with aython: unsupported: ... before anything is built |
A reject: file; the program never runs, so nothing can differ at run time. The frontend chapter covers these |
| Aborts where CPython does not | The ELF prints one aython: <Kind> line and exits 1; CPython prints a result, or fails differently |
An abort:<Kind> file: the judge pins the ELF side and ignores CPython (how) |
| Runs, but differently | Both run to completion and print different text | Usually nothing can: a pass file needs identical bytes. These are recorded in the docs and kept out of the corpus and the fuzzer |
flowchart TD
q1{"Does the frontend<br/>accept the program?"} -->|no| rej["reject: file<br/>nothing runs"]
q1 -->|yes| q2{"Does the ELF fail?"}
q2 -->|yes| q3{"Does CPython fail<br/>naming the same kind?"}
q3 -->|yes| err["error: file<br/>both fail alike"]
q3 -->|no| ab["abort: file<br/>CPython's result ignored"]
q2 -->|no| q4{"Does CPython fail?"}
q4 -->|yes| none1["no marker fits<br/>recorded in the docs"]
q4 -->|no| q5{"Same stdout bytes?"}
q5 -->|yes| pass["pass file<br/>no difference"]
q5 -->|no| none2["no marker fits<br/>recorded in the docs"]
class ab accent
class err,pass good
class none1,none2 bad
The list below has 41 entries: 24 pinned by a corpus file and 17 recorded in the docs or the code with no file that could hold them. The build checks every named file: it must exist and carry exactly the marker shown, or the site does not build. Where a file pins the case, the CPython column is not written by hand: it is what CPython 3.14.4 printed for that file when this page was built.
Integers are 64-bit #
An aython int is a 24-byte box: refcount, type pointer, and one signed 64-bit payload (the objects chapter draws it). CPython’s int grows as large as memory allows. Arbitrary precision would need its own variable-length object, its own allocator and its own arithmetic in assembly, and the subset was designed without it (docs/core-design.md, “Int width” in the decisions table). The rule instead is that a result which does not fit is never silently wrong: every arithmetic helper checks, and aborts OverflowError.
runtime.s · int_mullines 1281–1429.Lmul_compute: # both sides int-like (fast path or validated slow path)
mov rax, [rbx + 16] # rax gets left boxed value
imul rax, [r12 + 16] # signed multiply, sets overflow flag
jo abort_overflow # abort OverflowError on signed overflow
mov rdi, rax # rdi gets raw product for int_new
call int_new # box product as new owned int
imul sets the processor’s overflow flag when the signed product does not fit in 64 bits, and jo jumps on it. int_add and int_sub test the flag the same way; int_neg compares against INT64_MIN before negating, the one value whose negation does not fit; and int_shl shifts the result back with sar and requires the original value.
| Case | aython | CPython | Why | Pinned by |
|---|---|---|---|---|
2**62 * 4, any int result past 64 bits |
Aborts OverflowError (int_mul checks the overflow flag with jo abort_overflow) |
Prints 18446744073709551616 and exits 0 |
An int is a boxed signed i64; arbitrary precision would need its own allocator and arithmetic | abort_overflow.py abort:OverflowError |
1 << 100 |
Aborts OverflowError (int_shl shifts the result back and requires the original value) |
Prints 1267650600228229401496703205376 and exits 0 |
Same 64-bit box | abort_shl_overflow.py abort:OverflowError |
x <<= 100 |
Aborts OverflowError, like the binary form |
Prints 1267650600228229401496703205376 and exits 0 |
Augmented assignment reuses the binary helper | abort_augassign_overflow.py abort:OverflowError |
2 ** 63 |
Aborts OverflowError from int squaring |
Prints 9223372036854775808 and exits 0 |
Same 64-bit box | err_power_overflow.py abort:OverflowError |
abs(-9223372036854775808) |
Aborts OverflowError: the negation of INT64_MIN does not fit |
Prints 9223372036854775808 and exits 0 |
Same 64-bit box; INT64_MIN itself boxes directly |
abort_abs_overflow.py abort:OverflowError |
The abort is an ordinary unwind, so a try/except OverflowError around 2**62 * 4 catches it in aython. In CPython the same handler never runs, because nothing is raised. The fuzzer keeps every generated literal small for this reason, and classifies an ELF-only OverflowError as the one known divergence rather than a failure.
Strings are ASCII bytes #
A str is a length and a pointer to bytes, and its length is both its byte count and its character count. That one equation makes indexing, slicing, len and hashing simple byte operations, and it only holds if every character is one byte. So non-ASCII text is kept out at every door: string literals are refused by the frontend, read_file and argv() abort ValueError on any byte of 128 or above, and chr stops at 127.
runtime.s · chr_newlines 13407–13449 cmp rax, 0 # below the Unicode range?
jl abort_value # negatives abort ValueError, like CPython
cmp rax, 0x10FFFF # above the Unicode range?
jg abort_value # that end aborts ValueError too, like CPython
cmp rax, 127 # above ASCII?
jg abort_overflow # 128..0x10FFFF have no bytes==chars spelling (issue #81)
mov r12, rax # r12 keeps the code point across the alloc call
| Case | aython | CPython | Why | Pinned by |
|---|---|---|---|---|
A non-ASCII string literal, "h\u00e9llo" |
Refused before anything is built: unsupported: non-ascii |
Prints héllo |
A str is a byte string whose length is its character count; one byte per character | rej_nonstr.py reject:non-ascii |
read_file of a file holding bytes 128 and up |
Aborts ValueError, the existing kind for bad values, chosen over adding an encoding kind |
Prints café and exits 0 |
Same ASCII model: the bytes could not be a str | err_io_nonascii.py abort:ValueError |
chr(200), any code point 128 to 0x10FFFF |
Aborts OverflowError (0-127 is exact; outside 0-0x10FFFF is ValueError, like CPython) |
Prints È and exits 0 |
The ASCII-only model cannot name the character; tracked in issue #81 | abort_chr_nonascii.py abort:OverflowError |
"a" % "b", any %-formatting of a str |
Aborts TypeError for every % on strs |
TypeError: not all arguments converted during string formatting, exit 1 |
%-formatting is one of the cut string forms; the probe pins that it aborts rather than printing |
abort_str_modfmt.py abort:TypeError |
"abc".startswith(("a", "b")) |
Aborts TypeError: startswith/endswith take one str |
Prints True and exits 0 |
Only the plain-str form is implemented | abort_startswith_tuple.py abort:TypeError |
"a" % "b" is an odd entry: CPython raises TypeError for that particular pair as well (the table shows what it printed). The probe pins aython’s rule, that every % on a str aborts, which also covers "%d" % 1, where CPython prints 1.
Instances are plain dicts #
A class instance is a dict whose keys are its attribute names, with no class pointer anywhere. Methods are resolved at compile time to flattened functions such as C__get, so nothing at run time needs to know an object’s class (the frontend chapter explains the flattening). That keeps the runtime’s object kinds fixed, and it is why anything that needs to know the class at run time differs: printing an instance, comparing two instances, and failing to find an attribute. A missing attribute is a dict lookup that misses:
tests/mvp/abort_class_missing.py · emitted · main_mainmov [rbp-24], rax # park the owned receiver
# attr key 'nope': copy pooled bytes into a fresh box
lea rdi, .Lstr_1[rip] # key bytes (helper borrows them)
mov rsi, 4 # key length
call str_new # rax = new owned str key (refcnt 1)
mov [rbp-32], rax # park the owned key
...
mov rsi, [rbp-32] # arg2 = key (helper borrows it)
call obj_getitem # rax = owned value (missing aborts KeyError)
mov [rbp-40], rax # park the owned value across the cleanup calls
| Case | aython | CPython | Why | Pinned by |
|---|---|---|---|---|
f"{c}" on a class instance |
Aborts TypeError, as for every value other than an int, str, bool or None in an f-string |
Prints <__main__.C object at 0x…> and exits 0 |
An instance is its namespace dict and carries no class tag, so there is no <C object at ...> to spell |
abort_class_display.py abort:TypeError |
print(c) and repr(c) on a class instance |
Prints the namespace, e.g. {'n': 1} |
Prints <__main__.C object at 0x...> |
Same: the instance is a dict | None. CPython’s line holds an address that changes run to run, so no pass file can match it; the adjacent f-string edge is pinned instead |
c.nope, a missing attribute |
Aborts KeyError: an attribute read is a dict lookup |
AttributeError: 'C' object has no attribute 'nope', exit 1 |
c.nope compiles to obj_getitem on the instance dict with the attribute name as a fresh str key |
abort_class_missing.py abort:KeyError |
c1 == c2 for two instances with equal attributes |
True: dicts compare by content |
False: instances compare by identity |
Same representation; use is for identity |
None. Not in the corpus; recorded in README.md Limits |
c.keys() on an instance whose class defines no keys |
Answers the namespace’s keys | Raises AttributeError |
Method calls that name no user method fall through to the builtin dict methods; that is why builtin method names cannot be user method names | None. Not in the corpus; recorded in docs/core-design.md Classes |
A store to an undeclared attribute on a __slots__-only instance |
Succeeds: the dict accepts any key | Raises AttributeError |
__slots__ declarations are skipped; tracked in issue #72 |
None. It runs to completion here and fails there, which fits no marker: abort needs the ELF to fail |
Errors are a kind, not an object #
When something fails, the runtime does not build an exception object. It jumps to one of eleven stubs, each of which loads a kind id into eax and enters the unwinder; if no handler is waiting, the kind’s name is written to stderr and the process exits with status 1.
| Stub | Kind id | Kind |
|---|---|---|
abort_type |
1 | TypeError |
abort_index |
2 | IndexError |
abort_key |
3 | KeyError |
abort_value |
4 | ValueError |
abort_runtime |
5 | RuntimeError |
abort_zero |
6 | ZeroDivisionError |
abort_overflow |
7 | OverflowError |
abort_memory |
8 | MemoryError |
abort_recursion |
9 | RecursionError |
abort_file |
10 | FileNotFoundError |
abort_notimpl |
11 | NotImplementedError |
runtime.s · abort_msglines 281–319# ---- abort helpers: one shared stub per error kind --------------------
# Each loads its message and falls into abort_msg (write + exit, never
# returns). All runtime helpers jump here; sharing one copy keeps the
# spelling of every message in exactly one place. Exported so generated
# code (arity checks today) can abort the same way helpers do.
.globl abort_msg
.type abort_msg, @function
.globl abort_type
.type abort_type, @function
.globl abort_index
.type abort_index, @function
.globl abort_key
.type abort_key, @function
.globl abort_value
.type abort_value, @function
.globl abort_runtime
.type abort_runtime, @function
.globl abort_zero
.type abort_zero, @function
.globl abort_overflow
.type abort_overflow, @function
.globl abort_memory
.type abort_memory, @function
.globl abort_recursion
.type abort_recursion, @function
.globl abort_file
.type abort_file, @function
.globl abort_notimpl
.type abort_notimpl, @function
abort_msg: # shared abort entry point
and rsp, -16 # noreturn: realign unconditionally (callers arrive
# via mixed call/jmp chains, so entry alignment is unknown)
mov rdx, rsi # rdx gets message length from rsi
mov rsi, rdi # rsi gets message pointer from rdi
mov rdi, 2 # rdi gets stderr fd 2
call write # write message to stderr via libc (errno ignored here)
mov edi, 1 # rdi gets exit status 1
call _exit # terminate via libc, never returns
ud2 # trap in case _exit ever returns
There is no traceback, no message, and no kind outside these 11: no AttributeError, no NameError, no SystemExit. Wherever CPython would raise one of those, aython either refuses the program at compile time or aborts with the nearest kind it has. The judge was built around this: it compares only whether both sides failed and whether both stderrs name the kind (the judge chapter).
| Case | aython | CPython | Why | Pinned by |
|---|---|---|---|---|
| Any uncaught error | One line, aython: ZeroDivisionError, on stderr; exit status 1 |
ZeroDivisionError: division by zero, exit 1 |
An exception is a kind id (1 to 11) plus an unwind; no object, message or frame list exists | err_divzero.py error:ZeroDivisionError |
(1, 2).pop(), a method on the wrong receiver |
Aborts TypeError |
AttributeError: 'tuple' object has no attribute 'pop', exit 1 |
Each method helper checks its receiver’s tag and aborts with the existing kind; there is no AttributeError kind |
abort_method_recv.py abort:TypeError |
exit("boom") |
Aborts TypeError: the status must be an int |
boom, exit 1 |
exit folds an int into the process status and never unwinds |
abort_exit_str.py abort:TypeError |
exit() inside a bare try: ... except: |
Leaves the process; no handler runs | The bare except: catches SystemExit |
exit never unwinds, which matches except Exception but not bare except |
None. Recorded in docs/core-design.md Program input and exit; not in the corpus |
Reading a name assigned on only one side of an if, when the other side ran |
Reads None: every slot starts as None |
Raises NameError |
Slots are initialised once in the prologue; the frontend refuses names never assigned at all, so only maybe-assigned names reach run time | None. Recorded as a gap in codegen.py _prologue_lines; not in the corpus |
x += 1 where x was never assigned |
Aborts TypeError (the slot holds its None initial value) |
Raises NameError |
Every slot starts as None; no NameError kind exists |
None. Recorded in docs/core-design.md Non-goals; not in the corpus |
Memory, depth and recursion #
All memory is one 64 MiB arena mapped at start-up. Object headers are recycled through free lists, while item, byte and entry buffers are never returned. Objects are freed by reference counting alone, with no cycle collector, and the printer and equality walk nested containers by plain recursion with a fixed depth cap:
runtime.s · obj_eqlines 2984–3276obj_eq: # entry: rdi/rsi hold borrowed left/right, returns owned bool
mov rax, [rip + eq_depth] # load current equality nesting depth
cmp rax, 100 # compare against depth cap 100, same as print
jae abort_recursion # abort instead of overflowing native stack
inc qword ptr [rip + eq_depth] # count entering one deeper level
push rbp # save old frame pointer
...
eq_ret: # rax holds owned immortal bool result
dec qword ptr [rip + eq_depth] # count leaving one level
pop r15 # restore callee-saved r15
The cap is a depth, not cycle detection. A self-referential list hits it and aborts instead of overflowing the native stack, which is the point; but an acyclic list nested 101 deep hits it too. repr is different: it keeps a stack of the containers it is inside and spells a cycle as [...], exactly like CPython, so only print and comparison are cut off by the cap.
| Case | aython | CPython | Why | Pinned by |
|---|---|---|---|---|
A list that contains itself, printed: a.append(a); print(a) |
Aborts RecursionError at the print depth cap (100) |
Prints [1, [...]] and exits 0 |
Printing walks nesting with a counter instead of an identity set; repr(a) does keep one and spells [1, [...]] exactly |
abort_recursion_print.py abort:RecursionError |
a == b where a and b contain each other |
Aborts RecursionError at the obj_eq depth cap (100) |
RecursionError: Stack overflow (used 16336 kB) in comparison, exit 1 |
Equality shares the print cap through eq_depth instead of recursing without bound |
abort_eq_cycle.py abort:RecursionError |
a in c over mutually nested lists |
Aborts RecursionError: membership funnels into obj_eq |
RecursionError: Stack overflow (used 16344 kB) in comparison, exit 1 |
Same guard | abort_contains_cycle.py abort:RecursionError |
| An acyclic list nested more than 100 deep, printed or compared | Aborts RecursionError at the same cap |
Prints or compares it | The caps are a fixed depth (cmp rax, 100 in obj_eq and the print walk), not cycle detection |
None. Read from runtime.s; not in the corpus, which pins depth 50 as exact (pass_eq_deep.py, pass_contains_deep.py) |
"x" * 100000000 |
Aborts MemoryError |
Prints 100000000 and exits 0 |
All memory is one 64 MiB arena, mapped once at start-up | abort_oom.py abort:MemoryError |
| Recursion deeper than the native stack | The process faults | Raises RecursionError at its recursion limit |
User calls recurse on the native stack with no depth counter | None. A fault is not an abort line, so no marker fits |
| Reference cycles; objects abandoned mid-expression by an exception | Leak: their arena bytes are never reused | The cycle collector frees cycles | Reference counting only; the frame is discarded whole on unwind, so nothing double-frees | None. Not visible in output; check --leak pins the opposite, that acyclic header-only code is flat |
Hashes and order #
Sets are the one type whose output order depends on hash values. aython’s set is a transliteration of CPython’s own table, so for ints, floats, bools and tuples, whose hashes it reproduces exactly, a set prints and iterates in CPython’s order through every resize. Strings are the exception, on purpose: CPython seeds its string hash per process, so the order of a set of strings changes from one run of CPython to the next. aython hashes strings with FNV-1a, with no seed:
runtime.slines 3935–3957obj_hash_str: # FNV-1a over the string bytes (order-sensitive, stable)
push rbx # save callee-saved rbx (leaf body, keeps frame aligned)
push r12 # save callee-saved r12
mov rbx, [rdi + 24] # rbx = string data pointer
mov r12, [rdi + 16] # r12 = byte length
movabs rax, 0xcbf29ce484222325 # FNV offset basis for 64-bit
test r12, r12 # empty string hashes to the basis itself
jz obj_hash_str_done # skip the loop for ""
obj_hash_str_loop: # one xor-multiply per byte
xor al, [rbx] # fold the next byte into the low byte
mov rcx, 0x100000001b3 # FNV prime for 64-bit (wraps mod 2^64, by design)
imul rax, rcx # multiply by the prime
inc rbx # advance byte pointer
dec r12 # count down remaining bytes
jnz obj_hash_str_loop # hash the next byte
obj_hash_str_done: # rax = FNV-1a of the bytes
cmp rax, -1 # CPython reserves -1 as the error sentinel (never a hash)
jne obj_hash_str_ret # any other value is the hash
mov rax, -2 # -1 maps to -2, exactly like CPython's unicode hash
obj_hash_str_ret: # rax = hash
pop r12 # restore callee-saved r12
pop rbx # restore callee-saved rbx
ret # return hash in rax
None has a fixed hash in aython, the value CPython gave its own None on one build; CPython hashes the object’s address, which can vary:
runtime.slines 3932–3934obj_hash_none: # None hashes by CPython's pointer hash of the singleton
mov eax, 0xfca86420 # _Py_HashPointer(&None) as pinned by CPython 3.14 here
ret # (non-PIE static address, stable per build; re-derive with print(hash(None)))
| Case | aython | CPython | Why | Pinned by |
|---|---|---|---|---|
Iterating, printing or pop of a set that holds strings |
Follows aython’s table, filled with FNV-1a string hashes: the same order every run | Varies run to run: string hashes are seeded per process | A deterministic hash needs no seed; CPython disagrees with itself here | None. CPython has no single answer to compare with; the corpus and the fuzzer never print or iterate such sets |
Order-observable sets that hold None |
None hashes to a fixed constant |
Hashes the singleton’s address, which can vary | The constant is CPython’s value as pinned on one build | None. Kept order-free in the corpus, like strings |
hash of a NaN key |
0 | A pointer hash | Unobservable: nan != nan, so only the identical object can hit, and dict_lookup tests identity before it compares hashes |
None. No output differs |
None of these can be a corpus case: there is no single CPython answer to compare against. The corpus and the fuzzer therefore never print, iterate or pop a set that holds strings; membership, length, equality and mutation are exact and are tested.
Builtins and operators #
The remaining differences come from what the subset leaves out: lazy iterators, view objects, a complex type, slices as values, and the compile-time sharing of constants.
| Case | aython | CPython | Why | Pinned by |
|---|---|---|---|---|
print(enumerate(a)), zip, reversed |
Prints a list: these build a fresh list | Prints an iterator object | Lazy iterator objects are out of scope; inside a for the two agree |
None. CPython’s line holds an address; the fuzzer uses them only as for iterables |
print(d.items()), keys(), values() |
Prints a list (of 2-element lists for items) |
Prints a view, e.g. dict_items([('a', 1)]) |
No view objects exist; the methods return fresh lists | None. Not in the corpus; recorded in docs/core-design.md Methods |
a = 1000; b = 1000; a is b |
False: each literal is boxed by its own int_new |
True when its compiler shares the constant, as it does in one script |
Every display and literal outside the small-int cache builds a fresh object (except ()); is is a pointer compare |
None. CPython’s answer depends on how it folds constants, so the corpus compares with == |
f"{[1]}", a list in an f-string |
Aborts TypeError: f-strings spell int, str, bool and None only |
Prints [1] and exits 0 |
Interpolation goes through str_of_value, which covers the scalars |
abort_fstring_list.py abort:TypeError |
f"{s}" for a set s |
Aborts TypeError |
Prints {1, 2} and exits 0 |
Same | abort_fstring_set.py abort:TypeError |
(-2.0) ** 0.5 |
Aborts ValueError |
Prints (8.659560562354934e-17+1.4142135623730951j) and exits 0 |
There is no complex type | err_power_value.py abort:ValueError |
d[1:2] = [1] on a dict |
Aborts TypeError, as for any non-list slice store |
Runs to exit 0, printing nothing | A slice is not a value in the subset, so it cannot be a key | abort_slice_store_dict.py abort:TypeError |
del d[1:2] on a dict |
Aborts TypeError |
KeyError: slice(1, 2, None), exit 1 |
Same | abort_slice_del_dict.py abort:TypeError |
argv()[0] |
The ELF’s path | The shimmed argv() returns sys.argv, whose first item is the source path |
Each side reports the program it actually ran | None. Corpus programs compare argv()[1:] only; the fuzzer never reads [0] |
What is not on this list #
- Refusals. Generator expressions,
with,lambda,int()andfloat(),str.formatand the rest of the 71rejectcases are not differences in behaviour: the program never runs. Onlyrej_nonstr.pyis listed above, because the ASCII rule shows up at run time too. - Things CPython does not guarantee. Addresses in
repr, the order of a set of strings, and which constants are shared are not part of Python’s meaning; aython’s answers are as valid as CPython’s, they just are not the same bytes. - Speed. Timing is a separate question, treated in the speed chapter.
- Unrecorded differences. This list is everything the repository records. A difference nobody has noticed is not here; the fuzzer exists to find those, and each one it finds becomes either a fix or a new
abort:file.
Where this lives #
| Concept | Where |
|---|---|
| The recorded limits | README.md “Limits”; docs/core-design.md Program contract, Non-goals, Later |
| The probes | tests/mvp/ abort_*.py, err_io_nonascii.py, err_power_value.py, err_power_overflow.py |
How an abort probe is judged |
src/aython/judge.py _check_abort |
| 64-bit overflow checks | runtime.s int_add, int_sub, int_mul (jo abort_overflow) |
| ASCII checks | runtime.s chr_new; src/aython/frontend.py (non-ASCII literal refusal) |
| Instances as dicts | src/aython/codegen.py attribute reads through obj_getitem |
| Kinds and the abort path | runtime.s abort_msg, abort_type … abort_notimpl, exc_check |
| Depth caps | runtime.s obj_eq (eq_depth), aython_print_obj (print_depth) |
| Hashes | runtime.s obj_hash (obj_hash_str, obj_hash_none), obj_hash_float |
| The fuzzer’s avoidance rules | src/aython/fuzz.py module docstring, KNOWN_DIVERGENCE, compare_runs |
| This page’s table | docsite/figures/limits.py; CPython’s side from docsite/figures/judgecorpus.py |
Check yourself #
Check yourself
x = 2**62 * 4is the body of atrywhose handler isexcept OverflowError:, and the handler printsbig. What do the two sides print?- Both print
big - aython prints
big; CPython prints nothing, because nothing is raised - aython aborts
OverflowErrorbecause aborts cannot be caught
Answer
aython printsbig; CPython prints nothing, because nothing is raised. An abort is an ordinary unwind with kind 7, so a matching handler catches it. CPython computes the product and never enters the handler.- Both print
Why can the
__slots__store divergence (issue #72) not be a corpus file?- It crashes the frontend
- aython succeeds where CPython fails, and
abortrequires the ELF to fail whilepassrequires CPython to succeed - The judge does not run class programs
Answer
aython succeeds where CPython fails, andabortrequires the ELF to fail whilepassrequires CPython to succeed. No marker describes ‘ELF exits 0, CPython raises’.errorneeds both to fail,abortneeds the ELF to fail,passneeds both to succeed with the same bytes.Why does aython hash strings with FNV-1a instead of CPython’s algorithm?
- FNV-1a is faster on x86-64
- CPython seeds its string hash per process, so there is no fixed order to match; a deterministic hash needs no seed
- CPython also uses FNV-1a
Answer
CPython seeds its string hash per process, so there is no fixed order to match; a deterministic hash needs no seed. Matching CPython exactly would still not match CPython, because CPython changes its own order from run to run. For ints, floats, bools and tuples aython reproduces CPython’s hashes and order exactly.c.nopeon an instance with no attributenopeabortsKeyError, notAttributeError. Why?- The instance is a dict, the read is a dict lookup with the key
'nope', and aython has noAttributeErrorkind - A bug in
obj_getitem - CPython also raises
KeyErrorthere
Answer
The instance is a dict, the read is a dict lookup with the key'nope', and aython has noAttributeErrorkind. Attribute reads compile toobj_getitemon the instance dict. The eleven kinds have noAttributeError, and a missed dict lookup isKeyError.- The instance is a dict, the read is a dict lookup with the key
A program prints a list nested 150 deep, with no cycle. What happens?
- Both sides print it
- aython aborts
RecursionErrorat the print depth cap; CPython prints it - aython prints
[...]at depth 100
Answer
aython abortsRecursionErrorat the print depth cap; CPython prints it. The printer’s guard counts depth and aborts past 100. It does not look for cycles;repr, which does, would still print the list.