picop.containers#

Category facade: typed Core containers (dict / list / set / tuple).

Prefer from picop.hot import for micro-opt starters. This module groups word-prefix container helpers for discovery without a flat barrel dump. See Safety for unchecked accessors.

picop.containers.dict_check(p)#

Return True if p is a dict or subtype (PyDict_Check). :type p: object :param p:

Return type:

bool

picop.containers.dict_check_exact(p)#

Return True if type(p) is dict (PyDict_CheckExact). :type p: object :param p:

Return type:

bool

picop.containers.dict_get(d, key)#

Return d[key] via borrowed PyDict_GetItem.

Notes

Missing keys and stored None both yield None. Prefer dict_get_ref when you need to distinguish those cases.

Parameters:
Return type:

object

picop.containers.dict_get_ref(d, key)#

Return a strong ref to d[key] via PyDict_GetItemRef.

Notes

Missing keys yield None; a stored None is a distinct strong ref to None. Prefer this over dict_get when that distinction matters.

Parameters:
Return type:

object

picop.containers.dict_contains(d, key)#

Return whether key is in d (PyDict_Contains). :type d: dict :param d: :type key: str :param key:

Return type:

bool

picop.containers.dict_len(d)#

Return len(d) via PyDict_GET_SIZE. :type d: dict :param d:

Return type:

int

picop.containers.dict_eq(a, b)#

Return True if typed dicts are equal (identity/size short-circuit + richcompare). :type a: dict :param a: :type b: dict :param b:

Return type:

bool

picop.containers.dict_size(d)#

Return len(d) via checked PyDict_Size.

Notes

Prefer dict_len on a typed dict hot path.

Parameters:

d (object)

Return type:

int

picop.containers.dict_set(d, key, value)#

Set d[key] = value via PyDict_SetItem.

Notes

Returns 0 on success and -1 on error; errors raise. Do not use the status int as a bool.

Parameters:
Return type:

int

picop.containers.dict_del(d, key)#

Delete d[key] via PyDict_DelItem.

Notes

Returns 0 on success and -1 on error; errors raise. Do not use the status int as a bool.

Parameters:
Return type:

int

picop.containers.dict_pop(d, key)#

Remove key and return its value via PyDict_Pop.

Notes

Missing keys yield None (same ambiguity as a stored None value).

Parameters:
Return type:

object

picop.containers.dict_setdefault(d, key, default=None)#

Return d.setdefault(key, default) via borrowed PyDict_SetDefault.

Notes

The returned reference is borrowed. Prefer dict_setdefault_ref when you need a strong ref.

Parameters:
Return type:

object

picop.containers.dict_update(d, other)#

Update d from other via PyDict_Update.

Notes

Returns 0 on success and -1 on error; errors raise. Do not use the status int as a bool.

Parameters:
Return type:

int

picop.containers.dict_clear(d)#

Clear d via PyDict_Clear. :type d: dict :param d:

Return type:

None

picop.containers.dict_copy(d)#

Return a shallow copy of d via PyDict_Copy. :type d: dict :param d:

Return type:

dict

picop.containers.dict_new()#

Return a new empty dict (PyDict_New).

Return type:

dict

picop.containers.list_check(p)#

Return True if p is a list or subtype (PyList_Check). :type p: object :param p:

Return type:

bool

picop.containers.list_check_exact(p)#

Return True if type(p) is list (PyList_CheckExact). :type p: object :param p:

Return type:

bool

picop.containers.deque_eq(a, b)#

Return True if deques are equal.

Notes

Identity short-circuit plus richcompare — same semantics as deque.__eq__.

Parameters:
Return type:

bool

picop.containers.range_eq(a, b)#

Return True if ranges represent the same sequence.

Notes

Identity short-circuit plus richcompare — same semantics as range.__eq__.

Parameters:
Return type:

bool

picop.containers.list_eq(a, b)#

Return True if typed lists are equal (identity/len short-circuit + richcompare). :type a: list :param a: :type b: list :param b:

Return type:

bool

picop.containers.list_len(l)#

Return len(l) via PyList_GET_SIZE. :type l: list :param l:

Return type:

int

picop.containers.list_size(l)#

Return len(l) via checked PyList_Size.

Notes

Prefer list_len on a typed list hot path.

Parameters:

l (object)

Return type:

int

picop.containers.list_get(l, i)#

Return l[i] via PyList_GET_ITEM.

Notes

Unchecked: out-of-bounds is undefined behavior. Prefer list_get_checked / list_get_ref when the index may be OOB, or bound the index yourself before calling.

Parameters:
Return type:

object

picop.containers.list_get_checked(l, i)#

Return l[i] via bounds-checked PyList_GetItem.

Notes

Raises IndexError on out-of-bounds (unlike unchecked list_get).

Parameters:
Return type:

object

picop.containers.list_get_ref(l, i)#

Return a strong ref to l[i] via PyList_GetItemRef.

Notes

Raises IndexError on out-of-bounds (unlike unchecked list_get).

Parameters:
Return type:

object

picop.containers.list_append(l, value)#

Append value via PyList_Append.

Notes

Returns 0 on success and -1 on error; errors raise. Do not use the status int as a bool.

Parameters:
Return type:

int

picop.containers.list_insert(l, i, value)#

Insert value at i via PyList_Insert.

Notes

Returns 0 on success and -1 on error; errors raise. Do not use the status int as a bool.

Parameters:
Return type:

int

picop.containers.list_extend(l, iterable)#

Extend l from iterable via PyList_Extend.

Notes

Returns 0 on success and -1 on error; errors raise. Do not use the status int as a bool.

Parameters:
Return type:

int

picop.containers.list_clear(l)#

Clear l via PyList_Clear.

Notes

Returns 0 on success and -1 on error; errors raise. Do not use the status int as a bool.

Parameters:

l (list)

Return type:

int

picop.containers.set_check(p)#

Return True if p is a set or subtype (PySet_Check). :type p: object :param p:

Return type:

bool

picop.containers.set_check_exact(p)#

Return True if type(p) is set (PySet_CheckExact). :type p: object :param p:

Return type:

bool

picop.containers.frozenset_check(p)#

Return True if p is a frozenset or subtype. :type p: object :param p:

Return type:

bool

picop.containers.frozenset_check_exact(p)#

Return True if type(p) is frozenset. :type p: object :param p:

Return type:

bool

picop.containers.frozenset_eq(a, b)#

Return True if typed frozensets are equal (identity/size short-circuit + richcompare). :type a: frozenset :param a: :type b: frozenset :param b:

Return type:

bool

picop.containers.set_contains(anyset, value)#

Return whether value is in anyset via PySet_Contains. :type anyset: object :param anyset: :type value: object :param value:

Return type:

bool

picop.containers.set_add(s, value)#

Add value via PySet_Add.

Notes

Returns 0 on success; errors raise. Do not use the status int as a bool.

Parameters:
Return type:

int

picop.containers.set_discard(s, value)#

Discard value via PySet_Discard.

Notes

Returns 1 if removed, 0 if absent (no KeyError). Errors raise. Do not treat the status int as a plain bool for success/failure.

Parameters:
Return type:

int

picop.containers.set_clear(s)#

Clear s via PySet_Clear.

Notes

Returns 0 on success; errors raise. Do not use the status int as a bool.

Parameters:

s (set)

Return type:

int

picop.containers.set_update(s, iterable)#

Update s from iterable via _PySet_Update.

Notes

Returns 0 on success; errors raise. Do not use the status int as a bool.

Parameters:
Return type:

int

picop.containers.set_len(s)#

Return len(s) via PySet_GET_SIZE (exact set). :type s: set :param s:

Return type:

int

picop.containers.set_eq(a, b)#

Return True if typed sets are equal (identity/size short-circuit + richcompare). :type a: set :param a: :type b: set :param b:

Return type:

bool

picop.containers.set_size(anyset)#

Return len(anyset) via checked PySet_Size.

Notes

Accepts set/frozenset/subtypes. Prefer set_len on a typed exact set hot path.

Parameters:

anyset (object)

Return type:

int

picop.containers.tuple_check(p)#

Return True if p is a tuple or subtype (PyTuple_Check). :type p: object :param p:

Return type:

bool

picop.containers.tuple_check_exact(p)#

Return True if type(p) is tuple (PyTuple_CheckExact). :type p: object :param p:

Return type:

bool

picop.containers.tuple_eq(a, b)#

Return True if typed tuples are equal (identity/len + richcompare). :type a: tuple :param a: :type b: tuple :param b:

Return type:

bool

picop.containers.tuple_len(t)#

Return len(t) via PyTuple_GET_SIZE. :type t: tuple[object, ...] :param t:

Return type:

int

picop.containers.tuple_size(t)#

Return len(t) via checked PyTuple_Size.

Notes

Prefer tuple_len on typed hot paths.

Parameters:

t (tuple[object, ...])

Return type:

int

picop.containers.tuple_get(t, i)#

Return t[i] via PyTuple_GET_ITEM.

Notes

Unchecked: out-of-bounds is undefined behavior. Prefer tuple_get_checked when the index may be OOB, or bound the index yourself before calling.

Parameters:
Return type:

object

picop.containers.tuple_get_checked(t, i)#

Return t[i] via bounds-checked PyTuple_GetItem.

Notes

Raises IndexError on out-of-bounds (unlike unchecked tuple_get).

Parameters:
Return type:

object

picop.containers.tuple_pack2(a, b)#

Return (a, b) via PyTuple_Pack. :type a: object :param a: :type b: object :param b:

Return type:

tuple[object, object]

picop.containers.tuple_pack3(a, b, c)#

Return (a, b, c) via PyTuple_Pack. :type a: object :param a: :type b: object :param b: :type c: object :param c:

Return type:

tuple[object, object, object]

picop.containers.tuple_pack4(a, b, c, d)#

Return (a, b, c, d) via PyTuple_Pack. :type a: object :param a: :type b: object :param b: :type c: object :param c: :type d: object :param d:

Return type:

tuple[object, object, object, object]