summaryrefslogtreecommitdiff
path: root/tests/run/type_inference.pyx
diff options
context:
space:
mode:
Diffstat (limited to 'tests/run/type_inference.pyx')
-rw-r--r--tests/run/type_inference.pyx56
1 files changed, 54 insertions, 2 deletions
diff --git a/tests/run/type_inference.pyx b/tests/run/type_inference.pyx
index d2bef6431..e61b2dcdf 100644
--- a/tests/run/type_inference.pyx
+++ b/tests/run/type_inference.pyx
@@ -242,7 +242,7 @@ def c_functions():
>>> c_functions()
"""
f = cfunc
- assert typeof(f) == 'int (*)(int)', typeof(f)
+ assert typeof(f) == 'int (*)(int) except? -1', typeof(f)
assert 2 == f(1)
def builtin_functions():
@@ -276,6 +276,9 @@ def cascade():
assert typeof(e) == "double"
def cascaded_assignment():
+ """
+ >>> cascaded_assignment()
+ """
a = b = c = d = 1.0
assert typeof(a) == "double"
assert typeof(b) == "double"
@@ -284,6 +287,36 @@ def cascaded_assignment():
e = a + b + c + d
assert typeof(e) == "double"
+
+def unpacking(x):
+ """
+ >>> unpacking(0)
+ """
+ a, b, c, (d, e) = x, 1, 2.0, [3, [5, 6]]
+ assert typeof(a) == "Python object", typeof(a)
+ assert typeof(b) == "long", typeof(b)
+ assert typeof(c) == "double", typeof(c)
+ assert typeof(d) == "long", typeof(d)
+ assert typeof(e) == "list object", typeof(e)
+
+
+def star_unpacking(*x):
+ """
+ >>> star_unpacking(1, 2)
+ """
+ a, b = x
+ c, *d = x
+ *e, f = x
+ *g, g = x # re-assignment
+ assert typeof(a) == "Python object", typeof(a)
+ assert typeof(b) == "Python object", typeof(b)
+ assert typeof(c) == "Python object", typeof(c)
+ assert typeof(d) == "list object", typeof(d)
+ assert typeof(e) == "list object", typeof(e)
+ assert typeof(f) == "Python object", typeof(f)
+ assert typeof(g) == "Python object", typeof(f)
+
+
def increment():
"""
>>> increment()
@@ -498,13 +531,19 @@ def safe_only():
cdef int c_int = 1
assert typeof(abs(c_int)) == "int", typeof(abs(c_int))
+ # float can be inferred
+ cdef float fl = 5.0
+ from_fl = fl
+ assert typeof(from_fl) == "float", typeof(from_fl)
+
+
@infer_types(None)
def safe_c_functions():
"""
>>> safe_c_functions()
"""
f = cfunc
- assert typeof(f) == 'int (*)(int)', typeof(f)
+ assert typeof(f) == 'int (*)(int) except? -1', typeof(f)
assert 2 == f(1)
@infer_types(None)
@@ -756,3 +795,16 @@ def test_bound_methods():
default_arg = o.default_arg
assert default_arg(2) == 12, default_arg(2)
assert default_arg(2, 3) == 15, default_arg(2, 2)
+
+def test_builtin_max():
+ """
+ # builtin max is slightly complicated because it gets transformed to EvalWithTempExprNode
+ # See https://github.com/cython/cython/issues/4155
+ >>> test_builtin_max()
+ """
+ class C:
+ a = 2
+ def get_max(self):
+ a = max(self.a, self.a)
+ assert typeof(a) == "Python object", typeof(a)
+ C().get_max()