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
Boxiang Sun
cython
Commits
f8735fb8
Commit
f8735fb8
authored
Apr 15, 2011
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make auto_cpdef play nicely with stararg functions
parent
472549a1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
3 deletions
+28
-3
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+11
-0
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+2
-3
tests/run/auto_cpdef.py
tests/run/auto_cpdef.py
+15
-0
No files found.
Cython/Compiler/Nodes.py
View file @
f8735fb8
...
...
@@ -2032,6 +2032,17 @@ class DefNode(FuncDefNode):
api
=
False
,
directive_locals
=
getattr
(
cfunc
,
'directive_locals'
,
{}))
def
is_cdef_func_compatible
(
self
):
"""Determines if the function's signature is compatible with a
cdef function. This can be used before calling
.as_cfunction() to see if that will be successful.
"""
if
self
.
needs_closure
:
return
False
if
self
.
star_arg
or
self
.
starstar_arg
:
return
False
return
True
def
analyse_declarations
(
self
,
env
):
self
.
is_classmethod
=
self
.
is_staticmethod
=
False
if
self
.
decorators
:
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
f8735fb8
...
...
@@ -1425,9 +1425,8 @@ class AlignFunctionDefinitions(CythonTransform):
error
(
pxd_def
.
pos
,
"previous declaration here"
)
return
None
node
=
node
.
as_cfunction
(
pxd_def
)
elif
(
self
.
scope
.
is_module_scope
and
not
node
.
needs_closure
and
self
.
directives
[
'auto_cpdef'
]):
elif
(
self
.
scope
.
is_module_scope
and
self
.
directives
[
'auto_cpdef'
]
and
node
.
is_cdef_func_compatible
()):
node
=
node
.
as_cfunction
(
scope
=
self
.
scope
)
# Enable this when nested cdef functions are allowed.
# self.visitchildren(node)
...
...
tests/run/auto_cpdef.py
View file @
f8735fb8
...
...
@@ -22,3 +22,18 @@ def call_str(arg):
STR
"""
return
str
(
arg
)
def
stararg_func
(
*
args
):
"""
>>> stararg_func(1, 2)
(1, 2)
"""
return
args
def
starstararg_func
(
**
kwargs
):
"""
>>> starstararg_func(a=1)
1
"""
return
kwargs
[
'a'
]
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