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
350f7692
Commit
350f7692
authored
Nov 11, 2009
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix for in/not in cascading.
parent
1175bb68
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
17 deletions
+47
-17
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+32
-17
tests/run/contains_T455.pyx
tests/run/contains_T455.pyx
+15
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
350f7692
...
...
@@ -5231,9 +5231,11 @@ class CmpNode(object):
else
:
negation
=
""
if
op
==
'in'
or
op
==
'not_in'
:
assert
not
coerce_result
code
.
globalstate
.
use_utility_code
(
contians_utility_code
)
if
self
.
type
is
PyrexTypes
.
py_object_type
:
coerce_result
=
"__Pyx_PyBoolOrNull_FromLong"
if
op
==
'not_in'
:
negation
=
"
if (likely(%s != -1)) %s = !%s; "
%
((
result_code
,)
*
3
)
negation
=
"
__Pyx_NegateNonNeg"
if
operand2
.
type
is
dict_type
:
code
.
globalstate
.
use_utility_code
(
raise_none_iter_error_utility_code
)
...
...
@@ -5241,22 +5243,27 @@ class CmpNode(object):
code
.
putln
(
"__Pyx_RaiseNoneNotIterableError(); %s"
%
code
.
error_goto
(
self
.
pos
))
code
.
putln
(
"} else {"
)
code
.
putln
(
"%s = PyDict_Contains(%s, %s); %s%s"
%
(
result_code
,
operand2
.
py_result
(),
operand1
.
py_result
(),
negation
,
code
.
error_goto_if_neg
(
result_code
,
self
.
pos
)))
code
.
putln
(
"}"
)
method
=
"PyDict_Contains"
else
:
method
=
"PySequence_Contains"
if
self
.
type
is
PyrexTypes
.
py_object_type
:
error_clause
=
code
.
error_goto_if_null
got_ref
=
"__Pyx_XGOTREF(%s); "
%
result_code
else
:
error_clause
=
code
.
error_goto_if_neg
got_ref
=
""
code
.
putln
(
"%s = PySequence_Contains(%s, %s
); %s%s"
%
(
"%s = %s(%s(%s(%s, %s))
); %s%s"
%
(
result_code
,
coerce_result
,
negation
,
method
,
operand2
.
py_result
(),
operand1
.
py_result
(),
negation
,
code
.
error_goto_if_neg
(
result_code
,
self
.
pos
)))
got_ref
,
error_clause
(
result_code
,
self
.
pos
)))
if
operand2
.
type
is
dict_type
:
code
.
putln
(
"}"
)
elif
(
operand1
.
type
.
is_pyobject
and
op
not
in
(
'is'
,
'is_not'
)):
...
...
@@ -5306,6 +5313,14 @@ class CmpNode(object):
else
:
return
op
contians_utility_code
=
UtilityCode
(
proto
=
"""
static INLINE long __Pyx_NegateNonNeg(long b) { return unlikely(b < 0) ? b : !b; }
static INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) {
return unlikely(b < 0) ? NULL : __Pyx_PyBool_FromLong(b);
}
"""
)
class
PrimaryCmpNode
(
ExprNode
,
CmpNode
):
# Non-cascaded comparison or first comparison of
...
...
tests/run/contains_T455.pyx
View file @
350f7692
...
...
@@ -80,3 +80,18 @@ def not_in_dict(k, dict dct):
TypeError: 'NoneType' object is not iterable
"""
return
k
not
in
dct
def
cascaded
(
a
,
b
,
c
):
"""
>>> cascaded(1, 2, 3)
Traceback (most recent call last):
...
TypeError: argument of type 'int' is not iterable
>>> cascaded(-1, (1,2), (1,3))
True
>>> cascaded(1, (1,2), (1,3))
False
>>> cascaded(-1, (1,2), (1,0))
False
"""
return
a
not
in
b
<
c
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