Errors, traceback, and the refcount path of the GC. After v0.3 a Go caller can raise a Python exception, catch it, walk the chain, and format a traceback. The interpreter still does not run Python code.
Port of cpython/Python/errors.c and cpython/Objects/exceptions.c
gating subset:
Set,SetString,Format,Occurred,Clear,Fetch,Restore,Raise,RaiseFrom,NormalizeException,AttachTraceback,Print,FormatException,Match,IsSubtype.- Exception class hierarchy (matches CPython MRO):
BaseException,Exception,LookupError,KeyError,IndexError,ArithmeticError,OverflowError,ZeroDivisionError,RuntimeError,NotImplementedError,AttributeError,NameError,TypeError,ValueError,StopIteration.OSError,ImportError, and theWarningsubtree land in later phases as callers need them. KeyError.__str__override that wraps a single arg viarepr.__cause__/__context__chaining viaRaise/RaiseFromplus__suppress_context__.
Port of cpython/Python/traceback.c:
TracebackEntry(file, line, name).Format,FormatException,Print.- Hook points for the VM to push frames; in v0.3 the VM is absent so
entries are pushed by
errors.Set*directly from the Go call site.
Port of cpython/Python/suggestions.c:
SuggestAttr(obj, name) stringforAttributeError.SuggestKey(mapping, key) stringforKeyError.- Levenshtein distance with the small-distance fast path.
Port of the rc-only path in cpython/Python/gc.c:
RegisterFinalizer,Finalize,Track,Untrack.- Cycle collection is a no-op in v0.3; the cycle collector lands in v0.10.
Port of cpython/Python/brc.c field layout only:
BiasedRefcountstruct with the per-thread queue header.- All ops are no-ops in the GIL build.
Port of the structs from cpython/Python/pystate.c:
Runtime,Interpreter,Threadstructs. No init flow yet (that arrives in v0.7 withpylifecycle).Thread.exccarries the current exception soerrors.Occurred(ts)has somewhere to read.
ts := state.NewThread()
errors.SetString(ts, errors.PyExc_ValueError, "boom")
exc := errors.Occurred(ts)
if exc == nil {
t.Fatal("expected exception")
}
errors.AttachTraceback(ts, traceback.Entry{File: "a.py", Line: 1, Name: "f"})
out := errors.FormatException(errors.Occurred(ts))
if len(out) == 0 {
t.Fatal("empty traceback")
}- Go: 1.26 or newer.
- CPython behavioural target: 3.14.0+.
- Exception messages must match CPython byte for byte for the leaves v0.3 ships.
- Cycle collector. v0.10.
- Free-threading exception slot. v0.14.
qsbrandfinalize-on-resurrect. v0.10 / v0.14.- Real frames in tracebacks. The VM lands in v0.6.