Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
c59a1dc1
Commit
c59a1dc1
authored
Nov 20, 2020
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix "float(None)" after optimising the "float('...')" parsing case..
parent
ba195179
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
1 deletion
+19
-1
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+7
-1
tests/run/builtin_float.py
tests/run/builtin_float.py
+12
-0
No files found.
Cython/Compiler/Optimize.py
View file @
c59a1dc1
...
...
@@ -2629,6 +2629,7 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
return
ExprNodes
.
TypecastNode
(
node
.
pos
,
operand
=
func_arg
,
type
=
node
.
type
)
arg
=
None
if
func_arg
.
type
is
Builtin
.
bytes_type
:
cfunc_name
=
"__Pyx_PyBytes_AsDouble"
utility_code_name
=
'pybytes_as_double'
...
...
@@ -2642,13 +2643,18 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
cfunc_name
=
"__Pyx_PyString_AsDouble"
utility_code_name
=
'pystring_as_double'
else
:
arg
=
func_arg
# no need for an additional None check
cfunc_name
=
"__Pyx_PyObject_AsDouble"
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
(
node
.
pos
,
cfunc_name
,
self
.
PyObject_AsDouble_func_type
,
args
=
pos_args
,
args
=
[
arg
]
,
is_temp
=
node
.
is_temp
,
utility_code
=
load_c_utility
(
utility_code_name
),
py_name
=
"float"
)
...
...
tests/run/builtin_float.py
View file @
c59a1dc1
...
...
@@ -60,6 +60,9 @@ def from_bytes(s: bytes):
1.2413112312318938e+47
>>> from_bytes(b"123E100")
1.23e+102
>>> from_bytes(None) # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError...
"""
return
float
(
s
)
...
...
@@ -92,6 +95,9 @@ def from_bytearray(s: bytearray):
1.2413112312318938e+47
>>> from_bytearray(bytearray(b"123E100"))
1.23e+102
>>> from_bytearray(None) # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError...
"""
return
float
(
s
)
...
...
@@ -112,6 +118,9 @@ def from_str(s: 'str'):
1.2413112312318938e+47
>>> from_str("123E100")
1.23e+102
>>> from_str(None) # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError...
"""
return
float
(
s
)
...
...
@@ -146,6 +155,9 @@ def from_unicode(s: 'unicode'):
1.23e+102
>>> from_unicode(u"123.23
\
\
N{PUNCTUATION SPACE}")
123.23
>>> from_unicode(None) # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError...
"""
return
float
(
s
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment