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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
e1324fc1
Commit
e1324fc1
authored
Apr 15, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix calling bool() and float() without arguments
parent
20d9cddc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
112 additions
and
4 deletions
+112
-4
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+12
-4
tests/run/empty_builtin_constructors.pyx
tests/run/empty_builtin_constructors.pyx
+100
-0
No files found.
Cython/Compiler/Optimize.py
View file @
e1324fc1
...
...
@@ -1249,8 +1249,12 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
"""
# Note: this requires the float() function to be typed as
# returning a C 'double'
if
len
(
pos_args
)
!=
1
:
self
.
_error_wrong_arg_count
(
'float'
,
node
,
pos_args
,
1
)
if
len
(
pos_args
)
==
0
:
return
ExprNode
.
FloatNode
(
node
,
value
=
"0.0"
,
constant_result
=
0.0
).
coerce_to
(
Builtin
.
float_type
,
self
.
current_env
())
elif
len
(
pos_args
)
!=
1
:
self
.
_error_wrong_arg_count
(
'float'
,
node
,
pos_args
,
'0 or 1'
)
return
node
func_arg
=
pos_args
[
0
]
if
isinstance
(
func_arg
,
ExprNodes
.
CoerceToPyTypeNode
):
...
...
@@ -1271,8 +1275,12 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
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
)
if
len
(
pos_args
)
==
0
:
return
ExprNodes
.
BoolNode
(
node
.
pos
,
value
=
False
,
constant_result
=
False
).
coerce_to
(
Builtin
.
bool_type
,
self
.
current_env
())
elif
len
(
pos_args
)
!=
1
:
self
.
_error_wrong_arg_count
(
'bool'
,
node
,
pos_args
,
'0 or 1'
)
return
node
return
pos_args
[
0
].
coerce_to_boolean
(
self
.
current_env
()).
coerce_to_pyobject
(
self
.
current_env
())
...
...
tests/run/empty_builtin_constructors.pyx
0 → 100644
View file @
e1324fc1
cimport
cython
import
sys
IS_PY3
=
sys
.
version_info
[
0
]
>=
3
def
_bool
():
"""
>>> _bool() == bool()
True
"""
return
bool
()
def
_int
():
"""
>>> _int() == int()
True
"""
return
int
()
def
_long
():
"""
>>> IS_PY3 or _long() == long()
True
"""
return
long
()
def
_float
():
"""
>>> _float() == float()
True
"""
return
float
()
def
_complex
():
"""
>>> _complex() == complex()
True
"""
return
complex
()
def
_bytes
():
"""
>>> IS_PY3 and _bytes() == bytes() or _bytes() == str()
True
"""
return
bytes
()
def
_str
():
"""
>>> _str() == str()
True
"""
return
str
()
def
_unicode
():
"""
>>> IS_PY3 and _unicode() == str() or _unicode() == unicode()
True
"""
return
unicode
()
def
_tuple
():
"""
>>> _tuple() == tuple()
True
"""
return
tuple
()
def
_list
():
"""
>>> _list() == list()
True
"""
return
list
()
def
_dict
():
"""
>>> _dict() == dict()
True
"""
return
dict
()
py_set
=
cython
.
set
def
_set
():
"""
>>> _set() == py_set()
True
"""
return
set
()
py_frozenset
=
cython
.
frozenset
def
_frozenset
():
"""
>>> _frozenset() == py_frozenset()
True
"""
return
frozenset
()
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