picop.hot#

Curated micro-opt starters — prefer from picop.hot import over the flat barrel.

Core frozen at 1.0 — this __all__ is part of the stable Core surface (additive minors OK; removals need a major). Full public surface remains on picop / picop.cy*. Soft letter/bare aliases were removed in 0.3. See Quickstart and Safety.

picop.hot.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.hot.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.hot.dict_len(d)#

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

Return type:

int

Parameters:

d (dict)

picop.hot.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

Parameters:
picop.hot.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.hot.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.hot.list_len(l)#

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

Return type:

int

Parameters:

l (list)

picop.hot.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.hot.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.hot.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.hot.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

Parameters:
picop.hot.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.hot.tuple_len(t)#

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

Return type:

int

Parameters:

t (tuple[object, ...])

picop.hot.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.hot.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]

Parameters:
picop.hot.bytes_len(b)#

Return len(b) via PyBytes_GET_SIZE. :type b: bytes :param b:

Return type:

int

Parameters:

b (bytes)

picop.hot.bytes_contains(haystack, needle)#

Return True if needle is in haystack.

Notes

Uses memchr/memmem under 256B, else the builtin in path.

Parameters:
Return type:

bool

picop.hot.bytes_eq(a, b)#

Return True if a == b.

Notes

Identity/len short-circuit plus memcmp on typed bytes.

Parameters:
Return type:

bool

picop.hot.bytes_ne(a, b)#

Return True if a != b (inverse of bytes_eq). :type a: bytes :param a: :type b: bytes :param b:

Return type:

bool

Parameters:
picop.hot.bytes_startswith(s, prefix)#

Return True if typed s begins with prefix.

Notes

Length gate plus memcmp on the typed prefix region.

Parameters:
Return type:

bool

picop.hot.bytes_endswith(s, suffix)#

Return True if typed s ends with suffix.

Notes

Length gate plus tail memcmp on the typed suffix region.

Parameters:
Return type:

bool

picop.hot.bytearray_eq(a, b)#

Return True if typed bytearray values are equal.

Notes

Identity/len short-circuit plus memcmp.

Parameters:
Return type:

bool

picop.hot.bytearray_ne(a, b)#

Return True if typed bytearray values differ (not bytearray_eq). :type a: bytearray :param a: :type b: bytearray :param b:

Return type:

bool

Parameters:
picop.hot.bytearray_contains(haystack, needle)#

Return True if needle is found in typed haystack.

Notes

Mirrors bytes_contains search strategy on a typed bytearray.

Parameters:
Return type:

bool

picop.hot.array_eq(a, b)#

Return True if typed array.array values are equal.

Notes

Compares typecode/len then memcmp.

Parameters:
Return type:

bool

picop.hot.array_ne(a, b)#

Return True if typed array.array values differ (not array_eq). :type a: array :param a: :type b: array :param b:

Return type:

bool

Parameters:
picop.hot.memoryview_eq(a, b)#

Return True if views are equal.

Notes

C-contiguous buffers use a memcmp fast path; otherwise falls back to richcompare.

Parameters:
Return type:

bool

picop.hot.memoryview_ne(a, b)#

Return True if views differ.

Notes

Inverse of memoryview_eq; same contig/richcompare rules.

Parameters:
Return type:

bool

picop.hot.str_len(s)#

Return len(s) via PyUnicode_GET_LENGTH. :type s: str :param s:

Return type:

int

Parameters:

s (str)

picop.hot.str_eq(a, b)#

Return whether a == b.

Notes

Uses 1BYTE memcmp or PyUnicode_Compare depending on kind.

Parameters:
Return type:

bool

picop.hot.str_contains(haystack, needle)#

Return whether needle is in haystack.

Notes

Uses 1BYTE memchr/memmem or Find depending on kind.

Parameters:
Return type:

bool

picop.hot.ansi_wrap(prefix, text, suffix=None)#

Return prefix + text + suffix.

Notes

Default suffix is the ANSI reset sequence.

Parameters:
Return type:

str

picop.hot.ansi_fg8(code)#

Return an 8-color foreground SGR for code.

Notes

Table hit for codes 3037.

Parameters:

code (int)

Return type:

str

picop.hot.ansi_strip(s)#

Remove CSI sequences from s in a single pass.

Notes

Returns s unchanged when no CSI sequences are present.

Parameters:

s (str)

Return type:

str