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
f7efb99a
Commit
f7efb99a
authored
Oct 01, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make ctuples available in pure python code
parent
6a67efec
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
0 deletions
+37
-0
CHANGES.rst
CHANGES.rst
+2
-0
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+10
-0
docs/src/tutorial/pure.rst
docs/src/tutorial/pure.rst
+2
-0
tests/run/ctuple.pyx
tests/run/ctuple.pyx
+23
-0
No files found.
CHANGES.rst
View file @
f7efb99a
...
...
@@ -16,6 +16,8 @@ Features added
* Cpdef enums are now first-class iterable, callable types in Python.
* Ctuples can now be declared in pure Python code.
* Posix declarations for DLL loading and stdio extensions were added.
Patch by Lars Buitinck.
...
...
Cython/Compiler/ExprNodes.py
View file @
f7efb99a
...
...
@@ -7172,6 +7172,16 @@ class TupleNode(SequenceNode):
node
.
is_partly_literal
=
True
return
node
def
analyse_as_type
(
self
,
env
):
# ctuple type
if
not
self
.
args
:
return
None
item_types
=
[
arg
.
analyse_as_type
(
env
)
for
arg
in
self
.
args
]
if
any
(
t
is
None
for
t
in
item_types
):
return
None
entry
=
env
.
declare_tuple_type
(
self
.
pos
,
item_types
)
return
entry
.
type
def
coerce_to
(
self
,
dst_type
,
env
):
if
self
.
type
.
is_ctuple
:
if
dst_type
.
is_ctuple
and
self
.
type
.
size
==
dst_type
.
size
:
...
...
docs/src/tutorial/pure.rst
View file @
f7efb99a
...
...
@@ -222,6 +222,8 @@ The Python types int, long and bool are interpreted as C ``int``, ``long``
and ``bint`` respectively. Also, the Python builtin types ``list``, ``dict``,
``tuple``, etc. may be used, as well as any user defined types.
Typed C-tuples can be declared as a tuple of C types.
Extension types and cdef functions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
...
tests/run/ctuple.pyx
View file @
f7efb99a
...
...
@@ -141,6 +141,7 @@ cpdef (int, double) cpdef_ctuple_return_type(int x, double y):
"""
return
x
,
y
@
cython
.
infer_types
(
True
)
def
test_type_inference
():
"""
...
...
@@ -155,6 +156,28 @@ def test_type_inference():
assert
cython
.
typeof
(
xo
)
==
"tuple object"
,
cython
.
typeof
(
xo
)
@
cython
.
locals
(
a
=
(
int
,
int
),
b
=
(
cython
.
long
,
cython
.
float
))
def
test_pure_python_declaration
(
x
,
y
):
"""
>>> test_pure_python_declaration(1, 2)
(int, int)
(long, float)
((1, 2), (1, 2.0))
>>> test_pure_python_declaration(1.0, 2.0)
(int, int)
(long, float)
((1, 2), (1, 2.0))
>>> test_pure_python_declaration('x', 'y')
Traceback (most recent call last):
TypeError: an integer is required
"""
a
=
(
x
,
y
)
b
=
(
x
,
y
)
print
(
cython
.
typeof
(
a
))
print
(
cython
.
typeof
(
b
))
return
(
a
,
b
)
def
test_equality
((
int
,
int
)
ab
,
(
int
,
int
)
cd
,
(
int
,
int
)
ef
):
"""
>>> test_equality((1, 2), (3, 4), (5, 6))
...
...
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