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
4ac64ddf
Commit
4ac64ddf
authored
May 27, 2020
by
Stefan Behnel
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disable "c_api_binop_methods" directive in 0.29.x and provide it only as an enabled forward option.
parent
f06e051a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
85 deletions
+4
-85
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+4
-0
tests/run/binop_reverse_methods_GH2056.pyx
tests/run/binop_reverse_methods_GH2056.pyx
+0
-85
No files found.
Cython/Compiler/ModuleNode.py
View file @
4ac64ddf
...
...
@@ -1902,6 +1902,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if
scope
.
directives
[
'c_api_binop_methods'
]:
code
.
putln
(
'#define %s %s'
%
(
func_name
,
slot
.
left_slot
.
slot_code
(
scope
)))
return
else
:
error
(
self
.
pos
,
"The 'c_api_binop_methods' directive is only supported for forward compatibility"
" and must be True."
)
code
.
putln
()
preprocessor_guard
=
slot
.
preprocessor_guard_code
()
...
...
tests/run/binop_reverse_methods_GH2056.pyx
deleted
100644 → 0
View file @
f06e051a
cimport
cython
@
cython
.
c_api_binop_methods
(
False
)
@
cython
.
cclass
class
Base
(
object
):
"""
>>> Base() + 2
'Base.__add__(Base(), 2)'
>>> 2 + Base()
'Base.__radd__(Base(), 2)'
>>> Base() ** 2
'Base.__pow__(Base(), 2, None)'
>>> 2 ** Base()
'Base.__rpow__(Base(), 2, None)'
>>> pow(Base(), 2, 100)
'Base.__pow__(Base(), 2, 100)'
"""
def
__add__
(
self
,
other
):
return
"Base.__add__(%s, %s)"
%
(
self
,
other
)
def
__radd__
(
self
,
other
):
return
"Base.__radd__(%s, %s)"
%
(
self
,
other
)
def
__pow__
(
self
,
other
,
mod
):
return
"Base.__pow__(%s, %s, %s)"
%
(
self
,
other
,
mod
)
def
__rpow__
(
self
,
other
,
mod
):
return
"Base.__rpow__(%s, %s, %s)"
%
(
self
,
other
,
mod
)
def
__repr__
(
self
):
return
"%s()"
%
(
self
.
__class__
.
__name__
)
@
cython
.
c_api_binop_methods
(
False
)
@
cython
.
cclass
class
OverloadLeft
(
Base
):
"""
>>> OverloadLeft() + 2
'OverloadLeft.__add__(OverloadLeft(), 2)'
>>> 2 + OverloadLeft()
'Base.__radd__(OverloadLeft(), 2)'
>>> OverloadLeft() + Base()
'OverloadLeft.__add__(OverloadLeft(), Base())'
>>> Base() + OverloadLeft()
'Base.__add__(Base(), OverloadLeft())'
"""
def
__add__
(
self
,
other
):
return
"OverloadLeft.__add__(%s, %s)"
%
(
self
,
other
)
@
cython
.
c_api_binop_methods
(
False
)
@
cython
.
cclass
class
OverloadRight
(
Base
):
"""
>>> OverloadRight() + 2
'Base.__add__(OverloadRight(), 2)'
>>> 2 + OverloadRight()
'OverloadRight.__radd__(OverloadRight(), 2)'
>>> OverloadRight() + Base()
'Base.__add__(OverloadRight(), Base())'
>>> Base() + OverloadRight()
'OverloadRight.__radd__(OverloadRight(), Base())'
"""
def
__radd__
(
self
,
other
):
return
"OverloadRight.__radd__(%s, %s)"
%
(
self
,
other
)
@
cython
.
c_api_binop_methods
(
True
)
@
cython
.
cclass
class
OverloadCApi
(
Base
):
"""
>>> OverloadCApi() + 2
'OverloadCApi.__add__(OverloadCApi(), 2)'
>>> 2 + OverloadCApi()
'OverloadCApi.__add__(2, OverloadCApi())'
>>> OverloadCApi() + Base()
'OverloadCApi.__add__(OverloadCApi(), Base())'
>>> Base() + OverloadCApi()
'OverloadCApi.__add__(Base(), OverloadCApi())'
"""
def
__add__
(
self
,
other
):
return
"OverloadCApi.__add__(%s, %s)"
%
(
self
,
other
)
Kirill Smelkov
@kirr
mentioned in commit
17368cb1
·
May 28, 2020
mentioned in commit
17368cb1
mentioned in commit 17368cb13f2f76e17234369f5723924531a208f5
Toggle commit list
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