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
1175bb68
Commit
1175bb68
authored
Nov 11, 2009
by
Lisandro Dalcin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implementation of 'not in' is broken (ticket #455)
parent
6f9ac4da
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
8 deletions
+94
-8
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+12
-8
tests/run/contains_T455.pyx
tests/run/contains_T455.pyx
+82
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
1175bb68
...
...
@@ -5226,9 +5226,14 @@ class CmpNode(object):
coerce_result
=
"__Pyx_PyBool_FromLong"
else
:
coerce_result
=
""
if
'not'
in
op
:
negation
=
"!"
else
:
negation
=
""
if
'not'
in
op
:
negation
=
"!"
else
:
negation
=
""
if
op
==
'in'
or
op
==
'not_in'
:
assert
not
coerce_result
if
op
==
'not_in'
:
negation
=
"if (likely(%s != -1)) %s = !%s; "
%
((
result_code
,)
*
3
)
if
operand2
.
type
is
dict_type
:
code
.
globalstate
.
use_utility_code
(
raise_none_iter_error_utility_code
)
...
...
@@ -5237,23 +5242,22 @@ class CmpNode(object):
code
.
error_goto
(
self
.
pos
))
code
.
putln
(
"} else {"
)
code
.
putln
(
"%s =
%s(%sPyDict_Contains(%s, %s));
%s"
%
(
"%s =
PyDict_Contains(%s, %s); %s
%s"
%
(
result_code
,
coerce_result
,
negation
,
operand2
.
py_result
(),
operand1
.
py_result
(),
negation
,
code
.
error_goto_if_neg
(
result_code
,
self
.
pos
)))
code
.
putln
(
"}"
)
else
:
code
.
putln
(
"%s =
%s(%sPySequence_Contains(%s, %s));
%s"
%
(
"%s =
PySequence_Contains(%s, %s); %s
%s"
%
(
result_code
,
coerce_result
,
negation
,
operand2
.
py_result
(),
operand1
.
py_result
(),
negation
,
code
.
error_goto_if_neg
(
result_code
,
self
.
pos
)))
elif
(
operand1
.
type
.
is_pyobject
and
op
not
in
(
'is'
,
'is_not'
)):
code
.
putln
(
"%s = PyObject_RichCompare(%s, %s, %s); %s"
%
(
...
...
tests/run/contains_T455.pyx
0 → 100644
View file @
1175bb68
def
in_sequence
(
x
,
seq
):
"""
>>> in_sequence(1, [])
False
>>> in_sequence(1, ())
False
>>> in_sequence(1, {})
False
>>> in_sequence(1, [1])
True
>>> in_sequence(1, (1,))
True
>>> in_sequence(1, {1:None})
True
>>> in_sequence(1, None)
Traceback (most recent call last):
...
TypeError: argument of type 'NoneType' is not iterable
>>> in_sequence(1, 1)
Traceback (most recent call last):
...
TypeError: argument of type 'int' is not iterable
"""
return
x
in
seq
def
not_in_sequence
(
x
,
seq
):
"""
>>> not_in_sequence(1, [])
True
>>> not_in_sequence(1, ())
True
>>> not_in_sequence(1, {})
True
>>> not_in_sequence(1, [1])
False
>>> not_in_sequence(1, (1,))
False
>>> not_in_sequence(1, {1:None})
False
>>> not_in_sequence(1, None)
Traceback (most recent call last):
...
TypeError: argument of type 'NoneType' is not iterable
>>> not_in_sequence(1, 1)
Traceback (most recent call last):
...
TypeError: argument of type 'int' is not iterable
"""
return
x
not
in
seq
def
in_dict
(
k
,
dict
dct
):
"""
>>> in_dict(1, {})
False
>>> in_dict(1, {1:None})
True
>>> in_dict(1, None)
Traceback (most recent call last):
...
TypeError: 'NoneType' object is not iterable
"""
return
k
in
dct
def
not_in_dict
(
k
,
dict
dct
):
"""
>>> not_in_dict(1, {})
True
>>> not_in_dict(1, {1:None})
False
>>> not_in_dict(1, None)
Traceback (most recent call last):
...
TypeError: 'NoneType' object is not iterable
"""
return
k
not
in
dct
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