picop.cyobject#

Object protocol helpers.

picop.cyobject.obj_as_fd(o)#

Return a file descriptor via PyObject_AsFileDescriptor.

Notes

Slower than the plain-Python equivalent x.fileno() (Tier A 1.40x); last- resort bridge for unknown objects.

On error raises — do not treat the result as a boolean success flag.

Parameters:

o (object)

Return type:

int

picop.cyobject.obj_bytes(o)#

Return bytes(o) via PyObject_Bytes.

Parameters:

o (object)

Return type:

object

picop.cyobject.obj_call(callable_object, args, kw=None)#

Call callable_object(*args, **kw) via PyObject_Call.

Notes

args must be a tuple; kw must be a dict or None (no keywords).

Parameters:
Return type:

object

picop.cyobject.obj_call_object(callable_object, args)#

Call callable_object(*args) via PyObject_CallObject.

Parameters:
Return type:

object

picop.cyobject.obj_callable(o)#

Return True if o is callable (PyCallable_Check).

Parameters:

o (object)

Return type:

bool

picop.cyobject.obj_delattr(o, name)#

Delete attribute name on o via PyObject_DelAttr.

Notes

Returns 0 on success; errors raise — do not use the status as a bool.

Parameters:
Return type:

int

picop.cyobject.obj_delattr_cstr(o, name)#

Delete C-string attribute name via PyObject_DelAttrString.

Notes

name must be bytes, not str. Returns 0 on success; errors raise — do not use the status as a bool. Alias of obj_delattr_string.

Parameters:
Return type:

int

picop.cyobject.obj_delitem(o, key)#

Delete o[key] via PyObject_DelItem.

Notes

Returns 0 on success; errors raise — do not use the status as a bool.

Parameters:
Return type:

int

picop.cyobject.obj_dir(o)#

Return dir(o) via PyObject_Dir.

Parameters:

o (object)

Return type:

object

picop.cyobject.obj_eq(a, b)#

Return True if a == b via PyObject_RichCompareBool.

Notes

Identity short-circuit applies. Prefer typed *_eq when both operands have a known Core type.

Parameters:
Return type:

bool

picop.cyobject.obj_format(obj, format_spec)#

Return format(obj, format_spec) via PyObject_Format.

Notes

Slower than the plain-Python equivalent format(x, spec) (Tier A 1.03x); last-resort bridge for unknown objects.

Parameters:
Return type:

object

picop.cyobject.obj_getattr(o, name)#

Return getattr(o, name) via PyObject_GetAttr.

Parameters:
Return type:

object

picop.cyobject.obj_getattr_cstr(o, name)#

Return the attribute named by a C string (PyObject_GetAttrString).

Parameters:
Return type:

object

picop.cyobject.obj_getitem(o, key)#

Return o[key] via PyObject_GetItem.

Notes

Slower than the plain-Python equivalent x[key] (Tier A 1.03x); last-resort bridge for unknown objects.

Parameters:
Return type:

object

picop.cyobject.obj_hasattr(o, name)#

Return True if o has attribute name (PyObject_HasAttr).

Notes

Slower than the plain-Python equivalent hasattr(x, name) (Tier A 1.04–1.05x); last-resort bridge for unknown objects.

Parameters:
Return type:

bool

picop.cyobject.obj_hasattr_cstr(o, name)#

Return True if o has the attribute named by a C string (PyObject_HasAttrString).

Parameters:
Return type:

bool

picop.cyobject.obj_hash(o)#

Return the hash of o (PyObject_Hash).

Parameters:

o (object)

Return type:

int

picop.cyobject.obj_isinstance(inst, cls)#

Return True if inst is an instance of cls (PyObject_IsInstance).

Parameters:
Return type:

bool

picop.cyobject.obj_issubclass(derived, cls)#

Return issubclass(derived, cls) via PyObject_IsSubclass.

Parameters:
Return type:

bool

picop.cyobject.obj_istrue(o)#

Return the truthiness of o (PyObject_IsTrue).

Notes

Slower than the plain-Python equivalent bool(x) (Tier A 1.07–1.07x); last- resort bridge for unknown objects.

Parameters:

o (object)

Return type:

bool

picop.cyobject.obj_iter(o)#

Return iter(o) via PyObject_GetIter.

Parameters:

o (object)

Return type:

object

picop.cyobject.obj_len(o)#

Return len(o) via PyObject_Length.

Parameters:

o (object)

Return type:

int

picop.cyobject.obj_length_hint(o, default_value)#

Return operator.length_hint(o, default_value) via PyObject_LengthHint.

Parameters:
Return type:

int

picop.cyobject.obj_not(o)#

Return not o via PyObject_Not.

Parameters:

o (object)

Return type:

bool

picop.cyobject.obj_repr(o)#

Return repr(o) via PyObject_Repr.

Parameters:

o (object)

Return type:

object

picop.cyobject.obj_richcompare(o1, o2, opid)#

Return rich comparison of o1 and o2 for opid (Py_EQ …).

Parameters:
Return type:

object

picop.cyobject.obj_richcompare_bool(o1, o2, opid)#

Return rich comparison as bool for opid (PyObject_RichCompareBool).

Parameters:
Return type:

bool

picop.cyobject.obj_setattr(o, name, v)#

Set attribute name on o via PyObject_SetAttr.

Notes

Returns 0 on success; errors raise — do not use the status as a bool.

Parameters:
Return type:

int

picop.cyobject.obj_setattr_cstr(o, name, v)#

Set C-string attribute name on o via PyObject_SetAttrString.

Notes

name must be bytes, not str. Returns 0 on success; errors raise — do not use the status as a bool. Alias of obj_setattr_string.

Parameters:
Return type:

int

picop.cyobject.obj_setitem(o, key, v)#

Set o[key] = v via PyObject_SetItem.

Notes

Returns 0 on success; errors raise — do not use the status as a bool.

Parameters:
Return type:

int

picop.cyobject.obj_size(o)#

Return Py_SIZE-style length via PyObject_Size (alias of obj_len).

Notes

Slower than the plain-Python equivalent len(x) (Tier A 1.03x); last-resort bridge for unknown objects.

Parameters:

o (object)

Return type:

int

picop.cyobject.obj_str(o)#

Return str(o) via PyObject_Str.

Notes

Slower than the plain-Python equivalent str(x) (Tier A 1.03x); last-resort bridge for unknown objects.

Parameters:

o (object)

Return type:

object

picop.cyobject.obj_type(o)#

Return the type of o (Py_TYPE).

Notes

Slower than the plain-Python equivalent type(x) (Tier A 1.10x); last-resort bridge for unknown objects.

Parameters:

o (object)

Return type:

object