Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1637c04
[WIP] PEP 814: Add built-in frozendict type
vstinner Nov 2, 2025
49aca48
Update Tools/build/generate_token.py for token.py
vstinner Nov 13, 2025
3299299
Try to fix build on Ubuntu and macOS
vstinner Nov 13, 2025
18ce520
Fix make check-c-globals
vstinner Nov 13, 2025
1a72eec
Add PyFrozenDict_Type to static_types
vstinner Nov 13, 2025
9d6ca58
Update Doc/library/stdtypes.rst
vstinner Nov 13, 2025
439c98c
Replace PyDict_Check() with _PyAnyDict_Check()
vstinner Nov 13, 2025
4a1a504
copy: support frozendict
vstinner Nov 13, 2025
302767b
Fix frozendict.__reduce_ex__()
vstinner Nov 13, 2025
07b3510
exec(): accept frozendict for globals
vstinner Nov 13, 2025
04f66ad
Make PyAnyDict_Check() public
vstinner Nov 13, 2025
6fca6d1
Optimize frozendict.copy()
vstinner Nov 14, 2025
6727967
Fix frozendict merge ("|=" operator); add tests
vstinner Nov 14, 2025
d231cdb
copy: use _copy_atomic_types instead; add tests
vstinner Nov 14, 2025
3a07c46
frozendict
vstinner Nov 14, 2025
bc25bb2
pprint supports frozendict
vstinner Nov 14, 2025
0acff5e
change json.tool._group_to_theme_color formatting
vstinner Nov 14, 2025
e90156e
json: use PyAnyDict_Check()
vstinner Nov 14, 2025
fe7e7f5
_pickle: fix refleak
vstinner Nov 14, 2025
4c5c8d2
frozendict_hash: use atomic load/store
vstinner Nov 14, 2025
0a57448
Update Lib/pydoc_data/topics.py
vstinner Nov 14, 2025
fc66056
Fix test_copy: remove duplicated test
vstinner Nov 17, 2025
c1f5055
frozendict | {} returns the same frozendict
vstinner Dec 12, 2025
6ff9c67
Fix frozendict_or()
vstinner Dec 12, 2025
9a64439
Moar frozendict|frozendict optimizations
vstinner Dec 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make PyAnyDict_Check() public
  • Loading branch information
vstinner committed Nov 13, 2025
commit 04f66ad6eade13f97a7be3e064527f916ef5e6cf
6 changes: 3 additions & 3 deletions Include/cpython/dictobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ PyAPI_DATA(PyTypeObject) PyFrozenDict_Type;
#define PyFrozenDict_Check(op) PyObject_TypeCheck((op), &PyFrozenDict_Type)
#define PyFrozenDict_CheckExact(op) Py_IS_TYPE((op), &PyFrozenDict_Type)

#define _PyAnyDict_CheckExact(ob) \
#define PyAnyDict_CheckExact(ob) \
(PyDict_CheckExact(ob) || PyFrozenDict_CheckExact(ob))
#define _PyAnyDict_Check(ob) \
#define PyAnyDict_Check(ob) \
(PyDict_Check(ob) || PyFrozenDict_Check(ob))

PyAPI_FUNC(PyObject *) _PyDict_GetItem_KnownHash(PyObject *mp, PyObject *key,
Expand All @@ -62,7 +62,7 @@ PyAPI_FUNC(int) PyDict_SetDefaultRef(PyObject *mp, PyObject *key, PyObject *defa
/* Get the number of items of a dictionary. */
static inline Py_ssize_t PyDict_GET_SIZE(PyObject *op) {
PyDictObject *mp;
assert(_PyAnyDict_Check(op));
assert(PyAnyDict_Check(op));
mp = _Py_CAST(PyDictObject*, op);
#ifdef Py_GIL_DISABLED
return _Py_atomic_load_ssize_relaxed(&mp->ma_used);
Expand Down
2 changes: 1 addition & 1 deletion Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2403,7 +2403,7 @@ defdict_or(PyObject* left, PyObject* right)
self = right;
other = left;
}
if (!_PyAnyDict_Check(other)) {
if (!PyAnyDict_Check(other)) {
Py_RETURN_NOTIMPLEMENTED;
}
// Like copy(), this calls the object's class.
Expand Down
4 changes: 2 additions & 2 deletions Modules/_pickle.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ _Pickle_InitState(PickleState *st)
PyObject_GetAttrString(compat_pickle, "NAME_MAPPING");
if (!st->name_mapping_2to3)
goto error;
if (!_PyAnyDict_CheckExact(st->name_mapping_2to3)) {
if (!PyAnyDict_CheckExact(st->name_mapping_2to3)) {
PyErr_Format(PyExc_RuntimeError,
"_compat_pickle.NAME_MAPPING should be a dict, not %.200s",
Py_TYPE(st->name_mapping_2to3)->tp_name);
Expand All @@ -335,7 +335,7 @@ _Pickle_InitState(PickleState *st)
PyObject_GetAttrString(compat_pickle, "IMPORT_MAPPING");
if (!st->import_mapping_2to3)
goto error;
if (!_PyAnyDict_CheckExact(st->import_mapping_2to3)) {
if (!PyAnyDict_CheckExact(st->import_mapping_2to3)) {
PyErr_Format(PyExc_RuntimeError,
"_compat_pickle.IMPORT_MAPPING should be a dict, "
"not %.200s", Py_TYPE(st->import_mapping_2to3)->tp_name);
Expand Down
10 changes: 5 additions & 5 deletions Objects/abstract.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ PyObject_GetItem(PyObject *o, PyObject *key)
int
PyMapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **result)
{
if (_PyAnyDict_CheckExact(obj)) {
if (PyAnyDict_CheckExact(obj)) {
return PyDict_GetItemRef(obj, key, result);
}

Expand Down Expand Up @@ -1672,7 +1672,7 @@ PyNumber_ToBase(PyObject *n, int base)
int
PySequence_Check(PyObject *s)
{
if (_PyAnyDict_Check(s))
if (PyAnyDict_Check(s))
return 0;
return Py_TYPE(s)->tp_as_sequence &&
Py_TYPE(s)->tp_as_sequence->sq_item != NULL;
Expand Down Expand Up @@ -2454,7 +2454,7 @@ PyMapping_Keys(PyObject *o)
if (o == NULL) {
return null_error();
}
if (_PyAnyDict_CheckExact(o)) {
if (PyAnyDict_CheckExact(o)) {
return PyDict_Keys(o);
}
return method_output_as_list(o, &_Py_ID(keys));
Expand All @@ -2466,7 +2466,7 @@ PyMapping_Items(PyObject *o)
if (o == NULL) {
return null_error();
}
if (_PyAnyDict_CheckExact(o)) {
if (PyAnyDict_CheckExact(o)) {
return PyDict_Items(o);
}
return method_output_as_list(o, &_Py_ID(items));
Expand All @@ -2478,7 +2478,7 @@ PyMapping_Values(PyObject *o)
if (o == NULL) {
return null_error();
}
if (_PyAnyDict_CheckExact(o)) {
if (PyAnyDict_CheckExact(o)) {
return PyDict_Values(o);
}
return method_output_as_list(o, &_Py_ID(values));
Expand Down
2 changes: 1 addition & 1 deletion Objects/descrobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ static int
mappingproxy_contains(PyObject *self, PyObject *key)
{
mappingproxyobject *pp = (mappingproxyobject *)self;
if (_PyAnyDict_CheckExact(pp->mapping))
if (PyAnyDict_CheckExact(pp->mapping))
return PyDict_Contains(pp->mapping, key);
else
return PySequence_Contains(pp->mapping, key);
Expand Down
Loading
Loading