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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
8788cecf
Commit
8788cecf
authored
Jan 18, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add support for annotations on "*args" and "**kwargs" arguments
parent
620274bf
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
2 deletions
+23
-2
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+8
-0
tests/run/cython3.pyx
tests/run/cython3.pyx
+15
-2
No files found.
Cython/Compiler/ExprNodes.py
View file @
8788cecf
...
...
@@ -7812,6 +7812,14 @@ class PyCFunctionNode(ExprNode, ModuleNameMixin):
if
not
arg
.
annotation
.
type
.
is_pyobject
:
arg
.
annotation
=
arg
.
annotation
.
coerce_to_pyobject
(
env
)
annotations
.
append
((
arg
.
pos
,
arg
.
name
,
arg
.
annotation
))
for
arg
in
(
self
.
def_node
.
star_arg
,
self
.
def_node
.
starstar_arg
):
if
arg
and
arg
.
annotation
:
arg
.
annotation
=
arg
.
annotation
.
analyse_types
(
env
)
if
not
arg
.
annotation
.
type
.
is_pyobject
:
arg
.
annotation
=
arg
.
annotation
.
coerce_to_pyobject
(
env
)
annotations
.
append
((
arg
.
pos
,
arg
.
name
,
arg
.
annotation
))
if
self
.
def_node
.
return_type_annotation
:
annotations
.
append
((
self
.
def_node
.
return_type_annotation
.
pos
,
StringEncoding
.
EncodedString
(
"return"
),
...
...
tests/run/cython3.pyx
View file @
8788cecf
# cython: language_level=3
# cython: language_level=3
, binding=True
# mode: run
# tag: generators, python3, exceptions
...
...
@@ -437,11 +437,24 @@ def int_literals():
print
(
cython
.
typeof
(
1
UL
))
print
(
cython
.
typeof
(
10000000000000
UL
))
def
annotation_syntax
(
a
:
"test new test"
,
b
:
"other"
=
2
)
->
"ret"
:
def
annotation_syntax
(
a
:
"test new test"
,
b
:
"other"
=
2
,
*
args
:
"ARGS"
,
**
kwargs
:
"KWARGS"
)
->
"ret"
:
"""
>>> annotation_syntax(1)
3
>>> annotation_syntax(1,3)
4
>>> len(annotation_syntax.__annotations__)
5
>>> print(annotation_syntax.__annotations__['a'])
test new test
>>> print(annotation_syntax.__annotations__['b'])
other
>>> print(annotation_syntax.__annotations__['args'])
ARGS
>>> print(annotation_syntax.__annotations__['kwargs'])
KWARGS
>>> print(annotation_syntax.__annotations__['return'])
ret
"""
return
a
+
b
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