#define PyBytes_Repr PyString_Repr
#define PyBytes_Concat PyString_Concat
#define PyBytes_ConcatAndDel PyString_ConcatAndDel
+ #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type)
+ #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type)
+#endif
+
+#ifndef PySet_CheckExact
+# define PySet_CheckExact(obj) (Py_TYPE(obj) == PySet_Type)
#endif
#if PY_MAJOR_VERSION >= 3
def subtype_of(self, type):
return type.is_pyobject and self.assignable_from(type)
-
- def type_test_code(self, arg, notnone=False):
+
+ def type_check_function(self, exact=True):
type_name = self.name
+ if type_name == 'bool':
+ return 'PyBool_Check'
+
if type_name == 'str':
- type_check = 'PyString_CheckExact'
- elif type_name == 'set':
- type_check = 'PyAnySet_CheckExact'
+ type_check = 'PyString_Check'
elif type_name == 'frozenset':
- type_check = 'PyFrozenSet_CheckExact'
- elif type_name == 'bool':
- type_check = 'PyBool_Check'
+ type_check = 'PyFrozenSet_Check'
else:
- type_check = 'Py%s_CheckExact' % type_name.capitalize()
+ type_check = 'Py%s_Check' % type_name.capitalize()
+ if exact:
+ type_check += 'Exact'
+ return type_check
+
+ def isinstance_code(self, arg):
+ return '%s(%s)' % (self.type_check_function(exact=False), arg)
+ def type_test_code(self, arg, notnone=False):
+ type_check = self.type_check_function(exact=True)
check = 'likely(%s(%s))' % (type_check, arg)
if not notnone:
check = check + ('||((%s) == Py_None)' % arg)