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
a8376335
Commit
a8376335
authored
Apr 28, 2009
by
Lisandro Dalcin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
compiler directive to control METH_O and METH_NOARGS flags (ticket #295)
parent
ad09367f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
10 deletions
+66
-10
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+5
-5
Cython/Compiler/Options.py
Cython/Compiler/Options.py
+1
-5
tests/run/always_allow_keywords_T295.pyx
tests/run/always_allow_keywords_T295.pyx
+60
-0
No files found.
Cython/Compiler/Nodes.py
View file @
a8376335
...
...
@@ -1691,9 +1691,11 @@ class DefNode(FuncDefNode):
def
analyse_signature
(
self
,
env
):
any_type_tests_needed
=
0
# Use the simpler calling signature for zero- and one-argument functions.
if
not
self
.
entry
.
is_special
and
not
self
.
star_arg
and
not
self
.
starstar_arg
:
if
self
.
entry
.
signature
is
TypeSlots
.
pyfunction_signature
and
Options
.
optimize_simple_methods
:
if
self
.
entry
.
is_special
:
self
.
entry
.
trivial_signature
=
len
(
self
.
args
)
==
1
and
not
(
self
.
star_arg
or
self
.
starstar_arg
)
elif
not
env
.
directives
[
'always_allow_keywords'
]
and
not
(
self
.
star_arg
or
self
.
starstar_arg
):
# Use the simpler calling signature for zero- and one-argument functions.
if
self
.
entry
.
signature
is
TypeSlots
.
pyfunction_signature
:
if
len
(
self
.
args
)
==
0
:
self
.
entry
.
signature
=
TypeSlots
.
pyfunction_noargs
elif
len
(
self
.
args
)
==
1
:
...
...
@@ -1705,8 +1707,6 @@ class DefNode(FuncDefNode):
elif
len
(
self
.
args
)
==
2
:
if
self
.
args
[
1
].
default
is
None
and
not
self
.
args
[
1
].
kw_only
:
self
.
entry
.
signature
=
TypeSlots
.
ibinaryfunc
elif
self
.
entry
.
is_special
:
self
.
entry
.
trivial_signature
=
len
(
self
.
args
)
==
1
and
not
(
self
.
star_arg
or
self
.
starstar_arg
)
sig
=
self
.
entry
.
signature
nfixed
=
sig
.
num_fixed_args
()
for
i
in
range
(
nfixed
):
...
...
Cython/Compiler/Options.py
View file @
a8376335
...
...
@@ -45,11 +45,6 @@ lookup_module_cpdef = 0
# WARNING: This is a work in progress, may currently segfault.
init_local_none
=
1
# Optimize no argument and one argument methods by using the METH_O and METH_NOARGS
# calling conventions. These are faster calling conventions, but disallow the use of
# keywords (which, admittedly, are of little use in these cases).
optimize_simple_methods
=
1
# Append the c file and line number to the traceback for exceptions.
c_line_in_traceback
=
1
...
...
@@ -68,6 +63,7 @@ option_defaults = {
'auto_cpdef'
:
False
,
'cdivision'
:
True
,
# Will be False in 0.12
'cdivision_warnings'
:
False
,
'always_allow_keywords'
:
False
,
}
# Override types possibilities above, if needed
...
...
tests/run/always_allow_keywords_T295.pyx
0 → 100644
View file @
a8376335
__doc__
=
"""
>>> func1(None)
>>> func1(*[None])
>>> func1(arg=None)
Traceback (most recent call last):
...
TypeError: func1() takes no keyword arguments
>>> func2(None)
>>> func2(*[None])
>>> func2(arg=None)
Traceback (most recent call last):
...
TypeError: func2() takes no keyword arguments
>>> func3(None)
>>> func3(*[None])
>>> func3(arg=None)
>>> A().meth1(None)
>>> A().meth1(*[None])
>>> A().meth1(arg=None)
Traceback (most recent call last):
...
TypeError: meth1() takes no keyword arguments
>>> A().meth2(None)
>>> A().meth2(*[None])
>>> A().meth2(arg=None)
Traceback (most recent call last):
...
TypeError: meth2() takes no keyword arguments
>>> A().meth3(None)
>>> A().meth3(*[None])
>>> A().meth3(arg=None)
"""
cimport
cython
def
func1
(
arg
):
pass
@
cython
.
always_allow_keywords
(
False
)
def
func2
(
arg
):
pass
@
cython
.
always_allow_keywords
(
True
)
def
func3
(
arg
):
pass
cdef
class
A
:
def
meth1
(
self
,
arg
):
pass
@
cython
.
always_allow_keywords
(
False
)
def
meth2
(
self
,
arg
):
pass
@
cython
.
always_allow_keywords
(
True
)
def
meth3
(
self
,
arg
):
pass
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