Commit c59a1dc1 authored by Stefan Behnel's avatar Stefan Behnel

Fix "float(None)" after optimising the "float('...')" parsing case..

parent ba195179
...@@ -2629,6 +2629,7 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin, ...@@ -2629,6 +2629,7 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
return ExprNodes.TypecastNode( return ExprNodes.TypecastNode(
node.pos, operand=func_arg, type=node.type) node.pos, operand=func_arg, type=node.type)
arg = None
if func_arg.type is Builtin.bytes_type: if func_arg.type is Builtin.bytes_type:
cfunc_name = "__Pyx_PyBytes_AsDouble" cfunc_name = "__Pyx_PyBytes_AsDouble"
utility_code_name = 'pybytes_as_double' utility_code_name = 'pybytes_as_double'
...@@ -2642,13 +2643,18 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin, ...@@ -2642,13 +2643,18 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
cfunc_name = "__Pyx_PyString_AsDouble" cfunc_name = "__Pyx_PyString_AsDouble"
utility_code_name = 'pystring_as_double' utility_code_name = 'pystring_as_double'
else: else:
arg = func_arg # no need for an additional None check
cfunc_name = "__Pyx_PyObject_AsDouble" cfunc_name = "__Pyx_PyObject_AsDouble"
utility_code_name = 'pyobject_as_double' utility_code_name = 'pyobject_as_double'
if arg is None:
arg = func_arg.as_none_safe_node(
"float() argument must be a string or a number, not 'NoneType'")
return ExprNodes.PythonCapiCallNode( return ExprNodes.PythonCapiCallNode(
node.pos, cfunc_name, node.pos, cfunc_name,
self.PyObject_AsDouble_func_type, self.PyObject_AsDouble_func_type,
args = pos_args, args = [arg],
is_temp = node.is_temp, is_temp = node.is_temp,
utility_code = load_c_utility(utility_code_name), utility_code = load_c_utility(utility_code_name),
py_name = "float") py_name = "float")
......
...@@ -60,6 +60,9 @@ def from_bytes(s: bytes): ...@@ -60,6 +60,9 @@ def from_bytes(s: bytes):
1.2413112312318938e+47 1.2413112312318938e+47
>>> from_bytes(b"123E100") >>> from_bytes(b"123E100")
1.23e+102 1.23e+102
>>> from_bytes(None) # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError...
""" """
return float(s) return float(s)
...@@ -92,6 +95,9 @@ def from_bytearray(s: bytearray): ...@@ -92,6 +95,9 @@ def from_bytearray(s: bytearray):
1.2413112312318938e+47 1.2413112312318938e+47
>>> from_bytearray(bytearray(b"123E100")) >>> from_bytearray(bytearray(b"123E100"))
1.23e+102 1.23e+102
>>> from_bytearray(None) # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError...
""" """
return float(s) return float(s)
...@@ -112,6 +118,9 @@ def from_str(s: 'str'): ...@@ -112,6 +118,9 @@ def from_str(s: 'str'):
1.2413112312318938e+47 1.2413112312318938e+47
>>> from_str("123E100") >>> from_str("123E100")
1.23e+102 1.23e+102
>>> from_str(None) # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError...
""" """
return float(s) return float(s)
...@@ -146,6 +155,9 @@ def from_unicode(s: 'unicode'): ...@@ -146,6 +155,9 @@ def from_unicode(s: 'unicode'):
1.23e+102 1.23e+102
>>> from_unicode(u"123.23\\N{PUNCTUATION SPACE}") >>> from_unicode(u"123.23\\N{PUNCTUATION SPACE}")
123.23 123.23
>>> from_unicode(None) # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError...
""" """
return float(s) return float(s)
......
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