Commit 2e216822 authored by Robert Bradshaw's avatar Robert Bradshaw

Allow coercion of C literal lists to stl types.

parent 9d9657fa
......@@ -6687,6 +6687,9 @@ class ListNode(SequenceNode):
if isinstance(arg, CoerceToPyTypeNode):
arg = arg.arg
self.args[i] = arg.coerce_to(base_type, env)
elif dst_type.is_cpp_class:
# TODO(robertwb): Avoid object conversion for vector/list/set.
return TypecastNode(self.pos, operand=self, type=PyrexTypes.py_object_type).coerce_to(dst_type, env)
elif self.mult_factor:
error(self.pos, "Cannot coerce multiplied list to '%s'" % dst_type)
elif dst_type.is_struct:
......
......@@ -116,6 +116,14 @@ def test_double_vector(o):
cdef vector[double] v = o
return v
def test_repeated_double_vector(a, b, int n):
"""
>>> test_repeated_double_vector(1, 1.5, 3)
[1.0, 1.5, 1.0, 1.5, 1.0, 1.5]
"""
cdef vector[double] v = [a, b] * n
return v
ctypedef int my_int
def test_typedef_vector(o):
......
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