Commit 59840c9a authored by didier deshommes's avatar didier deshommes

Re: [Cython] cython doesn't compile cdef'd variables of type set?

parent 5ef2899e
......@@ -105,7 +105,11 @@ builtin_types_table = [
("keys", "O", "O", "PyDict_Keys"),
("values","O", "O", "PyDict_Values")]),
("set", "PySet_Type", []),
("set", "PySet_Type", [("clear", "O", "i", "PySet_Clear"),
("discard", "OO", "i", "PySet_Discard"),
("add", "OO", "i", "PySet_Add"),
("pop", "O", "O", "PySet_Pop")]),
("frozenset", "PyFrozenSet_Type", []),
("slice", "PySlice_Type", []),
......
......@@ -6,7 +6,6 @@ import StringEncoding
import Naming
import copy
class BaseType:
#
# Base class for all Pyrex types including pseudo-types.
......@@ -297,7 +296,12 @@ class BuiltinObjectType(PyObjectType):
return type.is_pyobject and self.assignable_from(type)
def type_test_code(self, arg):
return 'likely(Py%s_CheckExact(%s)) || (%s) == Py_None || (PyErr_Format(PyExc_TypeError, "Expected %s, got %%s", Py_TYPE(%s)->tp_name), 0)' % (self.name[0].upper() + self.name[1:], arg, arg, self.name, arg)
type = self.name.capitalize()
if type == 'Set':
type = 'AnySet'
elif type == 'Frozenset':
type = 'FrozenSet'
return 'likely(Py%s_CheckExact(%s)) || (%s) == Py_None || (PyErr_Format(PyExc_TypeError, "Expected %s, got %%s", Py_TYPE(%s)->tp_name), 0)' % (type, arg, arg, self.name, arg)
def declaration_code(self, entity_code,
for_display = 0, dll_linkage = None, pyrex = 0):
......
__doc__ = u"""
>>> test_set_add()
set(['a', 1])
>>> test_set_clear()
set([])
>>> test_set_pop()
set([])
>>> test_set_discard()
set([233, '12'])
"""
def test_set_add():
cdef set s1
s1 = set([1])
s1.add(1)
s1.add('a')
s1.add(1)
return s1
def test_set_clear():
cdef set s1
s1 = set([1])
s1.clear()
return s1
def test_set_pop():
cdef set s1
s1 = set()
s1.add('2')
two = s1.pop()
return s1
def test_set_discard():
cdef set s1
s1 = set()
s1.add('12')
s1.add(3)
s1.add(233)
s1.discard('3')
s1.discard(3)
return s1
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