[Python-Dev] Undocumented change / bug in Python3's PyMapping_Check (original) (raw)

John Millikin jmillikin at gmail.com
Tue May 5 07:19:36 CEST 2009


In Python 2, PyMapping_Check will return 0 for list objects. In Python 3, it returns 1. Obviously, this makes it rather difficult to differentiate between mappings and other sized iterables. In addition, it differs from the behavior of the collections.Mapping ABC -- isinstance([], collections.Mapping) returns False.

I believe the new behavior is erroneous, but would like to confirm that before filing a bug.

The behavior can be seen from a C extension, or if you're lazy, using ctypes:

Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import ctypes ctypes.CDLL('libpython2.6.so').PyMappingCheck(ctypes.pyobject([])) 0

Python 3.0.1+ (r301:69556, Apr 15 2009, 15:59:22) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import ctypes ctypes.CDLL('libpython3.0.so').PyMappingCheck(ctypes.pyobject([])) 1



More information about the Python-Dev mailing list