From 0c7abc14f52623616c24f9cc37f79b2aa206a9b8 Mon Sep 17 00:00:00 2001 From: jbarlow83 Date: Thu, 16 Feb 2017 00:43:23 -0800 Subject: [PATCH 1/3] mapping.rst: PyMapping_Check(list) returns 1 As discussed below, in Python 3, PyMapping_Check(list) returns 1. This behavior is justified by a developer as consistent with Python 3's internals. It is however surprising to C-API users (speaking from experience) and because it deviates from collections.abc.Mapping. https://mail.python.org/pipermail/python-dev/2009-May/089445.html Squashed a few revisions --- Doc/c-api/mapping.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Doc/c-api/mapping.rst b/Doc/c-api/mapping.rst index a71e94283776e9..1aec0148c9b4c4 100644 --- a/Doc/c-api/mapping.rst +++ b/Doc/c-api/mapping.rst @@ -9,7 +9,9 @@ Mapping Protocol .. c:function:: int PyMapping_Check(PyObject *o) Return ``1`` if the object provides mapping protocol, and ``0`` otherwise. This - function always succeeds. + function always succeeds. The C-API mapping protocol is not equivalent to + :class:`collections.abc.Mapping`. In particular, ``PyMapping_Check(list)`` + returns ``1``. .. c:function:: Py_ssize_t PyMapping_Size(PyObject *o) From be98854415d97981b1a1b5e1522c7579e6360646 Mon Sep 17 00:00:00 2001 From: jbarlow83 Date: Thu, 22 Feb 2018 17:06:31 -0800 Subject: [PATCH 2/3] Update mapping.rst --- Doc/c-api/mapping.rst | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Doc/c-api/mapping.rst b/Doc/c-api/mapping.rst index 1aec0148c9b4c4..1f5432c6860e5b 100644 --- a/Doc/c-api/mapping.rst +++ b/Doc/c-api/mapping.rst @@ -8,10 +8,11 @@ Mapping Protocol .. c:function:: int PyMapping_Check(PyObject *o) - Return ``1`` if the object provides mapping protocol, and ``0`` otherwise. This - function always succeeds. The C-API mapping protocol is not equivalent to - :class:`collections.abc.Mapping`. In particular, ``PyMapping_Check(list)`` - returns ``1``. + **Not recommended.** Return ``1`` if the object provides the C-API mapping + protocol, and ``0`` otherwise. This function always succeeds. The C-API + mapping protocol is not equivalent to :class:`collections.abc.Mapping`, and + also returns ``1`` for sequences that support slicing. Use + :c:func::`PyObject_IsInstance` instead. .. c:function:: Py_ssize_t PyMapping_Size(PyObject *o) From 463418bf67109248dbbfe534d7cec93558280cdd Mon Sep 17 00:00:00 2001 From: jbarlow83 Date: Sun, 20 May 2018 22:00:33 -0700 Subject: [PATCH 3/3] Remove alternative to PyMapping_Check --- Doc/c-api/mapping.rst | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Doc/c-api/mapping.rst b/Doc/c-api/mapping.rst index 1f5432c6860e5b..347c7869a17149 100644 --- a/Doc/c-api/mapping.rst +++ b/Doc/c-api/mapping.rst @@ -9,10 +9,8 @@ Mapping Protocol .. c:function:: int PyMapping_Check(PyObject *o) **Not recommended.** Return ``1`` if the object provides the C-API mapping - protocol, and ``0`` otherwise. This function always succeeds. The C-API - mapping protocol is not equivalent to :class:`collections.abc.Mapping`, and - also returns ``1`` for sequences that support slicing. Use - :c:func::`PyObject_IsInstance` instead. + protocol, and ``0`` otherwise. This function always succeeds. PyMapping_Check() + also returns 1 for sequences that support slicing. .. c:function:: Py_ssize_t PyMapping_Size(PyObject *o)