Documentation
¶
Overview ¶
Package objects ports the gating subset of cpython/Objects/. v0.2 covers the object protocol, the type slot table, and the concrete builtins needed to construct a dict, hash a tuple, and iterate a list. Strings, bytes, set, exceptions, and the cycle collector arrive in later phases (see notes/Spec/1700/).
Set and frozenset objects. Mirrors CPython's open-addressed hash table layout. frozenset is an immutable set that supports all read operations but disallows mutation; it stores its hash lazily.
CPython: Objects/setobject.c
Index ¶
- Constants
- Variables
- func Decref(o Object)
- func DelAttr(o Object, name Object) error
- func Hash(o Object) (int64, error)
- func Incref(o Object)
- func Is(a, b Object) bool
- func IsNone(o Object) bool
- func IsNotImplemented(o Object) bool
- func IsSubtype(sub, super *Type) bool
- func IsTruthy(o Object) (bool, error)
- func Repr(o Object) (string, error)
- func RichCmpBool(a, b Object, op CompareOp) (bool, error)
- func SetAttr(o Object, name Object, value Object) error
- func Str(o Object) (string, error)
- func VectorcallNargs(nargsf uint) int
- type Bool
- type BuiltinFunction
- type Cell
- type Code
- type CompareOp
- type Dict
- type Float
- type Function
- type Header
- type Int
- type LineEntry
- type List
- type MappingMethods
- type Module
- type NumberMethods
- type Object
- func Call(callable Object, args *Tuple, kwargs *Dict) (Object, error)
- func CallNoArgs(callable Object) (Object, error)
- func CallObject(callable Object, args *Tuple) (Object, error)
- func CallOneArg(callable Object, arg Object) (Object, error)
- func False() Object
- func GetAttr(o Object, name Object) (Object, error)
- func MakeTpCall(callable Object, args []Object, nargs int, keywords Object) (Object, error)
- func NewBool(b bool) Object
- func NewStr(s string) Object
- func None() Object
- func NotImplemented() Object
- func RichCmp(a, b Object, op CompareOp) (Object, error)
- func True() Object
- func Vectorcall(callable Object, args []Object, nargsf uint, kwnames *Tuple) (Object, error)
- type PositionEntry
- type Range
- type SequenceMethods
- type Set
- type Slice
- type Tuple
- type Type
- type VarHeader
Constants ¶
const VectorcallArgumentsOffset uint = 1 << 63
VectorcallArgumentsOffset is the high bit of nargsf signaling that the caller reserved one slot at args[-1] for a self pointer; the callee may overwrite that slot. Mirrors PY_VECTORCALL_ARGUMENTS_OFFSET, the high bit of size_t.
CPython: Include/cpython/abstract.h:24 PY_VECTORCALL_ARGUMENTS_OFFSET
Variables ¶
var BoolType = NewType("bool", []*Type{IntType})
BoolType is the type singleton for bool. Mirrors PyBool_Type.
CPython: Objects/boolobject.c:L222 PyBool_Type
var BuiltinFunctionType = NewType("builtin_function_or_method", []*Type{objectType})
BuiltinFunctionType is the type singleton for built-in functions.
CPython: Objects/methodobject.c:357 PyCFunction_Type
var CellType = NewType("cell", []*Type{objectType})
CellType is the type singleton for cell objects.
CPython: Objects/cellobject.c PyCell_Type
var CodeType = NewType("code", []*Type{objectType})
CodeType is the type singleton for code objects.
CPython: Objects/codeobject.c PyCode_Type
var DictType = NewType("dict", []*Type{objectType})
DictType is the type singleton for dict. Mirrors PyDict_Type.
CPython: Objects/dictobject.c:L4023 PyDict_Type
var ErrStopIteration = errors.New("StopIteration")
ErrStopIteration signals end of iteration. Mirrors PyExc_StopIteration.
CPython: Objects/exceptions.c:L1937 PyExc_StopIteration
var FloatType = NewType("float", []*Type{objectType})
FloatType is the type singleton for float. Mirrors PyFloat_Type. Slots are wired in init() because floatHash transitively constructs Ints which would otherwise close the dep cycle.
CPython: Objects/floatobject.c:L2068 PyFloat_Type
var FrozensetType = NewType("frozenset", []*Type{objectType})
FrozensetType is the type singleton for frozenset.
CPython: Objects/setobject.c:L2468 PyFrozenSet_Type
var FunctionType = NewType("function", []*Type{objectType})
FunctionType is the type singleton for Python-defined functions.
CPython: Objects/funcobject.c PyFunction_Type
var IntType = NewType("int", []*Type{objectType})
IntType is the type singleton for int. Mirrors PyLong_Type. Slots are wired in init() to break the variable-init dependency cycle (slots reference NewIntFromBig which references the small-int cache which references IntType).
CPython: Objects/longobject.c:L6447 PyLong_Type
var ListType = NewType("list", []*Type{objectType})
ListType is the type singleton for list. Mirrors PyList_Type.
CPython: Objects/listobject.c:L3380 PyList_Type
var ModuleType = NewType("module", []*Type{objectType})
ModuleType is the type singleton for module objects.
CPython: Objects/moduleobject.c:766 PyModule_Type
var RangeType = NewType("range", []*Type{objectType})
RangeType is the type singleton for range. Mirrors PyRange_Type.
CPython: Objects/rangeobject.c:L949 PyRange_Type
var SetType = NewType("set", []*Type{objectType})
SetType is the type singleton for set.
CPython: Objects/setobject.c:L2318 PySet_Type
var SliceType = NewType("slice", []*Type{objectType})
SliceType is the type singleton for slice. Mirrors PySlice_Type.
CPython: Objects/sliceobject.c:L325 PySlice_Type
var TupleType = NewType("tuple", []*Type{objectType})
TupleType is the type singleton for tuple. Mirrors PyTuple_Type.
CPython: Objects/tupleobject.c:L961 PyTuple_Type
Functions ¶
func Decref ¶
func Decref(o Object)
Decref drops the refcount. If it reaches zero and the type defines a Dealloc slot, Dealloc is invoked. Until v0.10 lands the cycle collector, Dealloc is the only finalize hook.
CPython: Include/object.h:L631 Py_DECREF
func DelAttr ¶ added in v0.6.0
DelAttr deletes o.name. Forwards to SetAttr with value==nil to match CPython's single dispatch.
CPython: Objects/object.c:1490 PyObject_DelAttr
func Hash ¶
Hash returns the hash of o. Errors with errUnhashable when the type has no Hash slot. Mirrors PyObject_Hash.
CPython: Objects/object.c:L869 PyObject_Hash
func Incref ¶
func Incref(o Object)
Incref bumps the refcount. Concurrent Increfs are safe.
CPython: Include/object.h:L605 Py_INCREF
func Is ¶
Is reports identity equality, the Python `is` operator. Mirrors Py_Is.
CPython: Include/object.h:L257 Py_Is
func IsNone ¶
IsNone reports whether o is the None singleton. Mirrors Py_IsNone.
CPython: Include/object.h:L827 Py_IsNone
func IsNotImplemented ¶
IsNotImplemented reports whether o is the NotImplemented singleton.
CPython: Objects/object.c:L1965 Py_IsNotImplemented
func IsSubtype ¶
IsSubtype reports whether sub is sub or one of its bases. Mirrors PyType_IsSubtype.
CPython: Objects/typeobject.c:L2556 PyType_IsSubtype
func Repr ¶
Repr returns the Python repr of o. Falls back to a generic `<type at addr>` when the type lacks a Repr slot.
CPython: Objects/object.c:L518 PyObject_Repr
func RichCmpBool ¶
RichCmpBool runs RichCmp and converts the result to a Go bool. Mirrors PyObject_RichCompareBool.
CPython: Objects/object.c:L795 PyObject_RichCompareBool
func SetAttr ¶ added in v0.6.0
SetAttr writes o.name = value. value==nil deletes the attribute (CPython routes PyObject_DelAttr through here too).
CPython: Objects/object.c:1440 PyObject_SetAttr
func Str ¶
Str returns the Python str of o. Falls back to Repr.
CPython: Objects/object.c:L463 PyObject_Str
func VectorcallNargs ¶ added in v0.6.0
VectorcallNargs strips the VectorcallArgumentsOffset flag from nargsf and returns just the positional count.
CPython: Objects/call.c:1127 PyVectorcall_NARGS
Types ¶
type Bool ¶
type Bool struct {
Int
}
Bool is the Python bool. CPython makes bool a subclass of int with just two singleton instances; gopy follows the same pattern.
CPython: Objects/boolobject.c:L24 PyBool_Type
type BuiltinFunction ¶ added in v0.6.0
type BuiltinFunction struct {
Header
Name string
Fn func(args []Object, kwargs map[string]Object) (Object, error)
}
BuiltinFunction wraps a Go function so the VM can call it through the type's Vectorcall / Call slots. The Fn closure shape mirrors METH_VARARGS|METH_KEYWORDS (positional slice plus a kwargs map), which is the convention CPython's cfunction_call dispatches when vectorcall is unavailable.
CPython: Include/cpython/methodobject.h PyCFunctionObject
func NewBuiltinFunction ¶ added in v0.6.0
func NewBuiltinFunction(name string, fn func(args []Object, kwargs map[string]Object) (Object, error)) *BuiltinFunction
NewBuiltinFunction wraps fn under name.
type Cell ¶ added in v0.6.0
Cell holds a single Object reference shared between an enclosing function and its inner closures. MAKE_CELL allocates one, LOAD_DEREF / STORE_DEREF read and write Contents, and COPY_FREE_VARS hands the outer cells to the inner frame.
CPython: Include/cpython/cellobject.h PyCellObject
type Code ¶ added in v0.5.5
type Code struct {
Header
// Argument shape. CPython sets all four counts at compile time;
// the interpreter reads them when binding a CALL_FUNCTION.
Argcount int
PosonlyArgcount int
KwonlyArgcount int
Stacksize int
// Flags carries the CO_* bitset (CO_OPTIMIZED, CO_NEWLOCALS,
// CO_VARARGS, CO_VARKEYWORDS, CO_NESTED, CO_GENERATOR,
// CO_COROUTINE, CO_ASYNC_GENERATOR, etc.).
Flags int
// Code is the bytecode blob. Each instruction is a 16-bit
// (op, arg) pair; the interpreter dispatch loop walks it.
Code []byte
// Consts is the literal table the LOAD_CONST opcode indexes into.
Consts []any
// Names, Varnames, Freevars, Cellvars are name tables indexed
// by their respective LOAD_/STORE_ opcodes.
Names []string
Varnames []string
Freevars []string
Cellvars []string
// Filename, Name, Qualname mirror co_filename / co_name /
// co_qualname. The traceback renderer reads them.
Filename string
Name string
Qualname string
// Firstlineno is the source line of the first statement in
// the code; the linetable encodes deltas from this anchor.
Firstlineno int
// Linetable is the PEP 626 location table. Decoded via
// CoLines / CoPositions in code_tables.go.
Linetable []byte
// ExceptionTable is the compact try/except table the
// interpreter walks on RAISE_VARARGS / END_FINALLY.
ExceptionTable []byte
}
Code is the AST -> bytecode handoff value. Compile produces one of these per code-bearing node (module, function body, class body, comprehension).
CPython: Include/internal/pycore_code.h:115 _PyCodeObject
type CompareOp ¶
type CompareOp int
CompareOp identifies the six comparison operators Python exposes through __lt__/__le__/__eq__/__ne__/__gt__/__ge__. Numeric values match the C macros Py_LT..Py_GE so direct ports of slot implementations can pass the integer through.
CPython: Include/object.h:L375 Py_LT
type Dict ¶
type Dict struct {
Header
// contains filtered or unexported fields
}
Dict is the Python dict.
CPython: Include/cpython/dictobject.h:L19 PyDictObject
func NewDict ¶
func NewDict() *Dict
NewDict builds an empty dict.
CPython: Objects/dictobject.c:L765 PyDict_New
func (*Dict) Contains ¶
Contains reports whether key is in the dict.
CPython: Objects/dictobject.c:L2495 PyDict_Contains
func (*Dict) DelItem ¶
DelItem removes key. Mirrors PyDict_DelItem.
CPython: Objects/dictobject.c:L2154 PyDict_DelItem
func (*Dict) GetItem ¶
GetItem looks up key. Returns errKeyNotFound when absent.
CPython: Objects/dictobject.c:L1925 PyDict_GetItemWithError
func (*Dict) Keys ¶ added in v0.6.0
Keys returns a snapshot of the live keys in insertion order. The returned slice is owned by the caller.
CPython: Objects/dictobject.c PyDict_Keys
type Float ¶
type Float struct {
Header
// contains filtered or unexported fields
}
Float is the Python float, an IEEE-754 double.
CPython: Include/cpython/floatobject.h:L7 PyFloatObject
type Function ¶ added in v0.6.0
type Function struct {
Header
Name string
Qualname string
Code *Code
Globals Object
Defaults *Tuple // positional defaults, may be nil
KwDefaults *Dict // keyword-only defaults, may be nil
Closure *Tuple // tuple of cells, may be nil
}
Function is a Python-defined function: a code object plus the captured globals, defaults, and closure cells. The runtime call arm pushes a new frame off the bound code, threads the callable's globals through to the frame's f_globals, and dispatches.
v0.6 holds Code as Object so we don't need to import frame here; the call site does the type-check.
CPython: Include/cpython/funcobject.h PyFunctionObject
type Header ¶
type Header struct {
// contains filtered or unexported fields
}
Header is the per-object header. Mirrors struct _object in cpython/Include/object.h. The zero value is invalid; constructors set refcount to 1 and install the type pointer.
CPython: Include/object.h:L107 _object
func (*Header) Init ¶ added in v0.3.0
Init is the cross-package entry point to init. Out-of-package types such as the exception in errors/ embed Header and need to bind their Header.typ to a *Type without re-implementing the refcount dance.
CPython: Objects/object.c:L184 _PyObject_Init
type Int ¶
type Int struct {
Header
// contains filtered or unexported fields
}
Int is the Python int. CPython stores arbitrary-precision integers as a sign + digit array on PyLong; gopy uses math/big.Int for the same semantics. The fast-path for machine-word ints lands in v0.4 alongside the longobject.c port proper.
CPython: Include/cpython/longintrepr.h:L11 _PyLongValue
func NewInt ¶
NewInt builds an int from an int64. Returns the cached singleton for the small-int range.
CPython: Objects/longobject.c:L322 PyLong_FromLong
func NewIntFromBig ¶
NewIntFromBig builds an int from a math/big.Int. Returns the cached singleton when the value fits the small-int window.
CPython: Objects/longobject.c:L156 _PyLong_FromBytes (adapted from)
type LineEntry ¶ added in v0.5.5
LineEntry is one decoded line-table record. Start and End are bytecode byte offsets (half-open span); Line is the source line (1-based) or -1 when the entry has no associated source line.
CPython: Objects/codeobject.c:1156 PyCodeAddressRange (ar_start / ar_end / ar_line fields, projected without the column data).
type List ¶
type List struct {
VarHeader
// contains filtered or unexported fields
}
List is the Python list, a mutable ordered sequence.
CPython: Include/cpython/listobject.h:L7 PyListObject
func NewList ¶
NewList builds a list from items. The slice is copied.
CPython: Objects/listobject.c:L156 PyList_New
func (*List) Append ¶
Append adds v to the end. Mirrors PyList_Append.
CPython: Objects/listobject.c:L351 PyList_Append
func (*List) Item ¶
Item returns the item at index i without bounds check.
CPython: Objects/listobject.c:L308 PyList_GetItem
type MappingMethods ¶
type MappingMethods struct {
Length func(o Object) (int, error)
GetItem func(o, key Object) (Object, error)
SetItem func(o, key, v Object) error
DelItem func(o, key Object) error
}
MappingMethods is the v0.2 subset of tp_as_mapping.
CPython: Include/cpython/object.h:L255 PyMappingMethods
type Module ¶ added in v0.8.0
type Module struct {
Header
// contains filtered or unexported fields
}
Module mirrors PyModuleObject.
CPython: Include/cpython/moduleobject.h:11 PyModuleObject
func NewModule ¶ added in v0.8.0
NewModule creates an empty module with the given name in its __dict__.
CPython: Objects/moduleobject.c:74 PyModule_NewObject
func (*Module) Dict ¶ added in v0.8.0
Dict returns the module's attribute dict (__dict__).
CPython: Objects/moduleobject.c:459 PyModule_GetDict
type NumberMethods ¶
type NumberMethods struct {
Add func(a, b Object) (Object, error)
Subtract func(a, b Object) (Object, error)
Multiply func(a, b Object) (Object, error)
TrueDivide func(a, b Object) (Object, error)
FloorDivide func(a, b Object) (Object, error)
Remainder func(a, b Object) (Object, error)
And func(a, b Object) (Object, error)
Or func(a, b Object) (Object, error)
Xor func(a, b Object) (Object, error)
Lshift func(a, b Object) (Object, error)
Rshift func(a, b Object) (Object, error)
Power func(a, b, mod Object) (Object, error)
Divmod func(a, b Object) (Object, error)
Negative func(o Object) (Object, error)
Positive func(o Object) (Object, error)
Absolute func(o Object) (Object, error)
Invert func(o Object) (Object, error)
Bool func(o Object) (bool, error)
Int func(o Object) (Object, error)
Float func(o Object) (Object, error)
}
NumberMethods is the v0.2 subset of tp_as_number. The reflected variants are handled by the abstract layer; concrete types only implement the forward direction.
CPython: Include/cpython/object.h:L195 PyNumberMethods
type Object ¶
type Object interface {
// Type returns the object's type. Mirrors Py_TYPE.
Type() *Type
// Hdr returns a pointer to the embedded Header so generic
// runtime code can reach the refcount without knowing the
// concrete shape. CPython reaches the same field by casting to
// PyObject*.
Hdr() *Header
}
Object is the interface every Python value satisfies. Concrete types embed *Header (or *VarHeader) and add their own fields.
CPython: Include/object.h:L107 PyObject (interface analog)
func Call ¶ added in v0.6.0
Call is PyObject_Call: the legacy entry that hands a positional tuple and keyword dict to whatever path the callable advertises. vectorcall-capable types take a fast path; everything else lands in tp_call via MakeTpCall.
CPython: Objects/call.c:370 PyObject_Call (forwards to _PyObject_Call)
func CallNoArgs ¶ added in v0.6.0
CallNoArgs is PyObject_CallNoArgs; a zero-arg vectorcall.
CPython: Objects/call.c:101 PyObject_CallNoArgs
func CallObject ¶ added in v0.6.0
CallObject is PyObject_CallObject. args may be nil, in which case it behaves like CallNoArgs; otherwise it is treated as a positional tuple.
CPython: Objects/call.c:460 PyObject_CallObject
func CallOneArg ¶ added in v0.6.0
CallOneArg is PyObject_CallOneArg; a single-positional vectorcall that reserves the args[-1] slot via VectorcallArgumentsOffset.
CPython: Objects/call.c:386 PyObject_CallOneArg
func False ¶
func False() Object
False returns the False singleton. Mirrors Py_False.
CPython: Include/object.h:L857 Py_False
func GetAttr ¶ added in v0.6.0
GetAttr fetches o.name. Routes through the type's Getattro slot. Returns AttributeError when the type exposes no attribute access.
CPython: Objects/object.c:1290 PyObject_GetAttr
func MakeTpCall ¶ added in v0.6.0
MakeTpCall is the slow path used when a callable does not advertise vectorcall. It builds the (args_tuple, kwargs_dict) shape the tp_call slot expects and dispatches through it.
CPython: Objects/call.c:200 _PyObject_MakeTpCall
func NewBool ¶
NewBool returns the True or False singleton. Mirrors PyBool_FromLong.
CPython: Objects/boolobject.c:L33 PyBool_FromLong
func NewStr ¶ added in v0.3.0
NewStr wraps s in the v0.3 placeholder str object. The real unicodeobject port (v0.4) will replace this with a kind/length/data layout that matches CPython's compact-string representation.
CPython: Objects/unicodeobject.c:L1985 PyUnicode_FromString
func None ¶
func None() Object
None returns the singleton None value. Mirrors Py_None.
CPython: Include/object.h:L820 Py_None
func NotImplemented ¶
func NotImplemented() Object
NotImplemented returns the singleton NotImplemented value. Mirrors Py_NotImplemented.
CPython: Include/object.h:L863 Py_NotImplemented
func RichCmp ¶
RichCmp dispatches to tp_richcompare. Returns NotImplemented when neither operand handles the comparison. Mirrors PyObject_RichCompare.
CPython: Objects/object.c:L737 PyObject_RichCompare
func True ¶
func True() Object
True returns the True singleton. Mirrors Py_True.
CPython: Include/object.h:L860 Py_True
func Vectorcall ¶ added in v0.6.0
Vectorcall is the PEP 590 entry point used by the eval loop's CALL family. nargsf is the positional count plus the optional VectorcallArgumentsOffset flag; kwnames carries keyword names whose values live at args[nargs..nargs+nkwnames].
CPython: Objects/call.c:323 PyObject_Vectorcall (forwards to _PyObject_VectorcallTstate, Include/internal/pycore_call.h:162)
type PositionEntry ¶ added in v0.5.5
PositionEntry adds the column span; matches the PEP 657 four-field position used for fine-grained traceback rendering.
CPython: Objects/codeobject.c:1252 PyCode_Addr2Location output.
func CoAddr2Location ¶ added in v0.6.0
func CoAddr2Location(c *Code, addr int) (PositionEntry, bool)
CoAddr2Location returns the PositionEntry covering bytecode byte offset addr, or false when no entry covers it. Mirrors the single-address form of PyCode_Addr2Location, sparing callers the linear scan when they have a precomputed entries slice.
CPython: Objects/codeobject.c:1252 PyCode_Addr2Location
func CoPositions ¶ added in v0.5.5
func CoPositions(c *Code) []PositionEntry
CoPositions decodes the PEP 626 line table into one PositionEntry per coalesced run, in source order. Start/End are bytecode bytes (1 codeunit = 2 bytes); Column / EndColumn are -1 when the form omits column information; Line / EndLine are -1 for the "none" form.
CPython: Objects/codeobject.c:1199 advance_with_locations (called in a loop).
type Range ¶
Range is the Python range object. Bounds are stored as Int so the arithmetic stays correct for the full int range.
CPython: Objects/rangeobject.c:L19 rangeobject
type SequenceMethods ¶
type SequenceMethods struct {
Length func(o Object) (int, error)
Concat func(a, b Object) (Object, error)
Repeat func(o Object, n int) (Object, error)
GetItem func(o Object, i int) (Object, error)
SetItem func(o Object, i int, v Object) error
Contains func(o, v Object) (bool, error)
}
SequenceMethods is the v0.2 subset of tp_as_sequence.
CPython: Include/cpython/object.h:L262 PySequenceMethods
type Set ¶ added in v0.8.0
type Set struct {
Header
// contains filtered or unexported fields
}
Set is the mutable Python set type.
CPython: Objects/setobject.c:L544 PySetObject
func NewFrozenset ¶ added in v0.8.0
NewFrozenset creates a frozenset from the given items.
CPython: Objects/setobject.c:L2300 PyFrozenSet_New
func NewSet ¶ added in v0.8.0
func NewSet() *Set
NewSet creates an empty mutable set.
CPython: Objects/setobject.c:L2267 PySet_New (empty case)
func (*Set) Add ¶ added in v0.8.0
Add inserts key into the set. Returns an error if key is unhashable or if the set is frozen.
CPython: Objects/setobject.c:L413 set_add_key
func (*Set) Contains ¶ added in v0.8.0
Contains reports whether key is in the set.
CPython: Objects/setobject.c:L1777 set_contains_key
func (*Set) Discard ¶ added in v0.8.0
Discard removes key if present. Does nothing on miss. Errors if frozen.
CPython: Objects/setobject.c:L743 set_discard_key
type Slice ¶
Slice is the Python slice object: start, stop, step.
CPython: Include/cpython/sliceobject.h:L8 PySliceObject
type Tuple ¶
type Tuple struct {
VarHeader
// contains filtered or unexported fields
}
Tuple is the Python tuple, an immutable ordered sequence.
CPython: Include/cpython/tupleobject.h:L8 PyTupleObject
func NewTuple ¶
NewTuple builds a tuple from items. The empty tuple returns the cached singleton.
CPython: Objects/tupleobject.c:L155 PyTuple_New
type Type ¶
type Type struct {
Header
Name string
BaseSize int
ItemSize int
Bases []*Type
MRO []*Type
Repr func(o Object) (string, error)
Str func(o Object) (string, error)
Hash func(o Object) (int64, error)
RichCmp func(a, b Object, op CompareOp) (Object, error)
Iter func(o Object) (Object, error)
IterNext func(o Object) (Object, error)
Call func(o Object, args []Object, kwargs map[string]Object) (Object, error)
// Vectorcall is the PEP 590 fast-call slot. When non-nil, the call
// machinery uses this instead of going through Call. args is a flat
// array of positional values followed by keyword values; nargsf is
// the positional count optionally combined with the
// VectorcallArgumentsOffset flag; kwnames is a tuple of keyword
// name strings (or nil).
//
// CPython: Include/cpython/object.h tp_vectorcall_offset + Py_TPFLAGS_HAVE_VECTORCALL
Vectorcall func(callable Object, args []Object, nargsf uint, kwnames *Tuple) (Object, error)
// Getattro is the tp_getattro slot. Receives the owner and the
// attribute name (as a Str), returns the attribute value or an
// error. Mirrors getattrofunc.
//
// CPython: Include/cpython/object.h tp_getattro
Getattro func(o Object, name Object) (Object, error)
// Setattro is the tp_setattro slot. value==nil signals a delete
// (PyObject_DelAttr forwards there). Mirrors setattrofunc.
//
// CPython: Include/cpython/object.h tp_setattro
Setattro func(o Object, name Object, value Object) error
Dealloc func(o Object)
Number *NumberMethods
Sequence *SequenceMethods
Mapping *MappingMethods
}
Type is the meta-class for every Python value. Slots not yet implemented in v0.2 are nil; the runtime checks for nil before dispatching.
CPython: Include/cpython/typeobject.h:L139 _typeobject
func NewType ¶
NewType constructs a built-in type with the given name and bases. Bases must be non-empty for everything except `object`. The MRO is computed via C3 linearization.
CPython: Objects/typeobject.c:L4153 type_new (adapted from)
func NoneType ¶
func NoneType() *Type
NoneType returns the type singleton for None.
CPython: Objects/object.c:L1893 _PyNone_Type
func ObjectType ¶
func ObjectType() *Type
ObjectType returns the root `object` type singleton. Mirrors PyBaseObject_Type.
CPython: Objects/typeobject.c:L6299 PyBaseObject_Type