Commit 85656957 authored by Stefan Behnel's avatar Stefan Behnel

fix set.add(some_tuple) in Py2.4

parent fc08e13d
...@@ -401,13 +401,13 @@ static CYTHON_INLINE int PySet_Clear(PyObject *set) { ...@@ -401,13 +401,13 @@ static CYTHON_INLINE int PySet_Clear(PyObject *set) {
} }
static CYTHON_INLINE int PySet_Discard(PyObject *set, PyObject *key) { static CYTHON_INLINE int PySet_Discard(PyObject *set, PyObject *key) {
PyObject *ret = PyObject_CallMethod(set, (char*)"discard", (char*)"O", key); PyObject *ret = PyObject_CallMethod(set, (char*)"discard", (char*)"(O)", key);
if (!ret) return -1; if (!ret) return -1;
Py_DECREF(ret); return 0; Py_DECREF(ret); return 0;
} }
static CYTHON_INLINE int PySet_Add(PyObject *set, PyObject *key) { static CYTHON_INLINE int PySet_Add(PyObject *set, PyObject *key) {
PyObject *ret = PyObject_CallMethod(set, (char*)"add", (char*)"O", key); PyObject *ret = PyObject_CallMethod(set, (char*)"add", (char*)"(O)", key);
if (!ret) return -1; if (!ret) return -1;
Py_DECREF(ret); return 0; Py_DECREF(ret); return 0;
} }
......
...@@ -35,13 +35,14 @@ def test_set_add(): ...@@ -35,13 +35,14 @@ def test_set_add():
>>> type(test_set_add()) is _set >>> type(test_set_add()) is _set
True True
>>> sorted(test_set_add()) >>> sorted(test_set_add())
['a', 1] ['a', 1, (1, 2)]
""" """
cdef set s1 cdef set s1
s1 = set([1]) s1 = set([1, (1, 2)])
s1.add(1) s1.add(1)
s1.add('a') s1.add('a')
s1.add(1) s1.add(1)
s1.add((1,2))
return s1 return s1
def test_set_clear(): def test_set_clear():
...@@ -159,14 +160,18 @@ def test_set_of_tuple(): ...@@ -159,14 +160,18 @@ def test_set_of_tuple():
return set((1, 2, 3)) return set((1, 2, 3))
def sorted(it): def sorted(it):
# Py3 can't compare strings to ints # Py3 can't compare different types
chars = [] chars = []
nums = [] nums = []
tuples = []
for item in it: for item in it:
if type(item) is int: if type(item) is int:
nums.append(item) nums.append(item)
elif type(item) is tuple:
tuples.append(item)
else: else:
chars.append(item) chars.append(item)
nums.sort() nums.sort()
chars.sort() chars.sort()
return chars+nums tuples.sort()
return chars+nums+tuples
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