picop.cydict#

Fast dict accessors.

picop.cydict.dict_check(p)#

Return True if p is a dict or subtype (PyDict_Check).

Parameters:

p (object)

Return type:

bool

picop.cydict.dict_check_exact(p)#

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

Parameters:

p (object)

Return type:

bool

picop.cydict.dict_clear(d)#

Clear d via PyDict_Clear.

Parameters:

d (dict)

Return type:

None

picop.cydict.dict_contains(d, key)#

Return whether key is in d (PyDict_Contains).

Parameters:
Return type:

bool

picop.cydict.dict_copy(d)#

Return a shallow copy of d via PyDict_Copy.

Parameters:

d (dict)

Return type:

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

Parameters:
Return type:

bool

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_items_check(obj)#

Return whether obj is a dict_items view.

Parameters:

obj (object)

Return type:

bool

picop.cydict.dict_keys_check(obj)#

Return whether obj is a dict_keys view.

Parameters:

obj (object)

Return type:

bool

picop.cydict.dict_len(d)#

Return len(d) via PyDict_GET_SIZE.

Parameters:

d (dict)

Return type:

int

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

Parameters:

d (dict)

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.

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

picop.cydict.dict_values_check(obj)#

Return whether obj is a dict_values view.

Parameters:

obj (object)

Return type:

bool

picop.cydict.dict_view_check(obj)#

Return PyDictViewSet_Check: true for keys and items, not values.

Parameters:

obj (object)

Return type:

bool