[New-bugs-announce] [issue28280] Always return a list from PyMapping_Keys/PyMapping_Values/PyMapping_Items
Serhiy Storchaka
report at bugs.python.org
Mon Sep 26 14:13:46 EDT 2016
New submission from Serhiy Storchaka:
PyMapping_Keys(), PyMapping_Values() and PyMapping_Items() can return a list or tuple (because they use PySequence_Fast). But end users of this API often work only with lists and raise an exception if corresponding mapping methods return an instance of other type (actually only for tuples). See Modules/posixmodule.c, Modules/_winapi.c, Modules/_sre.c. The type is even not checked in the latter file.
Old documentation said that PyMapping_Keys(o) is equivalent to the Python expression list(o.keys()). Maybe it is worth to make this true. Make PyMapping_Keys(o) etc always returning a list. This could simplify the code that uses this C API. Since keys() etc usually return a dict view, a list or a generator, but not a tuple, this unlikely will cause performance regression.
----------
components: Interpreter Core
messages: 277443
nosy: rhettinger, serhiy.storchaka, xiang.zhang
priority: normal
severity: normal
status: open
title: Always return a list from PyMapping_Keys/PyMapping_Values/PyMapping_Items
type: enhancement
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28280>
_______________________________________
More information about the New-bugs-announce
mailing list