Commit 80ff11eb authored by Stefan Behnel's avatar Stefan Behnel

extended test cases for type inference in generators

parent 292c1eb0
...@@ -5,9 +5,48 @@ cimport cython ...@@ -5,9 +5,48 @@ cimport cython
def test_type_inference(): def test_type_inference():
""" """
>>> [ item for item in test_type_inference() ] >>> list(test_type_inference())
[(2.0, 'double'), (2.0, 'double'), (2.0, 'double')] [(2.0, 'double'), (2.0, 'double'), (2.0, 'double')]
""" """
x = 1.0 x = 1.0
for i in range(3): for i in range(3):
yield x * 2.0, cython.typeof(x) yield x * 2.0, cython.typeof(x)
def test_unicode_loop():
"""
>>> chars = list(test_unicode_loop())
1 Py_UCS4
2 Py_UCS4
2 Py_UCS4
2 Py_UCS4
2 Py_UCS4
>>> len(chars)
4
>>> ''.join(chars) == 'abcd'
True
"""
ustr = u'abcd'
print 1, cython.typeof(ustr[0])
for c in ustr:
print 2, cython.typeof(c)
yield c
def test_nonlocal_disables_inference():
"""
>>> chars = list(test_nonlocal_disables_inference())
1 Python object
2 Python object
2 Python object
>>> len(chars)
2
>>> ''.join(chars) == 'ab'
True
"""
ustr = u'ab'
print 1, cython.typeof(ustr[0])
def gen():
nonlocal ustr
for c in ustr:
print 2, cython.typeof(c)
yield c
return gen()
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