Commit e5c86145 authored by Stefan Behnel's avatar Stefan Behnel

merged in latest cython-devel

parents b67d841c 8f8ef5cd
...@@ -3655,9 +3655,9 @@ class SequenceNode(ExprNode): ...@@ -3655,9 +3655,9 @@ class SequenceNode(ExprNode):
code.put_gotref(item.py_result()) code.put_gotref(item.py_result())
value_node = self.coerced_unpacked_items[i] value_node = self.coerced_unpacked_items[i]
value_node.generate_evaluation_code(code) value_node.generate_evaluation_code(code)
code.put_error_if_neg(self.pos, code.put_error_if_neg(self.pos, "__Pyx_EndUnpack(%s, %d)" % (
"__Pyx_EndUnpack(%s)" % ( self.iterator.py_result(),
self.iterator.py_result())) len(self.args)))
if debug_disposal_code: if debug_disposal_code:
print("UnpackNode.generate_assignment_code:") print("UnpackNode.generate_assignment_code:")
print("...generating disposal code for %s" % self.iterator) print("...generating disposal code for %s" % self.iterator)
...@@ -7228,11 +7228,16 @@ impl = """ ...@@ -7228,11 +7228,16 @@ impl = """
raise_too_many_values_to_unpack = UtilityCode( raise_too_many_values_to_unpack = UtilityCode(
proto = """ proto = """
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(void); static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);
""", """,
impl = ''' impl = '''
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(void) { static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
PyErr_SetString(PyExc_ValueError, "too many values to unpack"); PyErr_Format(PyExc_ValueError,
#if PY_VERSION_HEX < 0x02050000
"too many values to unpack (expected %d)", (int)expected);
#else
"too many values to unpack (expected %zd)", expected);
#endif
} }
''') ''')
...@@ -7265,7 +7270,7 @@ static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) { ...@@ -7265,7 +7270,7 @@ static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) {
} else if (PyTuple_GET_SIZE(t) < index) { } else if (PyTuple_GET_SIZE(t) < index) {
__Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(t)); __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(t));
} else { } else {
__Pyx_RaiseTooManyValuesError(); __Pyx_RaiseTooManyValuesError(index);
} }
} }
""", """,
...@@ -7277,7 +7282,7 @@ requires = [raise_none_iter_error_utility_code, ...@@ -7277,7 +7282,7 @@ requires = [raise_none_iter_error_utility_code,
unpacking_utility_code = UtilityCode( unpacking_utility_code = UtilityCode(
proto = """ proto = """
static PyObject *__Pyx_UnpackItem(PyObject *, Py_ssize_t index); /*proto*/ static PyObject *__Pyx_UnpackItem(PyObject *, Py_ssize_t index); /*proto*/
static int __Pyx_EndUnpack(PyObject *); /*proto*/ static int __Pyx_EndUnpack(PyObject *, Py_ssize_t expected); /*proto*/
""", """,
impl = """ impl = """
static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) { static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) {
...@@ -7290,11 +7295,11 @@ static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) { ...@@ -7290,11 +7295,11 @@ static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) {
return item; return item;
} }
static int __Pyx_EndUnpack(PyObject *iter) { static int __Pyx_EndUnpack(PyObject *iter, Py_ssize_t expected) {
PyObject *item; PyObject *item;
if ((item = PyIter_Next(iter))) { if ((item = PyIter_Next(iter))) {
Py_DECREF(item); Py_DECREF(item);
__Pyx_RaiseTooManyValuesError(); __Pyx_RaiseTooManyValuesError(expected);
return -1; return -1;
} }
else if (!PyErr_Occurred()) else if (!PyErr_Occurred())
......
...@@ -28,15 +28,14 @@ __doc__ = u""" ...@@ -28,15 +28,14 @@ __doc__ = u"""
>>> b = B() >>> b = B()
>>> b.a0 #doctest: +ELLIPSIS >>> b.a0 #doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
...
AttributeError: ... AttributeError: ...
>>> b.b0 #doctest: +ELLIPSIS >>> b.b0 #doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
...
AttributeError: ... AttributeError: ...
>>> b.c0 #doctest: +ELLIPSIS >>> b.c0 #doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
...
AttributeError: ... AttributeError: ...
>>> isinstance(b.a1, type(None)) >>> isinstance(b.a1, type(None))
...@@ -56,28 +55,35 @@ True ...@@ -56,28 +55,35 @@ True
>>> b.a1 is not b.a2 >>> b.a1 is not b.a2
True True
TYPE_FIXES_REQUIRED:
>>> b.b1 = 1 #doctest: +ELLIPSIS >>> b.b1 = 1 #doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
...
TypeError: ... TypeError: ...
>>> b.c1 = 1 #doctest: +ELLIPSIS >>> b.c1 = 1 #doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
...
TypeError: ... TypeError: ...
>>> b.a2 = None #doctest: +ELLIPSIS >>> b.a2 = None #doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
...
AttributeError: ... AttributeError: ...
>>> b.b2 = [] #doctest: +ELLIPSIS >>> b.b2 = [] #doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
...
AttributeError: ... AttributeError: ...
>>> b.c2 = A() #doctest: +ELLIPSIS >>> b.c2 = A() #doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
...
AttributeError: ... AttributeError: ...
""" """
import sys
if sys.version_info < (2,5):
__doc__ = (__doc__.split('TYPE_FIXES_REQUIRED')[0] +
__doc__.split('TYPE_FIXES_REQUIRED')[1].replace('\nAttributeError: ...', '\nTypeError: ...'))
cdef class A: cdef class A:
cdef public short h cdef public short h
......
...@@ -13,15 +13,13 @@ def in_sequence(x, seq): ...@@ -13,15 +13,13 @@ def in_sequence(x, seq):
>>> in_sequence(1, {1:None}) >>> in_sequence(1, {1:None})
True True
>>> in_sequence(1, None) >>> in_sequence(1, None) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... TypeError: ...iterable...
TypeError: argument of type 'NoneType' is not iterable
>>> in_sequence(1, 1) >>> in_sequence(1, 1) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... TypeError: ...iterable...
TypeError: argument of type 'int' is not iterable
""" """
return x in seq return x in seq
...@@ -40,15 +38,13 @@ def not_in_sequence(x, seq): ...@@ -40,15 +38,13 @@ def not_in_sequence(x, seq):
>>> not_in_sequence(1, {1:None}) >>> not_in_sequence(1, {1:None})
False False
>>> not_in_sequence(1, None) >>> not_in_sequence(1, None) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... TypeError: ...iterable...
TypeError: argument of type 'NoneType' is not iterable
>>> not_in_sequence(1, 1) >>> not_in_sequence(1, 1) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... TypeError: ...iterable...
TypeError: argument of type 'int' is not iterable
""" """
return x not in seq return x not in seq
...@@ -83,10 +79,10 @@ def not_in_dict(k, dict dct): ...@@ -83,10 +79,10 @@ def not_in_dict(k, dict dct):
def cascaded(a, b, c): def cascaded(a, b, c):
""" """
>>> cascaded(1, 2, 3) >>> cascaded(1, 2, 3) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... ...
TypeError: argument of type 'int' is not iterable TypeError: ...iterable...
>>> cascaded(-1, (1,2), (1,3)) >>> cascaded(-1, (1,2), (1,3))
True True
>>> cascaded(1, (1,2), (1,3)) >>> cascaded(1, (1,2), (1,3))
......
...@@ -6,12 +6,10 @@ def test(dict d, index): ...@@ -6,12 +6,10 @@ def test(dict d, index):
>>> test(d, 2) >>> test(d, 2)
Traceback (most recent call last): Traceback (most recent call last):
...
KeyError: 2 KeyError: 2
>>> test(d, (1,2)) >>> test(d, (1,2))
Traceback (most recent call last): Traceback (most recent call last):
...
KeyError: (1, 2) KeyError: (1, 2)
>>> class Unhashable: >>> class Unhashable:
...@@ -19,13 +17,11 @@ def test(dict d, index): ...@@ -19,13 +17,11 @@ def test(dict d, index):
... raise ValueError ... raise ValueError
>>> test(d, Unhashable()) >>> test(d, Unhashable())
Traceback (most recent call last): Traceback (most recent call last):
...
ValueError ValueError
>>> test(None, 1) # doctest: +ELLIPSIS >>> test(None, 1) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... TypeError: ...subscriptable...
TypeError: 'NoneType' object is ...
""" """
return d[index] return d[index]
......
...@@ -103,9 +103,9 @@ def m_bytes(char a, bytes bytes_string): ...@@ -103,9 +103,9 @@ def m_bytes(char a, bytes bytes_string):
1 1
>>> m_bytes(ord('X'), py_bytes_string) >>> m_bytes(ord('X'), py_bytes_string)
0 0
>>> 'f'.encode('ASCII') in None >>> 'f'.encode('ASCII') in None # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
TypeError: argument of type 'NoneType' is not iterable TypeError: ...iterable...
>>> m_bytes(ord('f'), None) >>> m_bytes(ord('f'), None)
Traceback (most recent call last): Traceback (most recent call last):
TypeError: argument of type 'NoneType' is not iterable TypeError: argument of type 'NoneType' is not iterable
...@@ -121,9 +121,9 @@ def m_bytes_unsigned(unsigned char a, bytes bytes_string): ...@@ -121,9 +121,9 @@ def m_bytes_unsigned(unsigned char a, bytes bytes_string):
1 1
>>> m_bytes(ord('X'), py_bytes_string) >>> m_bytes(ord('X'), py_bytes_string)
0 0
>>> 'f'.encode('ASCII') in None >>> 'f'.encode('ASCII') in None # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
TypeError: argument of type 'NoneType' is not iterable TypeError: ...iterable...
>>> m_bytes(ord('f'), None) >>> m_bytes(ord('f'), None)
Traceback (most recent call last): Traceback (most recent call last):
TypeError: argument of type 'NoneType' is not iterable TypeError: argument of type 'NoneType' is not iterable
...@@ -168,9 +168,10 @@ def m_unicode(Py_UNICODE a, unicode unicode_string): ...@@ -168,9 +168,10 @@ def m_unicode(Py_UNICODE a, unicode unicode_string):
0 0
>>> m_unicode(ord(py_klingon_character), py_unicode_string) >>> m_unicode(ord(py_klingon_character), py_unicode_string)
1 1
>>> 'f' in None
>>> 'f' in None # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
TypeError: argument of type 'NoneType' is not iterable TypeError: ...iterable...
>>> m_unicode(ord('f'), None) >>> m_unicode(ord('f'), None)
Traceback (most recent call last): Traceback (most recent call last):
TypeError: argument of type 'NoneType' is not iterable TypeError: argument of type 'NoneType' is not iterable
......
...@@ -129,10 +129,9 @@ def index_pop_typed(list L, int i): ...@@ -129,10 +129,9 @@ def index_pop_typed(list L, int i):
@cython.test_fail_if_path_exists('//PythonCapiCallNode') @cython.test_fail_if_path_exists('//PythonCapiCallNode')
def crazy_pop(L): def crazy_pop(L):
""" """
>>> crazy_pop(list(range(10))) >>> crazy_pop(list(range(10))) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... TypeError: pop... at most 1 argument...3...
TypeError: pop() takes at most 1 argument (3 given)
>>> crazy_pop(A()) >>> crazy_pop(A())
(1, 2, 3) (1, 2, 3)
""" """
......
...@@ -136,9 +136,9 @@ def m_unicode(Py_UNICODE a, unicode unicode_string): ...@@ -136,9 +136,9 @@ def m_unicode(Py_UNICODE a, unicode unicode_string):
1 1
>>> m_unicode(ord(py_klingon_character), py_unicode_string) >>> m_unicode(ord(py_klingon_character), py_unicode_string)
0 0
>>> 'f' in None >>> 'f' in None # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
TypeError: argument of type 'NoneType' is not iterable TypeError: ...iterable...
>>> m_unicode(ord('f'), None) >>> m_unicode(ord('f'), None)
Traceback (most recent call last): Traceback (most recent call last):
TypeError: argument of type 'NoneType' is not iterable TypeError: argument of type 'NoneType' is not iterable
......
import sys
if sys.version_info < (2,5):
__doc__ = __doc__.replace(
u"'NoneType' object is not iterable\n >>> tuple_none_list()",
u'iteration over non-sequence\n >>> tuple_none_list()')
def f(obj1, obj2, obj3, obj4, obj5): def f(obj1, obj2, obj3, obj4, obj5):
""" """
...@@ -69,17 +64,17 @@ def l(obj1, obj2, obj3, obj4, obj5): ...@@ -69,17 +64,17 @@ def l(obj1, obj2, obj3, obj4, obj5):
def tuple_none(): def tuple_none():
""" """
>>> tuple_none() >>> tuple_none() # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
TypeError: 'NoneType' object is not iterable TypeError: ...itera...
""" """
return tuple(None) return tuple(None)
def tuple_none_list(): def tuple_none_list():
""" """
>>> tuple_none_list() >>> tuple_none_list() # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
TypeError: 'NoneType' object is not iterable TypeError: ...iterable...
""" """
cdef list none = None cdef list none = None
return tuple(none) return tuple(none)
...@@ -15,7 +15,7 @@ def assign3(t): ...@@ -15,7 +15,7 @@ def assign3(t):
ValueError: need more than 2 values to unpack ValueError: need more than 2 values to unpack
>>> assign3((1,2,3,4)) >>> assign3((1,2,3,4))
Traceback (most recent call last): Traceback (most recent call last):
ValueError: too many values to unpack ValueError: too many values to unpack (expected 3)
""" """
a,b,c = t a,b,c = t
return (a,b,c) return (a,b,c)
...@@ -39,16 +39,16 @@ def assign3_typed(tuple t): ...@@ -39,16 +39,16 @@ def assign3_typed(tuple t):
>>> assign3_typed((1,2)) >>> assign3_typed((1,2))
Traceback (most recent call last): Traceback (most recent call last):
ValueError: need more than 2 values to unpack ValueError: need more than 2 values to unpack
>>> a,b,c = (1,2,3,4) >>> a,b,c = (1,2,3,4) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ValueError: too many values to unpack ValueError: too many values to unpack...
>>> assign3_typed((1,2,3,4)) >>> assign3_typed((1,2,3,4))
Traceback (most recent call last): Traceback (most recent call last):
ValueError: too many values to unpack ValueError: too many values to unpack (expected 3)
>>> a,b = 99,98 >>> a,b = 99,98
>>> a,b = t >>> a,b = t # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
ValueError: too many values to unpack ValueError: too many values to unpack...
>>> a,b >>> a,b
(99, 98) (99, 98)
""" """
......
...@@ -6,8 +6,8 @@ TypeError: ... ...@@ -6,8 +6,8 @@ TypeError: ...
""" """
import sys import sys
if sys.version_info[0:2] >= (2,4): if sys.version_info >= (2,5):
__doc__ = __doc__.replace(u'TypeError:', u'AttributeError:') __doc__ = __doc__.replace('TypeError:', 'AttributeError:')
cdef extern from "external_defs.h": cdef extern from "external_defs.h":
......
...@@ -67,12 +67,17 @@ __doc__ = br""" ...@@ -67,12 +67,17 @@ __doc__ = br"""
True True
>>> null == u'\\x00' # unescaped by Python (required by doctest) >>> null == u'\\x00' # unescaped by Python (required by doctest)
True True
>>> wide_literal == u'\U00101234' # unescaped by Cython
True
>>> wide_literal == u'\\U00101234' # unescaped by Python >>> wide_literal == u'\\U00101234' # unescaped by Python
True True
""" """
if sys.version_info >= (2,6):
# this doesn't work well in older Python versions
__doc__ += u"""\
>>> wide_literal == u'\U00101234' # unescaped by Cython
True
"""
if sys.version_info[0] >= 3: if sys.version_info[0] >= 3:
__doc__ = __doc__.replace(u" u'", u" '") __doc__ = __doc__.replace(u" u'", u" '")
else: else:
......
from __future__ import with_statement from __future__ import with_statement
import sys
def typename(t): def typename(t):
return u"<type '%s'>" % type(t).__name__ name = type(t).__name__
if sys.version_info < (2,5):
if name == 'classobj' and issubclass(t, MyException):
name = 'type'
elif name == 'instance' and isinstance(t, MyException):
name = 'MyException'
return u"<type '%s'>" % name
class MyException(Exception): class MyException(Exception):
pass pass
......
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