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
Gwenaël Samain
cython
Commits
78b216f5
Commit
78b216f5
authored
Nov 25, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix '<int>bool(<int>x)' to always return 0 or 1 instead of plain '<int>x'
parent
a6b0f405
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
3 deletions
+16
-3
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+6
-2
tests/run/boolean_context.pyx
tests/run/boolean_context.pyx
+10
-1
No files found.
Cython/Compiler/Optimize.py
View file @
78b216f5
...
...
@@ -1860,8 +1860,12 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
self
.
_error_wrong_arg_count
(
'bool'
,
node
,
pos_args
,
'0 or 1'
)
return
node
else
:
return
pos_args
[
0
].
coerce_to_boolean
(
self
.
current_env
()).
coerce_to_pyobject
(
self
.
current_env
())
# => !!<bint>(x) to make sure it's exactly 0 or 1
operand
=
pos_args
[
0
].
coerce_to_boolean
(
self
.
current_env
())
operand
=
ExprNodes
.
NotNode
(
node
.
pos
,
operand
=
operand
)
operand
=
ExprNodes
.
NotNode
(
node
.
pos
,
operand
=
operand
)
# coerce back to Python object as that's the result we are expecting
return
operand
.
coerce_to_pyobject
(
self
.
current_env
())
### builtin functions
...
...
tests/run/boolean_context.pyx
View file @
78b216f5
...
...
@@ -5,4 +5,13 @@ def test():
True
"""
cdef
int
x
=
5
print
bool
(
x
)
return
bool
(
x
)
def
test_bool_and_int
():
"""
>>> test_bool_and_int()
1
"""
cdef
int
x
=
5
cdef
int
b
=
bool
(
x
)
return
b
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