utility_code = pyobject_as_double_utility_code,
py_name = "float")
+ def _handle_simple_function_bool(self, node, pos_args):
+ """Transform bool(x) into a type coercion to a boolean.
+ """
+ if len(pos_args) != 1:
+ self._error_wrong_arg_count('bool', node, pos_args, 1)
+ return node
+ return pos_args[0].coerce_to_boolean(
+ self.current_env()).coerce_to_pyobject(self.current_env())
+
### builtin functions
PyObject_GetAttr2_func_type = PyrexTypes.CFuncType(
+def bool_list(list obj):
+ """
+ >>> bool_list( [] )
+ False
+ >>> bool_list( [1] )
+ True
+ >>> bool_list(None)
+ False
+ """
+ return bool(obj)
+
def if_list(list obj):
"""
>>> if_list( [] )
else:
return False
+
+def bool_tuple(tuple obj):
+ """
+ >>> bool_tuple( () )
+ False
+ >>> bool_tuple( (1,) )
+ True
+ >>> bool_tuple(None)
+ False
+ """
+ return bool(obj)
+
def if_tuple(tuple obj):
"""
>>> if_tuple( () )
else:
return False
+
b0 = b''
b1 = b'abc'
+def bool_bytes(bytes obj):
+ """
+ >>> bool_bytes(b0)
+ False
+ >>> bool_bytes(b1)
+ True
+ >>> bool_bytes(None)
+ False
+ """
+ return bool(obj)
+
def if_bytes(bytes obj):
"""
>>> if_bytes(b0)
else:
return False
+
u0 = u''
u1 = u'abc'
+def bool_unicode(unicode obj):
+ """
+ >>> bool_unicode(u0)
+ False
+ >>> bool_unicode(u1)
+ True
+ >>> bool_unicode(None)
+ False
+ """
+ return bool(obj)
+
def if_unicode(unicode obj):
"""
>>> if_unicode(u0)