[New-bugs-announce] [issue31586] SystemError in _collections._count_element() in case of a bad mapping argument

Oren Milman report at bugs.python.org
Tue Sep 26 02:32:28 EDT 2017


New submission from Oren Milman:

The following code causes a SystemError:
class BadMapping:
    get = dict.get
    __setitem__ = dict.__setitem__

import _collections
_collections._count_elements(BadMapping(), [42])


This is because _count_elements() (in Modules/_collectionsmodule.c) assumes
that the mapping argument is a dictionary in case it has the same get() and
__setitem__() methods as dict. And so, _count_elements() passes the mapping
argument to _PyDict_GetItem_KnownHash(), which raises the SystemError.


ISTM it is a very unlikely corner case, so that adding a test (as well as
a NEWS.d item) for it is unnecessary.
What do you think?

----------
components: Extension Modules
messages: 303014
nosy: Oren Milman
priority: normal
severity: normal
status: open
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31586>
_______________________________________


More information about the New-bugs-announce mailing list