Commit f324eca3 authored by Stefan Behnel's avatar Stefan Behnel

prevent dict iter optimisation from striking at methods with unusual number of arguments

parent d15a656c
...@@ -164,9 +164,16 @@ class IterationTransform(Visitor.VisitorTransform): ...@@ -164,9 +164,16 @@ class IterationTransform(Visitor.VisitorTransform):
if not isinstance(iterator, ExprNodes.SimpleCallNode): if not isinstance(iterator, ExprNodes.SimpleCallNode):
return node return node
if iterator.args is None:
arg_count = iterator.arg_tuple and len(iterator.arg_tuple.args) or 0
else:
arg_count = len(iterator.args)
if arg_count and iterator.self is not None:
arg_count -= 1
function = iterator.function function = iterator.function
# dict iteration? # dict iteration?
if function.is_attribute and not reversed: if function.is_attribute and not reversed and not arg_count:
base_obj = iterator.self or function.obj base_obj = iterator.self or function.obj
method = function.attribute method = function.attribute
......
...@@ -174,6 +174,17 @@ def iterkeys(dict d): ...@@ -174,6 +174,17 @@ def iterkeys(dict d):
l.sort() l.sort()
return l return l
@cython.test_fail_if_path_exists(
"//WhileStatNode",
"//WhileStatNode//DictIterationNextNode")
def iterkeys_argerror(dict d):
"""
>>> try: iterkeys_argerror(d)
... except TypeError: pass
"""
for k in d.iterkeys(1):
print k
@cython.test_assert_path_exists( @cython.test_assert_path_exists(
"//WhileStatNode", "//WhileStatNode",
"//WhileStatNode//DictIterationNextNode") "//WhileStatNode//DictIterationNextNode")
...@@ -203,6 +214,17 @@ def optimistic_iterkeys(d): ...@@ -203,6 +214,17 @@ def optimistic_iterkeys(d):
l.sort() l.sort()
return l return l
@cython.test_fail_if_path_exists(
"//WhileStatNode",
"//WhileStatNode//DictIterationNextNode")
def optimistic_iterkeys_argerror(d):
"""
>>> try: optimistic_iterkeys_argerror(d)
... except TypeError: pass
"""
for k in d.iterkeys(1):
print k
@cython.test_assert_path_exists( @cython.test_assert_path_exists(
"//WhileStatNode", "//WhileStatNode",
"//WhileStatNode//DictIterationNextNode") "//WhileStatNode//DictIterationNextNode")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment