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
c062260b
Commit
c062260b
authored
Sep 04, 2017
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test and fix "__eq__" override with extern base type (tested with 'list').
parent
4a196738
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
3 deletions
+24
-3
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+6
-3
tests/run/ext_auto_richcmp.py
tests/run/ext_auto_richcmp.py
+18
-0
No files found.
Cython/Compiler/ModuleNode.py
View file @
c062260b
...
@@ -1830,17 +1830,20 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -1830,17 +1830,20 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
"case Py_%s: {"
%
cmp_type
)
code
.
putln
(
"case Py_%s: {"
%
cmp_type
)
if
cmp_method
==
'__eq__'
:
if
cmp_method
==
'__eq__'
:
eq_entry
=
entry
eq_entry
=
entry
code
.
putln
(
"if (o1 == o2) return __Pyx_NewRef(Py_True);"
)
# Python itself does not do this optimisation, it seems...
#code.putln("if (o1 == o2) return __Pyx_NewRef(Py_True);")
elif
cmp_method
==
'__ne__'
:
elif
cmp_method
==
'__ne__'
:
has_ne
=
True
has_ne
=
True
code
.
putln
(
"if (o1 == o2) return __Pyx_NewRef(Py_False);"
)
# Python itself does not do this optimisation, it seems...
#code.putln("if (o1 == o2) return __Pyx_NewRef(Py_False);")
code
.
putln
(
"return %s(o1, o2);"
%
entry
.
func_cname
)
code
.
putln
(
"return %s(o1, o2);"
%
entry
.
func_cname
)
code
.
putln
(
"}"
)
code
.
putln
(
"}"
)
if
eq_entry
and
not
has_ne
and
not
extern_parent
:
if
eq_entry
and
not
has_ne
and
not
extern_parent
:
code
.
putln
(
"case Py_NE: {"
)
code
.
putln
(
"case Py_NE: {"
)
code
.
putln
(
"PyObject *ret;"
)
code
.
putln
(
"PyObject *ret;"
)
code
.
putln
(
"if (o1 == o2) return __Pyx_NewRef(Py_False);"
)
# Python itself does not do this optimisation, it seems...
#code.putln("if (o1 == o2) return __Pyx_NewRef(Py_False);")
code
.
putln
(
"ret = %s(o1, o2);"
%
eq_entry
.
func_cname
)
code
.
putln
(
"ret = %s(o1, o2);"
%
eq_entry
.
func_cname
)
code
.
putln
(
"if (likely(ret && ret != Py_NotImplemented)) {"
)
code
.
putln
(
"if (likely(ret && ret != Py_NotImplemented)) {"
)
code
.
putln
(
"int b = __Pyx_PyObject_IsTrue(ret); Py_DECREF(ret);"
)
code
.
putln
(
"int b = __Pyx_PyObject_IsTrue(ret); Py_DECREF(ret);"
)
...
...
tests/run/ext_auto_richcmp.py
View file @
c062260b
...
@@ -424,3 +424,21 @@ class ClassLtGt(X):
...
@@ -424,3 +424,21 @@ class ClassLtGt(X):
if
isinstance
(
other
,
X
):
if
isinstance
(
other
,
X
):
return
self
.
x
>
other
.
x
return
self
.
x
>
other
.
x
return
NotImplemented
return
NotImplemented
@
cython
.
cclass
class
List
(
list
):
"""
>>> l = [1, 2, 3, 4]
>>> notl = List(l)
>>> notl == l
False
>>> notl != l # implemented by base type
False
>>> notl == notl
True
>>> notl != notl # implemented by base type
False
"""
def
__eq__
(
self
,
other
):
return
self
is
other
or
list
(
self
)
!=
list
(
other
)
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