Commit ae67505e authored by da-woods's avatar da-woods Committed by GitHub

Allow cast to ctuple (GH-3812)

parent fd1a431b
......@@ -316,9 +316,12 @@ def p_typecast(s):
s.next()
base_type = p_c_base_type(s)
is_memslice = isinstance(base_type, Nodes.MemoryViewSliceTypeNode)
is_template = isinstance(base_type, Nodes.TemplatedTypeNode)
is_const_volatile = isinstance(base_type, Nodes.CConstOrVolatileTypeNode)
if not is_memslice and not is_template and not is_const_volatile and base_type.name is None:
is_other_unnamed_type = isinstance(base_type, (
Nodes.TemplatedTypeNode,
Nodes.CConstOrVolatileTypeNode,
Nodes.CTupleBaseTypeNode,
))
if not (is_memslice or is_other_unnamed_type) and base_type.name is None:
s.error("Unknown type")
declarator = p_c_declarator(s, empty = 1)
if s.sy == '?':
......
......@@ -142,6 +142,17 @@ cpdef (int, double) cpdef_ctuple_return_type(int x, double y):
return x, y
def cast_to_ctuple(*o):
"""
>>> cast_to_ctuple(1, 2.)
(1, 2.0)
"""
cdef int x
cdef double y
x, y = <(int, double)>o
return x, y
@cython.infer_types(True)
def test_type_inference():
"""
......
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