1651. gopy modules
What we are porting
Three companion modules that the runtime hands to user code as
soon as Py_Initialize returns:
Python/bltinmodule.c(the v0.7 subset listed below). Thebuiltinsmodule:print,len,range,iter,abs,type,isinstance,repr,str,int,float,list,tuple,dict,set,getattr,setattr,hasattr,callable,id,hash,sorted,reversed,enumerate,zip,map,filter,sum,min,max,any,all,divmod,pow,chr,ord,bin,oct,hex,ascii,format,vars,dir.Python/sysmodule.c(the v0.7 subset). Thesysmodule:path,modules,argv,version,version_info,flags,implementation,stdin,stdout,stderr,exit,getrefcount,setrecursionlimit,getrecursionlimit,executable,platform,byteorder,maxsize,intern.Python/_warnings.c(~1.5k lines). The_warningsmodule that backswarnings.warn. Includes the filter list, the default actions, and the once-per-location dedup.Python/_contextvars.cis a one-line module init hook; the actual ContextVar implementation lives in spec 1663 (v0.9). v0.7 ships the import hook only soimport _contextvarsworks.
Why this lands in v0.7
Py_Initialize (spec 1622) must produce a usable interpreter,
which means print, len, range and sys.path have to be
populated by the time pythonrun.RunString (spec 1624) takes
over. The v0.6 builtins package shipped just print; v0.7
fills in the rest.
_warnings has to land in v0.7 because DeprecationWarning
and PendingDeprecationWarning are emitted from the eval
loop and codecs paths gopy already exercises.
Package layout
gopy/builtins/
init.go # _PyBuiltin_Init: registers everything below
abs.go # abs / divmod / pow / round
bool_int_float.go # bool / int / float / complex
bytes_str.go # bytes / bytearray / str / chr / ord / ascii / bin / oct / hex
collections.go # list / tuple / dict / set / frozenset
iters.go # iter / next / reversed / enumerate / zip / map / filter
reflect.go # type / isinstance / issubclass / getattr / setattr / hasattr
# delattr / vars / dir / id / hash / callable / repr
sequence_aggs.go # sum / min / max / any / all / sorted / len
format.go # format / range / slice
exec_eval.go # exec / eval / compile (stubbed v0.7; full v0.8)
gopy/sysmod/
init.go # _PySys_Create
attributes.go # path, argv, version, flags, implementation
recursion.go # set/getrecursionlimit, getrefcount
io.go # stdin/stdout/stderr placeholders (real wiring in v0.8)
intern.go
gopy/warnings/
warnings.go # _Py_Warn family
filters.go # filter list and default actions
registry.go # __warningregistry__ per-module dedup
v0.7 release blockers
builtins (spec drives ~30 individual tasks; grouped in the release rollup):
1651-builtins-Alen,iter,next,reversed,enumerate,zip,range. The iteration panel.1651-builtins-Btype,isinstance,issubclass,callable,id,hash,repr,str. The reflection panel.1651-builtins-Cgetattr,setattr,hasattr,delattr,vars,dir. The attribute panel.1651-builtins-Dsum,min,max,any,all,sorted. The aggregation panel (sorted needs Timsort from spec 1679 which is already in objects).1651-builtins-Eabs,divmod,pow,chr,ord,bin,oct,hex,ascii,format. The numeric and formatting panel.1651-builtins-FConstructor wrappersint(...),float(...),bool(...),list(...),tuple(...),dict(...),set(...). These call into the existing object ports.
sys:
1651-sys-A_PySys_Createplus the static attribute panel (version, version_info, platform, byteorder, maxsize, implementation). CPython:Python/sysmodule.c:_PySys_Create.1651-sys-Bsys.path,sys.argv,sys.modulespopulated fromPyConfig(1622).1651-sys-Csys.flagsnamed-tuple bound to thePyConfigint fields.1651-sys-Dsys.exit,sys.setrecursionlimit,sys.getrecursionlimit,sys.getrefcount,sys.intern.1651-sys-EPinsys.implementation.name == "gopy"andsys.implementation.cache_tag == "gopy-3140"per spec 1690.
_warnings:
1651-warn-APort_Py_Warn,_Py_Warn_NoCharField, the filter list, and the default rule set.1651-warn-BPer-module__warningregistry__dedup.1651-warn-Csimplefilter,filterwarnings,resetwarningsso user code can install filters.
Test gates
builtins/init_test.go: afterInit, the returned globals dict has every name from the v0.7 panel.builtins/print_test.go(already in v0.6) keeps passing.builtins/<file>_test.go: table-driven tests per file comparing gopy output topython3 -c "print(<expr>)".sysmod/sysmod_test.go:sys.version_infois the right named tuple;sys.path[0]is the script directory after Main runs against a script.warnings/warnings_test.go: install a filter, emit a warning, assert__warningregistry__carries the entry and the second emission is suppressed.
Out of scope
compile,exec,evalbuiltins land as stubs that call through to the v0.6 parser+compile+vm pipeline only when the caller passes pre-validated source. The full PEP 263 source encoding handshake is deferred to v0.8 with import.breakpoint()is not wired (depends on monitor; v0.11).help(),copyright(),credits(),license()are not wired (they live insite.py).