这是怎么回事?在
>>> list(map(lambda *x: x, *map(None, 'abc')))
Traceback (most recent call last):
File "<pyshell#52>", line 1, in <module>
list(map(lambda *x: x, *map(None, 'abc')))
TypeError: type object argument after * must be an iterable, not map
忽略代码的无意义。这是关于错误消息,“iterable,not map”。地图是可编辑的,不是吗?在
如果我只将None
替换为str
,整个过程都很好:
所以现在Python对map
没有任何问题。在
这在我的python3.6.1中发生过。相反,我的python3.5.2引发了预期的TypeError: 'NoneType' object is not callable
。而google搜索"must be an iterable, not map"根本找不到任何结果。很明显这是最近才被介绍的。在
这只是一个Python bug吗?或者这有什么意义吗?在
更新:Reported as bug如建议。在
我认为这是个虫子。以下是导致此异常的原因:
https://github.com/python/cpython/blob/b1660800f4f519dbfab9e5a4ad3eae1cfabab3ed/Python/ceval.c#L2514-L2523
对python字节码的反汇编确认它正在使用
BUILD_TUPLE_UNPACK_WITH_CALL
上面代码中的“bug”是假设任何
TypeError
,而_PyList_Extend
参数数组意味着它不是iterable,但是__iter__
本身可能引发类型错误。它正在重新抛出这个异常我建议在https://bugs.python.org打开一个bug
相关问题 更多 >
编程相关推荐