picop.containers#

Category facade: typed Core containers (dict / frozendict / 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).

Parameters:

p (object)

Return type:

bool

picop.containers.dict_check_exact(p)#

Return True if type(p) is dict (PyDict_CheckExact).

Parameters:

p (object)

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).

Parameters:
Return type:

bool

picop.containers.dict_len(d)#

Return len(d) via PyDict_GET_SIZE.

Parameters:

d (dict)

Return type:

int

picop.containers.dict_eq(a, b)#

Return True if typed dicts are equal (identity/size short-circuit + richcompare).

Parameters:
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.

Parameters:

d (dict)

Return type:

None

picop.containers.dict_copy(d)#

Return a shallow copy of d via PyDict_Copy.

Parameters:

d (dict)

Return type:

dict

picop.containers.dict_new()#

Return a new empty dict (PyDict_New).

Return type:

dict

picop.containers.frozendict_check(obj)#

Return True if obj is a frozendict or a frozendict subtype.

Parameters:

obj (object)

Return type:

bool

picop.containers.frozendict_check_exact(obj)#

Return True if obj is exactly a frozendict (subtypes excluded).

Parameters:

obj (object)

Return type:

bool

picop.containers.frozendict_empty()#

Return an empty frozendict without building an iterable.

Notes

raises NotImplementedError on 3.14.

Return type:

object

picop.containers.frozendict_new(iterable)#

Return a new frozendict built from an iterable.

Notes

None is not iterable — use frozendict_empty() for the no-iterable path. Passing an existing frozendict returns the same object with an incremented reference, not a copy. Raises NotImplementedError on 3.14.

Parameters:

iterable (object)

Return type:

object

picop.containers.anydict_check(obj)#

Return True if obj is a dict or a frozendict (subtypes included).

Notes

mirrors PyAnyDict_Check; on 3.14 this is dict_check.

Parameters:

obj (object)

Return type:

bool

picop.containers.anydict_check_exact(obj)#

Return True if obj is exactly a dict or exactly a frozendict.

Notes

dict subclasses such as defaultdict are False.

Parameters:

obj (object)

Return type:

bool

picop.containers.anydict_len(obj)#

Return the entry count of a dict or frozendict.

Notes

raises TypeError for anything else; the read uses the PyDict_GET_SIZE layout shared by dict and frozendict.

Parameters:

obj (object)

Return type:

int

picop.containers.list_check(p)#

Return True if p is a list or subtype (PyList_Check).

Parameters:

p (object)

Return type:

bool

picop.containers.list_check_exact(p)#

Return True if type(p) is list (PyList_CheckExact).

Parameters:

p (object)

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).

Parameters:
Return type:

bool

picop.containers.list_len(l)#

Return len(l) via PyList_GET_SIZE.

Parameters:

l (list)

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).

Parameters:

p (object)

Return type:

bool

picop.containers.set_check_exact(p)#

Return True if type(p) is set (PySet_CheckExact).

Parameters:

p (object)

Return type:

bool

picop.containers.frozenset_check(p)#

Return True if p is a frozenset or subtype.

Parameters:

p (object)

Return type:

bool

picop.containers.frozenset_check_exact(p)#

Return True if type(p) is frozenset.

Parameters:

p (object)

Return type:

bool

picop.containers.frozenset_eq(a, b)#

Return True if typed frozensets are equal (identity/size short-circuit + richcompare).

Parameters:
Return type:

bool

picop.containers.set_contains(anyset, value)#

Return whether value is in anyset via PySet_Contains.

Parameters:
Return type:

bool

picop.containers.set_add(s, value)#

Add value via PySet_Add.

Notes

Slower than the plain-Python equivalent s.add(v) (Tier A 1.07x); unchecked set mutation.

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

Slower than the plain-Python equivalent s.discard(v) (Tier A 1.04–1.06x); unchecked set mutation.

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

Slower than the plain-Python equivalent s.clear() (Tier A 1.03x); unchecked set mutation.

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

Slower than the plain-Python equivalent s.update(it) (Tier A 1.07x); unchecked set mutation.

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).

Parameters:

s (set)

Return type:

int

picop.containers.set_eq(a, b)#

Return True if typed sets are equal (identity/size short-circuit + richcompare).

Parameters:
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).

Parameters:

p (object)

Return type:

bool

picop.containers.tuple_check_exact(p)#

Return True if type(p) is tuple (PyTuple_CheckExact).

Parameters:

p (object)

Return type:

bool

picop.containers.tuple_eq(a, b)#

Return True if typed tuples are equal (identity/len + richcompare).

Parameters:
Return type:

bool

picop.containers.tuple_len(t)#

Return len(t) via PyTuple_GET_SIZE.

Parameters:

t (tuple[object, ...])

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.

Parameters:
Return type:

tuple[object, object]

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

Return (a, b, c) via PyTuple_Pack.

Parameters:
Return type:

tuple[object, object, object]

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

Return (a, b, c, d) via PyTuple_Pack.

Parameters:
Return type:

tuple[object, object, object, object]