Files
Viper_RegressionTesting/CPythonTest/App/cpython.vp
T
TermiNexus ee6461be46 chore(comments): Test 仓注释英文化(R11)
把 81 个 .vp 文件的中文 # 注释与三引号文档串改写为简洁英文,每个连续注释块 <=2 行;运行时中文字符串字面量(testcheck.begin/print 等用户可见消息)保持原样。骨架比对 HEAD 与工作区 112 文件漂移 0,全量 77/77 顺序回归通过。
2026-10-05 22:43:38 +08:00

708 lines
27 KiB
Plaintext

import t, c
# --- PyObject: base class of all Python objects ---
class PyObject:
ob_refcnt: t.CLong
ob_type: t.CPtr
# --- Reference counting ---
extern def Py_INCREF(op: PyObject*)
extern def Py_DECREF(op: PyObject*)
extern def Py_XINCREF(op: PyObject*)
extern def Py_XDECREF(op: PyObject*)
extern def Py_DecRef(op: PyObject*)
# --- Interpreter init/finalize ---
extern def Py_Initialize()
extern def Py_Finalize()
extern def Py_InitializeEx(initsigs: int)
extern def Py_FinalizeEx() -> int
extern def Py_IsInitialized() -> int
# --- PyConfig ---
class PySTATUS:
func: const str
err_msg: const str
exitcode: int
class PyPreConfig:
_config_version: int
_config_init: int
parse_argv: int
isolated: int
use_environment: int
utf8_mode: int
coerce_c_locale: int
C_locale_warnings: int
allocator: int
dev_mode: int
class PyWideStringList:
length: sizet
items: t.CPtr
class PyConfig:
_config_version: int
_config_init: int
isolated: int
use_environment: int
dev_mode: int
install_signal_handlers: int
use_hash_seed: int
hash_seed: t.CUnsignedLong
faulthandler: int
tracemalloc: int
import_time: int
show_ref_count: int
dump_refs: int
dump_refs_file: const str
malloc_stats: int
filesystem_errors: int
pycache_prefix: const str
parse_argv: int
argv: PyWideStringList
program_name: const str
xoptions: PyWideStringList
warnoptions: PyWideStringList
site_import: int
bytes_warning: int
warn_default_encoding: int
inspect: int
interactive: int
optimization_level: int
parser_debug: int
verbose: int
quiet: int
home: const str
pythonpath_env: const str
module_search_paths: PyWideStringList
module_search_paths_set: int
executable: const str
base_executable: const str
prefix: const str
base_prefix: const str
exec_prefix: const str
base_exec_prefix: const str
platlibdir: const str
stdio_filename: const str
extern def PyConfig_InitPythonConfig(config: PyConfig*)
extern def PyConfig_InitIsolatedConfig(config: PyConfig*)
extern def PyConfig_Clear(config: PyConfig*)
extern def PyConfig_Read(config: PyConfig*) -> PySTATUS
extern def Py_InitializeFromConfig(config: PyConfig*) -> PySTATUS
extern def Py_DecodeLocale(s: const str) -> str
extern def PyStatus_Exception(status: PySTATUS) -> int
# --- Integer ops (PyLong) ---
extern def PyLong_FromLong(v: int) -> PyObject*
extern def PyLong_FromUnsignedLong(v: t.CUnsignedLong) -> PyObject*
extern def PyLong_FromLongLong(v: t.CLong) -> PyObject*
extern def PyLong_FromUnsignedLongLong(v: t.CUnsignedLong) -> PyObject*
extern def PyLong_FromSsize_t(v: t.CPtrDiffT) -> PyObject*
extern def PyLong_FromSize_t(v: sizet) -> PyObject*
extern def PyLong_FromDouble(v: double) -> PyObject*
extern def PyLong_AsLong(obj: PyObject*) -> int
extern def PyLong_AsUnsignedLong(obj: PyObject*) -> t.CUnsignedLong
extern def PyLong_AsLongLong(obj: PyObject*) -> t.CLong
extern def PyLong_AsUnsignedLongLong(obj: PyObject*) -> t.CUnsignedLong
extern def PyLong_AsDouble(obj: PyObject*) -> double
extern def PyLong_AsSsize_t(obj: PyObject*) -> t.CPtrDiffT
extern def PyLong_AsSize_t(obj: PyObject*) -> sizet
# --- Float ops (PyFloat) ---
extern def PyFloat_FromDouble(v: double) -> PyObject*
extern def PyFloat_AsDouble(obj: PyObject*) -> double
extern def PyFloat_FromString(s: PyObject*) -> PyObject*
# --- String ops (PyUnicode / PyBytes) ---
extern def PyUnicode_FromString(u: const str) -> PyObject*
extern def PyUnicode_FromStringAndSize(u: const str, size: sizet) -> PyObject*
extern def PyUnicode_FromFormat(fmt: const str) -> PyObject*
extern def PyUnicode_AsUTF8(obj: PyObject*) -> str
extern def PyUnicode_AsUTF8AndSize(obj: PyObject*, size: t.CPtrDiffT*) -> str
extern def PyUnicode_AsWideChar(obj: PyObject*, wbuf: t.CPtr, bufsize: sizet) -> sizet
extern def PyUnicode_GetLength(obj: PyObject*) -> t.CPtrDiffT
extern def PyUnicode_ReadChar(obj: PyObject*, idx: sizet) -> uint32
extern def PyUnicode_WriteChar(obj: PyObject*, idx: sizet, ch: uint32) -> int
extern def PyUnicode_Compare(l: PyObject*, r: PyObject*) -> int
extern def PyUnicode_Concat(l: PyObject*, r: PyObject*) -> PyObject*
extern def PyUnicode_Contains(container: PyObject*, element: PyObject*) -> int
extern def PyUnicode_Format(fmt: PyObject*, args: PyObject*) -> PyObject*
extern def PyUnicode_InternInPlace(s: PyObject**): pass
extern def PyUnicode_InternFromString(u: const str) -> PyObject*
extern def PyBytes_FromString(v: const str) -> PyObject*
extern def PyBytes_FromStringAndSize(v: const str, size: sizet) -> PyObject*
extern def PyBytes_AsString(obj: PyObject*) -> str
extern def PyBytes_Size(obj: PyObject*) -> sizet
extern def PyBytes_FromObject(o: PyObject*) -> PyObject*
extern def PyBytes_FromFormat(fmt: const str) -> PyObject*
# --- Bool / None ---
extern def PyBool_FromLong(v: t.CLong) -> PyObject*
Py_True: PyObject | t.CPtr | t.State
Py_False: PyObject | t.CPtr | t.State
Py_None: PyObject | t.CPtr | t.State
# --- List ops (PyList) ---
extern def PyList_New(len: sizet) -> PyObject*
extern def PyList_Size(lst: PyObject*) -> sizet
extern def PyList_GetItem(lst: PyObject*, idx: sizet) -> PyObject*
extern def PyList_SetItem(lst: PyObject*, idx: sizet, item: PyObject*) -> int
extern def PyList_Insert(lst: PyObject*, idx: sizet, item: PyObject*) -> int
extern def PyList_Append(lst: PyObject*, item: PyObject*) -> int
extern def PyList_GetSlice(lst: PyObject*, lo: sizet, hi: sizet) -> PyObject*
extern def PyList_SetSlice(lst: PyObject*, lo: sizet, hi: sizet, items: PyObject*) -> int
extern def PyList_Sort(lst: PyObject*) -> int
extern def PyList_Reverse(lst: PyObject*) -> int
extern def PyList_AsTuple(lst: PyObject*) -> PyObject*
# --- Tuple ops (PyTuple) ---
extern def PyTuple_New(len: sizet) -> PyObject*
extern def PyTuple_Size(tup: PyObject*) -> sizet
extern def PyTuple_GetItem(tup: PyObject*, idx: sizet) -> PyObject*
extern def PyTuple_SetItem(tup: PyObject*, idx: sizet, item: PyObject*) -> int
extern def PyTuple_GetSlice(tup: PyObject*, lo: sizet, hi: sizet) -> PyObject*
extern def PyTuple_Pack(n: sizet) -> PyObject*
# --- Dict ops (PyDict) ---
extern def PyDict_New() -> PyObject*
extern def PyDict_GetItem(d: PyObject*, key: PyObject*) -> PyObject*
extern def PyDict_GetItemString(d: PyObject*, key: const str) -> PyObject*
extern def PyDict_SetItem(d: PyObject*, key: PyObject*, val: PyObject*) -> int
extern def PyDict_SetItemString(d: PyObject*, key: const str, val: PyObject*) -> int
extern def PyDict_DelItem(d: PyObject*, key: PyObject*) -> int
extern def PyDict_DelItemString(d: PyObject*, key: const str) -> int
extern def PyDict_Size(d: PyObject*) -> sizet
extern def PyDict_Keys(d: PyObject*) -> PyObject*
extern def PyDict_Values(d: PyObject*) -> PyObject*
extern def PyDict_Items(d: PyObject*) -> PyObject*
extern def PyDict_Copy(d: PyObject*) -> PyObject*
extern def PyDict_Clear(d: PyObject*): pass
extern def PyDict_Contains(d: PyObject*, key: PyObject*) -> int
extern def PyDict_Next(d: PyObject*, pos: t.CPtrDiffT*, key: PyObject**, val: PyObject**) -> int
extern def PyDict_Merge(d: PyObject*, other: PyObject*, override: int) -> int
extern def PyDict_Update(d: PyObject*, other: PyObject*) -> int
# --- Object common ops ---
extern def PyObject_Str(obj: PyObject*) -> PyObject*
extern def PyObject_Repr(obj: PyObject*) -> PyObject*
extern def PyObject_Type(obj: PyObject*) -> PyObject*
extern def PyObject_IsInstance(obj: PyObject*, cls: PyObject*) -> int
extern def PyObject_IsSubclass(obj: PyObject*, cls: PyObject*) -> int
extern def PyObject_HasAttr(obj: PyObject*, name: PyObject*) -> int
extern def PyObject_HasAttrString(obj: PyObject*, name: const str) -> int
extern def PyObject_GetAttr(obj: PyObject*, name: PyObject*) -> PyObject*
extern def PyObject_GetAttrString(obj: PyObject*, name: const str) -> PyObject*
extern def PyObject_SetAttr(obj: PyObject*, name: PyObject*, val: PyObject*) -> int
extern def PyObject_SetAttrString(obj: PyObject*, name: const str, val: PyObject*) -> int
extern def PyObject_DelAttr(obj: PyObject*, name: PyObject*) -> int
extern def PyObject_DelAttrString(obj: PyObject*, name: const str) -> int
extern def PyObject_Call(callable: PyObject*, args: PyObject*, kwargs: PyObject*) -> PyObject*
extern def PyObject_CallObject(callable: PyObject*, args: PyObject*) -> PyObject*
extern def PyObject_CallNoArgs(callable: PyObject*) -> PyObject*
extern def PyObject_CallOneArg(callable: PyObject*, arg: PyObject*) -> PyObject*
extern def PyObject_IsTrue(obj: PyObject*) -> int
extern def PyObject_Not(obj: PyObject*) -> int
extern def PyObject_RichCompare(o1: PyObject*, o2: PyObject*, opid: int) -> PyObject*
extern def PyObject_RichCompareBool(o1: PyObject*, o2: PyObject*, opid: int) -> int
extern def PyObject_Hash(obj: PyObject*) -> t.CLong
extern def PyObject_Length(obj: PyObject*) -> sizet
extern def PyObject_GetItem(obj: PyObject*, key: PyObject*) -> PyObject*
extern def PyObject_SetItem(obj: PyObject*, key: PyObject*, val: PyObject*) -> int
extern def PyObject_DelItem(obj: PyObject*, key: PyObject*) -> int
extern def PyObject_Dir(obj: PyObject*) -> PyObject*
extern def PyObject_GetIter(obj: PyObject*) -> PyObject*
extern def PyIter_Next(obj: PyObject*) -> PyObject*
# --- Comparison constants ---
Py_LT: int | t.State
Py_LE: int | t.State
Py_EQ: int | t.State
Py_NE: int | t.State
Py_GT: int | t.State
Py_GE: int | t.State
# --- Module ops ---
extern def PyImport_ImportModule(name: const str) -> PyObject*
extern def PyImport_Import(name: PyObject*) -> PyObject*
extern def PyImport_ImportModuleLevelObject(name: PyObject*, globs: PyObject*, locs: PyObject*, fromlist: PyObject*, level: int) -> PyObject*
extern def PyImport_ReloadModule(mod: PyObject*) -> PyObject*
extern def PyImport_AddModule(name: const str) -> PyObject*
extern def PyImport_GetModuleDict() -> PyObject*
extern def PyImport_ImportModuleEx(name: const str, globs: PyObject*, locs: PyObject*, fromlist: PyObject*) -> PyObject*
# --- Module creation ---
class PyMethodDef:
ml_name: const str
ml_meth: t.CPtr
ml_flags: int
ml_doc: const str
class PyModuleDef_Base:
ob_base: PyObject
m_init: t.CPtr
m_index: sizet
m_copy: PyObject*
class PyModuleDef:
m_base: PyModuleDef_Base
m_name: const str
m_doc: const str
m_size: t.CPtrDiffT
m_methods: PyMethodDef*
m_slots: t.CPtr
m_traverse: t.CPtr
m_clear: t.CPtr
m_free: t.CPtr
extern def PyModule_Create(mod: PyModuleDef*) -> PyObject*
extern def PyModule_Create2(mod: PyModuleDef*, ver: int) -> PyObject*
extern def PyModule_GetName(mod: PyObject*) -> str
extern def PyModule_GetDict(mod: PyObject*) -> PyObject*
extern def PyModule_GetFilenameObject(mod: PyObject*) -> PyObject*
extern def PyModule_AddObject(mod: PyObject*, name: const str, val: PyObject*) -> int
extern def PyModule_AddObjectRef(mod: PyObject*, name: const str, val: PyObject*) -> int
extern def PyModule_AddIntConstant(mod: PyObject*, name: const str, val: t.CLong) -> int
extern def PyModule_AddStringConstant(mod: PyObject*, name: const str, val: const str) -> int
# --- GIL management ---
extern def PyGILState_Ensure() -> int
extern def PyGILState_Release(state: int): pass
extern def PyEval_SaveThread() -> t.CPtr
extern def PyEval_RestoreThread(tstate: t.CPtr): pass
extern def PyEval_AcquireThread(tstate: t.CPtr): pass
extern def PyEval_ReleaseThread(tstate: t.CPtr): pass
extern def PyEval_AcquireLock(): pass
extern def PyEval_ReleaseLock(): pass
extern def PyEval_ThreadsInitialized() -> int
extern def PyEval_InitThreads(): pass
# --- Error handling ---
extern def PyErr_Occurred() -> PyObject*
extern def PyErr_Clear(): pass
extern def PyErr_Fetch(tp: PyObject**, val: PyObject**, tb: PyObject**): pass
extern def PyErr_Restore(tp: PyObject*, val: PyObject*, tb: PyObject*): pass
extern def PyErr_NormalizeException(tp: PyObject**, val: PyObject**, tb: PyObject**): pass
extern def PyErr_SetString(tp: PyObject*, msg: const str): pass
extern def PyErr_SetObject(tp: PyObject*, val: PyObject*): pass
extern def PyErr_BadArgument() -> t.CPtr | t.State: pass
extern def PyErr_NoMemory() -> t.CPtr | t.State: pass
extern def PyErr_Print(): pass
extern def PyErr_ExceptionMatches(exc: PyObject*) -> int | t.State: pass
extern def PyErr_GivenExceptionMatches(given: PyObject*, exc: PyObject*) -> int | t.State: pass
# --- Built-in exception types ---
PyExc_BaseException: PyObject | t.CPtr | t.State
PyExc_Exception: PyObject | t.CPtr | t.State
PyExc_TypeError: PyObject | t.CPtr | t.State
PyExc_ValueError: PyObject | t.CPtr | t.State
PyExc_RuntimeError: PyObject | t.CPtr | t.State
PyExc_KeyError: PyObject | t.CPtr | t.State
PyExc_IndexError: PyObject | t.CPtr | t.State
PyExc_AttributeError: PyObject | t.CPtr | t.State
PyExc_ImportError: PyObject | t.CPtr | t.State
PyExc_OSError: PyObject | t.CPtr | t.State
PyExc_IOError: PyObject | t.CPtr | t.State
PyExc_ZeroDivisionError: PyObject | t.CPtr | t.State
PyExc_OverflowError: PyObject | t.CPtr | t.State
PyExc_MemoryError: PyObject | t.CPtr | t.State
PyExc_NameError: PyObject | t.CPtr | t.State
PyExc_StopIteration: PyObject | t.CPtr | t.State
PyExc_NotImplementedError: PyObject | t.CPtr | t.State
PyExc_SyntaxError: PyObject | t.CPtr | t.State
PyExc_FileNotFoundError: PyObject | t.CPtr | t.State
PyExc_PermissionError: PyObject | t.CPtr | t.State
PyExc_IsADirectoryError: PyObject | t.CPtr | t.State
PyExc_NotADirectoryError: PyObject | t.CPtr | t.State
# --- Built-in functions ---
extern def Py_BuildValue(fmt: const str) -> PyObject*
extern def Py_VaBuildValue(fmt: const str, va: t.CPtr) -> PyObject*
# --- Type checks ---
extern def PyLong_Check(obj: PyObject*) -> int
extern def PyFloat_Check(obj: PyObject*) -> int
extern def PyUnicode_Check(obj: PyObject*) -> int
extern def PyBytes_Check(obj: PyObject*) -> int
extern def PyList_Check(obj: PyObject*) -> int
extern def PyTuple_Check(obj: PyObject*) -> int
extern def PyDict_Check(obj: PyObject*) -> int
extern def PyBool_Check(obj: PyObject*) -> int
extern def PyNone_Check(obj: PyObject*) -> int
# --- Memory management ---
extern def PyMem_Malloc(size: sizet) -> t.CPtr
extern def PyMem_Realloc(ptr: t.CPtr, size: sizet) -> t.CPtr
extern def PyMem_Free(ptr: t.CPtr)
extern def PyMem_Calloc(nelem: sizet, elsize: sizet) -> t.CPtr
extern def PyObject_Malloc(size: sizet) -> t.CPtr
extern def PyObject_Realloc(ptr: t.CPtr, size: sizet) -> t.CPtr
extern def PyObject_Free(ptr: t.CPtr)
extern def PyObject_Calloc(nelem: sizet, elsize: sizet) -> t.CPtr
extern def PyObject_Init(obj: PyObject*, tp: t.CPtr) -> PyObject*
extern def PyObject_InitVar(obj: PyObject*, tp: t.CPtr, size: sizet) -> PyObject*
# --- File ops ---
extern def PyFile_FromString(filename: const str, mode: const str) -> PyObject*
extern def PyFile_AsFile(file: PyObject*) -> t.CPtr
extern def PyFile_WriteObject(obj: PyObject*, file: PyObject*, flags: int) -> int
extern def PyFile_WriteString(s: const str, file: PyObject*) -> int
# --- Compile/execute ---
extern def Py_CompileString(s: const str, filename: const str, start: int) -> PyObject*
extern def PyEval_EvalCode(code: PyObject*, globs: PyObject*, locs: PyObject*) -> PyObject*
extern def PyEval_EvalCodeEx(code: PyObject*, globs: PyObject*, locs: PyObject*, args: PyObject**, argc: int, kws: PyObject**, kwc: int, defs: PyObject**, defc: int, kwdefs: PyObject*, closure: PyObject*) -> PyObject*: pass
extern def PyEval_EvalFrame(frame: t.CPtr) -> PyObject*: pass
extern def PyEval_CallObject(callable: PyObject*, args: PyObject*) -> PyObject*: pass
extern def PyEval_CallFunction(callable: PyObject*, fmt: const str) -> PyObject*: pass
extern def PyEval_CallMethod(obj: PyObject*, method: const str, fmt: const str) -> PyObject*: pass
# --- PyRun ---
extern def PyRun_SimpleString(cmd: const str) -> int
extern def PyRun_SimpleFile(fp: t.CPtr, filename: const str) -> int
extern def PyRun_AnyFile(fp: t.CPtr, filename: const str) -> int
extern def PyRun_String(s: const str, start: int, globs: PyObject*, locs: PyObject*) -> PyObject*
extern def PyRun_File(fp: t.CPtr, filename: const str, start: int, globs: PyObject*, locs: PyObject*) -> PyObject*
Py_single_input: int | t.State
Py_file_input: int | t.State
Py_eval_input: int | t.State
# --- Capsule ---
extern def PyCapsule_New(ptr: t.CPtr, name: const str, dtor: t.CPtr) -> PyObject*
extern def PyCapsule_GetPointer(cap: PyObject*, name: const str) -> t.CPtr
extern def PyCapsule_GetName(cap: PyObject*) -> str
extern def PyCapsule_IsValid(cap: PyObject*, name: const str) -> int
extern def PyCapsule_SetPointer(cap: PyObject*, ptr: t.CPtr) -> int
extern def PyCapsule_SetName(cap: PyObject*, name: const str) -> int
extern def PyCapsule_SetDestructor(cap: PyObject*, dtor: t.CPtr) -> int
# --- Sequence ops ---
extern def PySequence_Check(obj: PyObject*) -> int
extern def PySequence_Size(obj: PyObject*) -> sizet
extern def PySequence_Length(obj: PyObject*) -> sizet
extern def PySequence_Concat(o1: PyObject*, o2: PyObject*) -> PyObject*
extern def PySequence_Repeat(obj: PyObject*, count: sizet) -> PyObject*
extern def PySequence_GetItem(obj: PyObject*, idx: sizet) -> PyObject*
extern def PySequence_SetItem(obj: PyObject*, idx: sizet, val: PyObject*) -> int
extern def PySequence_DelItem(obj: PyObject*, idx: sizet) -> int
extern def PySequence_GetSlice(obj: PyObject*, start: sizet, end: sizet) -> PyObject*
extern def PySequence_SetSlice(obj: PyObject*, start: sizet, end: sizet, val: PyObject*) -> int
extern def PySequence_DelSlice(obj: PyObject*, start: sizet, end: sizet) -> int
extern def PySequence_Contains(obj: PyObject*, val: PyObject*) -> int
extern def PySequence_Index(obj: PyObject*, val: PyObject*) -> sizet
extern def PySequence_Count(obj: PyObject*, val: PyObject*) -> sizet
extern def PySequence_List(obj: PyObject*) -> PyObject*
extern def PySequence_Tuple(obj: PyObject*) -> PyObject*
# --- Mapping ops ---
extern def PyMapping_Check(obj: PyObject*) -> int
extern def PyMapping_Size(obj: PyObject*) -> sizet
extern def PyMapping_Length(obj: PyObject*) -> sizet
extern def PyMapping_HasKey(obj: PyObject*, key: PyObject*) -> int
extern def PyMapping_HasKeyString(obj: PyObject*, key: const str) -> int
extern def PyMapping_GetItemString(obj: PyObject*, key: const str) -> PyObject*
extern def PyMapping_SetItemString(obj: PyObject*, key: const str, val: PyObject*) -> int
extern def PyMapping_Keys(obj: PyObject*) -> PyObject*
extern def PyMapping_Values(obj: PyObject*) -> PyObject*
extern def PyMapping_Items(obj: PyObject*) -> PyObject*
# --- Number ops ---
extern def PyNumber_Add(o1: PyObject*, o2: PyObject*) -> PyObject*
extern def PyNumber_Subtract(o1: PyObject*, o2: PyObject*) -> PyObject*
extern def PyNumber_Multiply(o1: PyObject*, o2: PyObject*) -> PyObject*
extern def PyNumber_MatrixMultiply(o1: PyObject*, o2: PyObject*) -> PyObject*
extern def PyNumber_FloorDivide(o1: PyObject*, o2: PyObject*) -> PyObject*
extern def PyNumber_TrueDivide(o1: PyObject*, o2: PyObject*) -> PyObject*
extern def PyNumber_Modulo(o1: PyObject*, o2: PyObject*) -> PyObject*
extern def PyNumber_Power(o1: PyObject*, o2: PyObject*, o3: PyObject*) -> PyObject*
extern def PyNumber_Negative(obj: PyObject*) -> PyObject*
extern def PyNumber_Positive(obj: PyObject*) -> PyObject*
extern def PyNumber_Absolute(obj: PyObject*) -> PyObject*
extern def PyNumber_Invert(obj: PyObject*) -> PyObject*
extern def PyNumber_Lshift(o1: PyObject*, o2: PyObject*) -> PyObject*
extern def PyNumber_Rshift(o1: PyObject*, o2: PyObject*) -> PyObject*
extern def PyNumber_And(o1: PyObject*, o2: PyObject*) -> PyObject*
extern def PyNumber_Xor(o1: PyObject*, o2: PyObject*) -> PyObject*
extern def PyNumber_Or(o1: PyObject*, o2: PyObject*) -> PyObject*
extern def PyNumber_Index(obj: PyObject*) -> PyObject*
extern def PyNumber_Long(obj: PyObject*) -> PyObject*
extern def PyNumber_Float(obj: PyObject*) -> PyObject*
extern def PyNumber_Check(obj: PyObject*) -> int
# --- Weak references ---
extern def PyWeakref_NewRef(obj: PyObject*, cb: PyObject*) -> PyObject*
extern def PyWeakref_GetObject(ref: PyObject*) -> PyObject*
extern def PyWeakref_Check(obj: PyObject*) -> int
# --- Property descriptors ---
class PyGetSetDef:
name: const str
get: t.CPtr
set: t.CPtr
doc: const str
closure: t.CPtr
class PyMemberDef:
name: const str
type: int
offset: t.CPtrDiffT
flags: int
doc: const str
# --- sys module ---
extern def PySys_GetObject(name: const str) -> PyObject*
extern def PySys_SetObject(name: const str, val: PyObject*) -> int
extern def PySys_ResetWarnOptions(): pass
extern def PySys_AddWarnOption(s: PyObject*): pass
extern def PySYS_AddXOption(s: PyObject*): pass
extern def PySys_WriteStdout(fmt: const str): pass
extern def PySys_WriteStderr(fmt: const str): pass
extern def PySys_FormatStdout(fmt: const str): pass
extern def PySys_FormatStderr(fmt: const str): pass
# --- Memory view ---
extern def PyMemoryView_FromObject(obj: PyObject*) -> PyObject*
extern def PyMemoryView_GetContiguous(obj: PyObject*, btype: int, order: char) -> PyObject*
extern def PyMemoryView_Check(obj: PyObject*) -> int
# --- set / frozenset ---
extern def PySet_New(iterable: PyObject*) -> PyObject*
extern def PySet_Add(s: PyObject*, key: PyObject*) -> int
extern def PySet_Discard(s: PyObject*, key: PyObject*) -> int
extern def PySet_Contains(s: PyObject*, key: PyObject*) -> int
extern def PySet_Size(s: PyObject*) -> sizet
extern def PySet_Clear(s: PyObject*): pass
extern def PySet_Check(obj: PyObject*) -> int
extern def PyFrozenSet_New(iterable: PyObject*) -> PyObject*
extern def PyFrozenSet_Check(obj: PyObject*) -> int
# --- slice ---
extern def PySlice_New(start: PyObject*, stop: PyObject*, step: PyObject*) -> PyObject*
extern def PySlice_GetIndicesEx(sl: PyObject*, length: sizet, start: sizet*, stop: sizet*, step: sizet*, slicelen: sizet*) -> int
extern def PySlice_Unpack(sl: PyObject*, start: t.CPtrDiffT*, stop: t.CPtrDiffT*, step: t.CPtrDiffT*): pass
extern def PySlice_AdjustIndices(length: sizet, start: t.CPtrDiffT*, stop: t.CPtrDiffT*, step: t.CPtrDiffT) -> sizet
extern def PySlice_Check(obj: PyObject*) -> int
# --- Type wrapper classes: operator overloading ---
# --- PyLongObj: Python integer wrapper ---
class PyLongObj:
ptr: PyObject*
def __new__(self) -> 'PyLongObj' | t.CPtr:
return t.CPtr(malloc(PyLongObj.__sizeof__()))
@staticmethod
def from_long(val: t.CLong) -> 'PyLongObj' | t.CPtr:
obj: PyLongObj* = PyLongObj()
obj.ptr = PyLong_FromLong(val)
return obj
def __add__(self, other: PyLongObj*) -> 'PyLongObj' | t.CPtr:
res: PyLongObj* = PyLongObj()
res.ptr = PyNumber_Add(self.ptr, other.ptr)
return res
def __sub__(self, other: PyLongObj*) -> 'PyLongObj' | t.CPtr:
res: PyLongObj* = PyLongObj()
res.ptr = PyNumber_Subtract(self.ptr, other.ptr)
return res
def __mul__(self, other: PyLongObj*) -> 'PyLongObj' | t.CPtr:
res: PyLongObj* = PyLongObj()
res.ptr = PyNumber_Multiply(self.ptr, other.ptr)
return res
def __neg__(self) -> 'PyLongObj' | t.CPtr:
res: PyLongObj* = PyLongObj()
res.ptr = PyNumber_Negative(self.ptr)
return res
def to_long(self) -> t.CLong:
return PyLong_AsLong(self.ptr)
def __str__(self) -> PyObject*:
return PyObject_Str(self.ptr)
def dec_ref(self):
Py_DecRef(self.ptr)
# --- PyFloatObj: Python float wrapper ---
class PyFloatObj:
ptr: PyObject*
def __new__(self) -> 'PyFloatObj' | t.CPtr:
return t.CPtr(malloc(PyFloatObj.__sizeof__()))
@staticmethod
def from_double(val: double) -> 'PyFloatObj' | t.CPtr:
obj: PyFloatObj* = PyFloatObj()
obj.ptr = PyFloat_FromDouble(val)
return obj
def __add__(self, other: PyFloatObj*) -> 'PyFloatObj' | t.CPtr:
res: PyFloatObj* = PyFloatObj()
res.ptr = PyNumber_Add(self.ptr, other.ptr)
return res
def __sub__(self, other: PyFloatObj*) -> 'PyFloatObj' | t.CPtr:
res: PyFloatObj* = PyFloatObj()
res.ptr = PyNumber_Subtract(self.ptr, other.ptr)
return res
def __mul__(self, other: PyFloatObj*) -> 'PyFloatObj' | t.CPtr:
res: PyFloatObj* = PyFloatObj()
res.ptr = PyNumber_Multiply(self.ptr, other.ptr)
return res
def __truediv__(self, other: PyFloatObj*) -> 'PyFloatObj' | t.CPtr:
res: PyFloatObj* = PyFloatObj()
res.ptr = PyNumber_TrueDivide(self.ptr, other.ptr)
return res
def __neg__(self) -> 'PyFloatObj' | t.CPtr:
res: PyFloatObj* = PyFloatObj()
res.ptr = PyNumber_Negative(self.ptr)
return res
def to_double(self) -> double:
return PyFloat_AsDouble(self.ptr)
def __str__(self) -> PyObject*:
return PyObject_Str(self.ptr)
def dec_ref(self):
Py_DecRef(self.ptr)
# --- PyUnicodeObj: Python string wrapper ---
class PyUnicodeObj:
ptr: PyObject*
def __new__(self) -> 'PyUnicodeObj' | t.CPtr:
return t.CPtr(malloc(PyUnicodeObj.__sizeof__()))
@staticmethod
def from_string(s: char*) -> 'PyUnicodeObj' | t.CPtr:
obj: PyUnicodeObj* = PyUnicodeObj()
obj.ptr = PyUnicode_FromString(s)
return obj
def __add__(self, other: PyUnicodeObj*) -> 'PyUnicodeObj' | t.CPtr:
res: PyUnicodeObj* = PyUnicodeObj()
res.ptr = PyUnicode_Concat(self.ptr, other.ptr)
return res
def __len__(self) -> t.CPtrDiffT:
return PyUnicode_GetLength(self.ptr)
def as_utf8(self) -> char*:
return PyUnicode_AsUTF8(self.ptr)
def __str__(self) -> PyObject*:
return self.ptr
def dec_ref(self):
Py_DecRef(self.ptr)
# --- PyListObj: Python list wrapper ---
class PyListObj:
ptr: PyObject*
def __new__(self) -> 'PyListObj' | t.CPtr:
return t.CPtr(malloc(PyListObj.__sizeof__()))
@staticmethod
def new() -> 'PyListObj' | t.CPtr:
obj: PyListObj* = PyListObj()
obj.ptr = PyList_New(0)
return obj
def __getitem__(self, idx: sizet) -> PyObject*:
return PyList_GetItem(self.ptr, idx)
def __setitem__(self, idx: sizet, val: PyObject*):
PyList_SetItem(self.ptr, idx, val)
def __len__(self) -> sizet:
return PyList_Size(self.ptr)
def append(self, item: PyObject*) -> int:
return PyList_Append(self.ptr, item)
def dec_ref(self):
Py_DecRef(self.ptr)
# --- PyDictObj: Python dict wrapper ---
class PyDictObj:
ptr: PyObject*
def __new__(self) -> 'PyDictObj' | t.CPtr:
return t.CPtr(malloc(PyDictObj.__sizeof__()))
@staticmethod
def new() -> 'PyDictObj' | t.CPtr:
obj: PyDictObj* = PyDictObj()
obj.ptr = PyDict_New()
return obj
def __getitem__(self, key: PyObject*) -> PyObject*:
return PyDict_GetItem(self.ptr, key)
def __setitem__(self, key: PyObject*, val: PyObject*):
PyDict_SetItem(self.ptr, key, val)
def __len__(self) -> sizet:
return PyDict_Size(self.ptr)
def get_string(self, key: char*) -> PyObject*:
return PyDict_GetItemString(self.ptr, key)
def set_string(self, key: char*, val: PyObject*):
PyDict_SetItemString(self.ptr, key, val)
def dec_ref(self):
Py_DecRef(self.ptr)