picop.cydict#

Fast dict accessors.

picop.cydict.dict_check(p)#

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

Return type:

bool

Parameters:

p (object)

picop.cydict.dict_check_exact(p)#

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

Return type:

bool

Parameters:

p (object)

picop.cydict.dict_clear(d)#

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

Return type:

None

Parameters:

d (dict)

picop.cydict.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.cydict.dict_copy(d)#

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

Return type:

dict

Parameters:

d (dict)

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

Parameters:
picop.cydict.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.cydict.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.cydict.dict_get_with_error(d, key)#

Return d[key] via PyDict_GetItemWithError.

Notes

Hash/equality errors propagate. Missing keys yield None (same missing-vs-stored-None ambiguity as dict_get).

Parameters:
Return type:

object

picop.cydict.dict_len(d)#

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

Return type:

int

Parameters:

d (dict)

picop.cydict.dict_merge(d, other, override=True)#

Merge other into d via PyDict_Merge.

Notes

override controls whether existing keys are overwritten. Returns 0 on success and -1 on error; errors raise. Do not use the status int as a bool.

Parameters:
Return type:

int

picop.cydict.dict_merge_from_seq2(d, seq2, override=True)#

Merge key/value pairs from seq2 via PyDict_MergeFromSeq2.

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.cydict.dict_new()#

Return a new empty dict (PyDict_New).

Return type:

dict

picop.cydict.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.cydict.dict_proxy(d)#

Return a read-only mappingproxy over d (PyDictProxy_New). :type d: dict :param d:

Return type:

object

picop.cydict.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.cydict.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.cydict.dict_setdefault_ref(d, key, default=None)#

Return setdefault via strong-ref PyDict_SetDefaultRef. :type d: dict :param d: :type key: object :param key: :type default: object, default: None :param default:

Return type:

object

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