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
Gwenaël Samain
cython
Commits
c8b85056
Commit
c8b85056
authored
Nov 02, 2009
by
Dag Sverre Seljebotn
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
ea85d044
09f35807
Changes
177
Show whitespace changes
Inline
Side-by-side
Showing
177 changed files
with
3851 additions
and
2932 deletions
+3851
-2932
Cython/Compiler/CmdLine.py
Cython/Compiler/CmdLine.py
+0
-4
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+1
-2
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+9
-9
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+0
-2
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+152
-34
Cython/Compiler/Options.py
Cython/Compiler/Options.py
+0
-6
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+14
-8
Demos/embed/Makefile
Demos/embed/Makefile
+11
-7
Demos/embed/assert_equal.py
Demos/embed/assert_equal.py
+6
-0
Demos/embed/embedded.output
Demos/embed/embedded.output
+2
-0
bin/cython_freeze
bin/cython_freeze
+9
-9
runtests.py
runtests.py
+27
-0
tests/run/addloop.pyx
tests/run/addloop.pyx
+12
-6
tests/run/addop.pyx
tests/run/addop.pyx
+3
-4
tests/run/addressof.pyx
tests/run/addressof.pyx
+3
-4
tests/run/always_allow_keywords_T295.pyx
tests/run/always_allow_keywords_T295.pyx
+38
-34
tests/run/and.pyx
tests/run/and.pyx
+40
-37
tests/run/append.pyx
tests/run/append.pyx
+22
-24
tests/run/argdefault.pyx
tests/run/argdefault.pyx
+56
-37
tests/run/arrayassign.pyx
tests/run/arrayassign.pyx
+70
-57
tests/run/ass2local.pyx
tests/run/ass2local.pyx
+3
-4
tests/run/assert.pyx
tests/run/assert.pyx
+9
-9
tests/run/autotestdict.pyx
tests/run/autotestdict.pyx
+0
-2
tests/run/backquote.pyx
tests/run/backquote.pyx
+7
-7
tests/run/bad_c_struct_T252.pyx
tests/run/bad_c_struct_T252.pyx
+0
-1
tests/run/behnel1.pyx
tests/run/behnel1.pyx
+4
-5
tests/run/big_indices.pyx
tests/run/big_indices.pyx
+3
-5
tests/run/bint.pyx
tests/run/bint.pyx
+10
-11
tests/run/boolop.pyx
tests/run/boolop.pyx
+3
-4
tests/run/bufaccess.pyx
tests/run/bufaccess.pyx
+0
-1
tests/run/builtin_types_none_T166.pyx
tests/run/builtin_types_none_T166.pyx
+5
-3
tests/run/builtinnames.pyx
tests/run/builtinnames.pyx
+9
-11
tests/run/call_crash.pyx
tests/run/call_crash.pyx
+3
-4
tests/run/callargs.pyx
tests/run/callargs.pyx
+130
-128
tests/run/carray_slicing.pyx
tests/run/carray_slicing.pyx
+36
-0
tests/run/carrays.pyx
tests/run/carrays.pyx
+12
-9
tests/run/cdef_bool_T227.pyx
tests/run/cdef_bool_T227.pyx
+18
-18
tests/run/cdef_decorator_directives_T183.pyx
tests/run/cdef_decorator_directives_T183.pyx
+8
-7
tests/run/cdef_opt.pyx
tests/run/cdef_opt.pyx
+12
-6
tests/run/cdef_setitem_T284.pyx
tests/run/cdef_setitem_T284.pyx
+14
-11
tests/run/cdefassign.pyx
tests/run/cdefassign.pyx
+4
-5
tests/run/cdefoptargs.pyx
tests/run/cdefoptargs.pyx
+16
-11
tests/run/cdivision_CEP_516.pyx
tests/run/cdivision_CEP_516.pyx
+61
-43
tests/run/cfuncdef.pyx
tests/run/cfuncdef.pyx
+3
-4
tests/run/char_constants_T99.pyx
tests/run/char_constants_T99.pyx
+10
-10
tests/run/cintop.pyx
tests/run/cintop.pyx
+4
-2
tests/run/cmp.pyx
tests/run/cmp.pyx
+17
-13
tests/run/coercearraytoptr.pyx
tests/run/coercearraytoptr.pyx
+0
-1
tests/run/complex_numbers_T305.pyx
tests/run/complex_numbers_T305.pyx
+75
-70
tests/run/concatcstrings.pyx
tests/run/concatcstrings.pyx
+0
-1
tests/run/consts.pyx
tests/run/consts.pyx
+43
-26
tests/run/cpdef_temps_T411.pyx
tests/run/cpdef_temps_T411.pyx
+9
-9
tests/run/crashT245.pyx
tests/run/crashT245.pyx
+4
-6
tests/run/cstruct.pyx
tests/run/cstruct.pyx
+12
-7
tests/run/ct_IF.pyx
tests/run/ct_IF.pyx
+12
-9
tests/run/ctruthtests.pyx
tests/run/ctruthtests.pyx
+38
-32
tests/run/cunion.pyx
tests/run/cunion.pyx
+9
-6
tests/run/cvardef.pyx
tests/run/cvardef.pyx
+3
-4
tests/run/dict.pyx
tests/run/dict.pyx
+40
-32
tests/run/dictintindex.pyx
tests/run/dictintindex.pyx
+108
-61
tests/run/dietachmayer1.pyx
tests/run/dietachmayer1.pyx
+3
-4
tests/run/empty_for_loop_T208.pyx
tests/run/empty_for_loop_T208.pyx
+8
-7
tests/run/enumerate_T316.pyx
tests/run/enumerate_T316.pyx
+85
-65
tests/run/exceptionpropagation.pyx
tests/run/exceptionpropagation.pyx
+6
-7
tests/run/ext_instance_type_T232.pyx
tests/run/ext_instance_type_T232.pyx
+6
-5
tests/run/extcmethod.pyx
tests/run/extcmethod.pyx
+7
-8
tests/run/extended_unpacking_T235.pyx
tests/run/extended_unpacking_T235.pyx
+195
-176
tests/run/extended_unpacking_T409.pyx
tests/run/extended_unpacking_T409.pyx
+0
-1
tests/run/extinherit.pyx
tests/run/extinherit.pyx
+5
-6
tests/run/extkwonlyargs.pyx
tests/run/extkwonlyargs.pyx
+55
-46
tests/run/extlen.pyx
tests/run/extlen.pyx
+0
-1
tests/run/extpropertyref.pyx
tests/run/extpropertyref.pyx
+4
-5
tests/run/exttype.pyx
tests/run/exttype.pyx
+21
-20
tests/run/filenames.pyx
tests/run/filenames.pyx
+0
-1
tests/run/flatin.pyx
tests/run/flatin.pyx
+24
-24
tests/run/float_floor_division_T260.pyx
tests/run/float_floor_division_T260.pyx
+3
-4
tests/run/fmod.pyx
tests/run/fmod.pyx
+3
-4
tests/run/for_from_float_T254.pyx
tests/run/for_from_float_T254.pyx
+33
-26
tests/run/for_in_range_T372.pyx
tests/run/for_in_range_T372.pyx
+35
-30
tests/run/forfrom.pyx
tests/run/forfrom.pyx
+8
-12
tests/run/funcexceptreraise.pyx
tests/run/funcexceptreraise.pyx
+0
-1
tests/run/hash_T326.pyx
tests/run/hash_T326.pyx
+4
-2
tests/run/if.pyx
tests/run/if.pyx
+27
-25
tests/run/importfrom.pyx
tests/run/importfrom.pyx
+24
-17
tests/run/index.pyx
tests/run/index.pyx
+56
-47
tests/run/inline.pyx
tests/run/inline.pyx
+4
-6
tests/run/inop.pyx
tests/run/inop.pyx
+55
-45
tests/run/inplace.pyx
tests/run/inplace.pyx
+28
-21
tests/run/int_float_builtins_as_casts_T400.pyx
tests/run/int_float_builtins_as_casts_T400.pyx
+139
-0
tests/run/int_literals.pyx
tests/run/int_literals.pyx
+9
-4
tests/run/ishimoto2.pyx
tests/run/ishimoto2.pyx
+7
-11
tests/run/isinstance.pyx
tests/run/isinstance.pyx
+4
-4
tests/run/isnonebool.pyx
tests/run/isnonebool.pyx
+11
-10
tests/run/iteratorexception.pyx
tests/run/iteratorexception.pyx
+3
-4
tests/run/iterdict.pyx
tests/run/iterdict.pyx
+46
-27
tests/run/king1.pyx
tests/run/king1.pyx
+8
-7
tests/run/kwargproblems.pyx
tests/run/kwargproblems.pyx
+5
-8
tests/run/kwonlyargs.pyx
tests/run/kwonlyargs.pyx
+40
-39
tests/run/kwonlyargscall.pyx
tests/run/kwonlyargscall.pyx
+139
-118
tests/run/large_consts_T237.pyx
tests/run/large_consts_T237.pyx
+13
-12
tests/run/list.pyx
tests/run/list.pyx
+39
-22
tests/run/listcomp.pyx
tests/run/listcomp.pyx
+16
-11
tests/run/literal_lists.pyx
tests/run/literal_lists.pyx
+10
-6
tests/run/literals.pyx
tests/run/literals.pyx
+11
-8
tests/run/locals.pyx
tests/run/locals.pyx
+8
-6
tests/run/locals_rebind_T429.pyx
tests/run/locals_rebind_T429.pyx
+4
-2
tests/run/menten1.pyx
tests/run/menten1.pyx
+4
-5
tests/run/modbody.pyx
tests/run/modbody.pyx
+10
-14
tests/run/modop.pyx
tests/run/modop.pyx
+12
-14
tests/run/multass.pyx
tests/run/multass.pyx
+13
-7
tests/run/new_style_exceptions.pyx
tests/run/new_style_exceptions.pyx
+5
-9
tests/run/nogil.pyx
tests/run/nogil.pyx
+6
-9
tests/run/nonecheck.pyx
tests/run/nonecheck.pyx
+47
-42
tests/run/nononetypecheck.pyx
tests/run/nononetypecheck.pyx
+3
-4
tests/run/notinop.pyx
tests/run/notinop.pyx
+45
-38
tests/run/or.pyx
tests/run/or.pyx
+39
-37
tests/run/packedstruct_T290.pyx
tests/run/packedstruct_T290.pyx
+0
-1
tests/run/parallel_swap_assign_T425.pyx
tests/run/parallel_swap_assign_T425.pyx
+0
-1
tests/run/pass.pyx
tests/run/pass.pyx
+3
-4
tests/run/pinard5.pyx
tests/run/pinard5.pyx
+4
-5
tests/run/powop.pyx
tests/run/powop.pyx
+33
-28
tests/run/print.pyx
tests/run/print.pyx
+3
-4
tests/run/pure.pyx
tests/run/pure.pyx
+42
-37
tests/run/pycmp.pyx
tests/run/pycmp.pyx
+6
-6
tests/run/pyintop.pyx
tests/run/pyintop.pyx
+23
-14
tests/run/pynumop.pyx
tests/run/pynumop.pyx
+7
-6
tests/run/pyobjcast_T313.pyx
tests/run/pyobjcast_T313.pyx
+0
-1
tests/run/r_argdefault.pyx
tests/run/r_argdefault.pyx
+8
-10
tests/run/r_delgado_1.pyx
tests/run/r_delgado_1.pyx
+0
-1
tests/run/r_forloop.pyx
tests/run/r_forloop.pyx
+96
-70
tests/run/r_jeff_epler_1.pyx
tests/run/r_jeff_epler_1.pyx
+3
-4
tests/run/r_mitch_chapman_2.pyx
tests/run/r_mitch_chapman_2.pyx
+3
-4
tests/run/r_primes.pyx
tests/run/r_primes.pyx
+3
-4
tests/run/r_print.pyx
tests/run/r_print.pyx
+4
-6
tests/run/r_pyclass.pyx
tests/run/r_pyclass.pyx
+4
-5
tests/run/r_starargcall.pyx
tests/run/r_starargcall.pyx
+5
-7
tests/run/r_starargs.pyx
tests/run/r_starargs.pyx
+3
-9
tests/run/r_starargsonly.pyx
tests/run/r_starargsonly.pyx
+3
-5
tests/run/r_typecast.pyx
tests/run/r_typecast.pyx
+4
-5
tests/run/r_vree_1.pyx
tests/run/r_vree_1.pyx
+0
-1
tests/run/range_optimisation_T203.pyx
tests/run/range_optimisation_T203.pyx
+89
-75
tests/run/ref2local.pyx
tests/run/ref2local.pyx
+3
-4
tests/run/return.pyx
tests/run/return.pyx
+10
-7
tests/run/returnparassign.pyx
tests/run/returnparassign.pyx
+4
-5
tests/run/simpcall.pyx
tests/run/simpcall.pyx
+16
-12
tests/run/sizeof.pyx
tests/run/sizeof.pyx
+3
-4
tests/run/slice2.pyx
tests/run/slice2.pyx
+19
-17
tests/run/specialfloat.pyx
tests/run/specialfloat.pyx
+68
-53
tests/run/starargs.pyx
tests/run/starargs.pyx
+32
-27
tests/run/str_char_coercion_T412.pyx
tests/run/str_char_coercion_T412.pyx
+38
-35
tests/run/strconstinclass.pyx
tests/run/strconstinclass.pyx
+0
-1
tests/run/strfunction.pyx
tests/run/strfunction.pyx
+17
-11
tests/run/struct_conversion.pyx
tests/run/struct_conversion.pyx
+26
-24
tests/run/subclasses.pyx
tests/run/subclasses.pyx
+28
-34
tests/run/subop.pyx
tests/run/subop.pyx
+7
-6
tests/run/switch.pyx
tests/run/switch.pyx
+114
-107
tests/run/tandemstats.pyx
tests/run/tandemstats.pyx
+4
-5
tests/run/temp_alloc_T409.pyx
tests/run/temp_alloc_T409.pyx
+4
-5
tests/run/temps_corner1.pyx
tests/run/temps_corner1.pyx
+4
-5
tests/run/ticket_124.pyx
tests/run/ticket_124.pyx
+4
-4
tests/run/tp_new.pyx
tests/run/tp_new.pyx
+139
-0
tests/run/tuple.pyx
tests/run/tuple.pyx
+34
-21
tests/run/tupleassign.pyx
tests/run/tupleassign.pyx
+86
-78
tests/run/tuplereassign.pyx
tests/run/tuplereassign.pyx
+16
-11
tests/run/type_inference.pyx
tests/run/type_inference.pyx
+18
-8
tests/run/type_slots_int_long_T287.pyx
tests/run/type_slots_int_long_T287.pyx
+24
-21
tests/run/typed_slice.pyx
tests/run/typed_slice.pyx
+40
-30
tests/run/typedfieldbug_T303.pyx
tests/run/typedfieldbug_T303.pyx
+17
-12
tests/run/typeof.pyx
tests/run/typeof.pyx
+19
-19
tests/run/unop.pyx
tests/run/unop.pyx
+3
-4
tests/run/unpack.pyx
tests/run/unpack.pyx
+3
-4
tests/run/unpacklistcomp.pyx
tests/run/unpacklistcomp.pyx
+13
-12
tests/run/varargcall.pyx
tests/run/varargcall.pyx
+3
-4
tests/run/varargdecl.pyx
tests/run/varargdecl.pyx
+3
-4
tests/run/watts1.pyx
tests/run/watts1.pyx
+4
-6
tests/run/withnogil.pyx
tests/run/withnogil.pyx
+7
-6
tests/run/withstat.pyx
tests/run/withstat.pyx
+51
-37
No files found.
Cython/Compiler/CmdLine.py
View file @
c8b85056
...
...
@@ -27,8 +27,6 @@ Options:
-z, --pre-import <module> If specified, assume undeclared names in this
module. Emulates the behavior of putting
"from <module> import *" at the top of the file.
--incref-local-binop Force local an extra incref on local variables before
performing any binary operations.
--cleanup <level> Release interned objects on python exit, for memory debugging.
Level indicates aggressiveness, default 0 releases nothing.
-w, --working <directory> Sets the working directory for Cython (the directory modules
...
...
@@ -108,8 +106,6 @@ def parse_command_line(args):
Options
.
embed_pos_in_docstring
=
1
elif
option
in
(
"-z"
,
"--pre-import"
):
Options
.
pre_import
=
pop_arg
()
elif
option
==
"--incref-local-binop"
:
Options
.
incref_local_binop
=
1
elif
option
==
"--cleanup"
:
Options
.
generate_cleanup_code
=
int
(
pop_arg
())
elif
option
in
(
"-D"
,
"--no-docstrings"
):
...
...
Cython/Compiler/ExprNodes.py
View file @
c8b85056
...
...
@@ -4488,8 +4488,6 @@ class BinopNode(ExprNode):
self
.
coerce_operands_to_pyobjects
(
env
)
self
.
type
=
py_object_type
self
.
is_temp
=
1
if
Options
.
incref_local_binop
and
self
.
operand1
.
type
.
is_pyobject
:
self
.
operand1
=
self
.
operand1
.
coerce_to_temp
(
env
)
else
:
self
.
analyse_c_operation
(
env
)
...
...
@@ -5538,6 +5536,7 @@ class CoercionNode(ExprNode):
# arg ExprNode node being coerced
subexprs
=
[
'arg'
]
constant_result
=
not_a_constant
def
__init__
(
self
,
arg
):
self
.
pos
=
arg
.
pos
...
...
Cython/Compiler/ModuleNode.py
View file @
c8b85056
...
...
@@ -2579,7 +2579,7 @@ __Pyx_char2wchar(char* arg)
mbstate_t mbs;
#endif
if (argsize != (size_t)-1) {
res = (wchar_t *)
PyMem_M
alloc((argsize+1)*sizeof(wchar_t));
res = (wchar_t *)
m
alloc((argsize+1)*sizeof(wchar_t));
if (!res)
goto oom;
count = mbstowcs(res, arg, argsize+1);
...
...
@@ -2593,7 +2593,7 @@ __Pyx_char2wchar(char* arg)
if (*tmp == 0)
return res;
}
PyMem_F
ree(res);
f
ree(res);
}
/* Conversion failed. Fall back to escaping with surrogateescape. */
#ifdef HAVE_MBRTOWC
...
...
@@ -2602,7 +2602,7 @@ __Pyx_char2wchar(char* arg)
/* Overallocate; as multi-byte characters are in the argument, the
actual output could use less memory. */
argsize = strlen(arg) + 1;
res =
PyMem_M
alloc(argsize*sizeof(wchar_t));
res =
m
alloc(argsize*sizeof(wchar_t));
if (!res) goto oom;
in = (unsigned char*)arg;
out = res;
...
...
@@ -2645,7 +2645,7 @@ __Pyx_char2wchar(char* arg)
/* Cannot use C locale for escaping; manually escape as if charset
is ASCII (i.e. escape all bytes > 128. This will still roundtrip
correctly in the locale's charset, which must be an ASCII superset. */
res =
PyMem_M
alloc((strlen(arg)+1)*sizeof(wchar_t));
res =
m
alloc((strlen(arg)+1)*sizeof(wchar_t));
if (!res) goto oom;
in = (unsigned char*)arg;
out = res;
...
...
@@ -2665,9 +2665,9 @@ oom:
int
main(int argc, char **argv)
{
wchar_t **argv_copy = (wchar_t **)
PyMem_M
alloc(sizeof(wchar_t*)*argc);
wchar_t **argv_copy = (wchar_t **)
m
alloc(sizeof(wchar_t*)*argc);
/* We need a second copies, as Python might modify the first one. */
wchar_t **argv_copy2 = (wchar_t **)
PyMem_M
alloc(sizeof(wchar_t*)*argc);
wchar_t **argv_copy2 = (wchar_t **)
m
alloc(sizeof(wchar_t*)*argc);
int i, res;
char *oldloc;
if (!argv_copy || !argv_copy2) {
...
...
@@ -2685,10 +2685,10 @@ main(int argc, char **argv)
free(oldloc);
res = __Pyx_main(argc, argv_copy);
for (i = 0; i < argc; i++) {
PyMem_F
ree(argv_copy2[i]);
f
ree(argv_copy2[i]);
}
PyMem_F
ree(argv_copy);
PyMem_F
ree(argv_copy2);
f
ree(argv_copy);
f
ree(argv_copy2);
return res;
}
#endif
...
...
Cython/Compiler/Nodes.py
View file @
c8b85056
...
...
@@ -3092,8 +3092,6 @@ class InPlaceAssignmentNode(AssignmentNode):
self
.
dup
=
self
.
create_dup_node
(
env
)
# re-assigns lhs to a shallow copy
self
.
rhs
.
analyse_types
(
env
)
self
.
lhs
.
analyse_target_types
(
env
)
if
Options
.
incref_local_binop
and
self
.
dup
.
type
.
is_pyobject
:
self
.
dup
=
self
.
dup
.
coerce_to_temp
(
env
)
import
ExprNodes
if
self
.
lhs
.
type
.
is_pyobject
:
self
.
rhs
=
self
.
rhs
.
coerce_to_pyobject
(
env
)
...
...
Cython/Compiler/Optimize.py
View file @
c8b85056
...
...
@@ -7,6 +7,7 @@ import UtilNodes
import
TypeSlots
import
Symtab
import
Options
import
Naming
from
Code
import
UtilityCode
from
StringEncoding
import
EncodedString
,
BytesLiteral
...
...
@@ -138,49 +139,51 @@ class IterationTransform(Visitor.VisitorTransform):
if
not
stop
:
return
node
carray_ptr
=
slice_node
.
base
.
coerce_to_simple
(
self
.
current_scope
)
if
start
and
start
.
constant_result
!=
0
:
counter_type
=
PyrexTypes
.
spanning_type
(
start
.
type
,
stop
.
type
)
start_ptr_node
=
ExprNodes
.
AddNode
(
start
.
pos
,
operand1
=
carray_ptr
,
operator
=
'+'
,
operand2
=
start
,
type
=
carray_ptr
.
type
)
else
:
counter_type
=
stop
.
type
start
=
ExprNodes
.
IntNode
(
slice_node
.
pos
,
value
=
0
,
type
=
counter_type
)
if
not
counter_type
.
is_int
:
# a Py_ssize_t should be enough for a pointer offset ...
counter_type
=
PyrexTypes
.
c_py_ssize_t_type
start_ptr_node
=
carray_ptr
if
counter_type
!=
start
.
type
:
st
art
=
start
.
coerce_to
(
counter_type
,
self
.
current_scope
)
if
counter_type
!=
stop
.
type
:
stop
=
stop
.
coerce_to
(
counter_type
,
self
.
current_scope
)
start
=
start
.
coerce_to_simple
(
self
.
current_scope
)
stop
=
stop
.
coerce_to_simple
(
self
.
current_scope
)
stop_ptr_node
=
ExprNodes
.
AddNode
(
st
op
.
pos
,
operand1
=
carray_ptr
,
operator
=
'+'
,
operand2
=
stop
,
type
=
carray_ptr
.
type
)
.
coerce_to_simple
(
self
.
current_scope
)
counter
=
UtilNodes
.
TempHandle
(
c
ounter_
type
)
counter
=
UtilNodes
.
TempHandle
(
c
array_ptr
.
type
)
counter_temp
=
counter
.
ref
(
node
.
target
.
pos
)
# special case: char* -> bytes
if
slice_node
.
base
.
type
.
is_string
and
node
.
target
.
type
.
is_pyobject
:
# special case: char* -> bytes
target_value
=
ExprNodes
.
SliceIndexNode
(
node
.
target
.
pos
,
start
=
counter_temp
,
stop
=
ExprNodes
.
AddNode
(
node
.
target
.
pos
,
operand1
=
counter_temp
,
operator
=
'+'
,
operand2
=
ExprNodes
.
IntNode
(
node
.
target
.
pos
,
value
=
1
,
type
=
counter_temp
.
type
),
type
=
counter_temp
.
type
),
base
=
slice_node
.
base
,
start
=
ExprNodes
.
IntNode
(
node
.
target
.
pos
,
value
=
'0'
,
constant_result
=
0
,
type
=
PyrexTypes
.
c_int_type
),
stop
=
ExprNodes
.
IntNode
(
node
.
target
.
pos
,
value
=
'1'
,
constant_result
=
1
,
type
=
PyrexTypes
.
c_int_type
),
base
=
counter_temp
,
type
=
Builtin
.
bytes_type
,
is_temp
=
1
)
else
:
target_value
=
ExprNodes
.
IndexNode
(
node
.
target
.
pos
,
index
=
counter_temp
,
base
=
slice_node
.
base
,
index
=
ExprNodes
.
IntNode
(
node
.
target
.
pos
,
value
=
'0'
,
constant_result
=
0
,
type
=
PyrexTypes
.
c_int_type
),
base
=
counter_temp
,
is_buffer_access
=
False
,
type
=
slice_node
.
base
.
type
.
base_type
)
type
=
carray_ptr
.
type
.
base_type
)
if
target_value
.
type
!=
node
.
target
.
type
:
target_value
=
target_value
.
coerce_to
(
node
.
target
.
type
,
...
...
@@ -197,9 +200,9 @@ class IterationTransform(Visitor.VisitorTransform):
for_node
=
Nodes
.
ForFromStatNode
(
node
.
pos
,
bound1
=
start
,
relation1
=
'<='
,
bound1
=
start
_ptr_node
,
relation1
=
'<='
,
target
=
counter_temp
,
relation2
=
'<'
,
bound2
=
stop
,
relation2
=
'<'
,
bound2
=
stop
_ptr_node
,
step
=
step
,
body
=
body
,
else_clause
=
node
.
else_clause
,
from_range
=
True
)
...
...
@@ -272,6 +275,7 @@ class IterationTransform(Visitor.VisitorTransform):
stats
=
loop_body
)
node
.
target
=
iterable_target
node
.
item
=
node
.
item
.
coerce_to
(
iterable_target
.
type
,
self
.
current_scope
)
node
.
iterator
.
sequence
=
enumerate_function
.
arg_tuple
.
args
[
0
]
# recurse into loop to check for further optimisations
...
...
@@ -299,7 +303,7 @@ class IterationTransform(Visitor.VisitorTransform):
constant_result
=
step_value
)
if
step_value
<
0
:
step
.
value
=
-
step_value
step
.
value
=
str
(
-
step_value
)
relation1
=
'>='
relation2
=
'>'
else
:
...
...
@@ -750,7 +754,11 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
return
self
.
_dispatch_to_handler
(
node
,
node
.
function
,
arg_tuple
)
def
visit_PyTypeTestNode
(
self
,
node
):
### cleanup to avoid redundant coercions to/from Python types
def
_visit_PyTypeTestNode
(
self
,
node
):
# disabled - appears to break assignments in some cases, and
# also drops a None check, which might still be required
"""Flatten redundant type checks after tree changes.
"""
old_arg
=
node
.
arg
...
...
@@ -759,6 +767,55 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
return
node
return
node
.
arg
def
visit_CoerceFromPyTypeNode
(
self
,
node
):
"""Drop redundant conversion nodes after tree changes.
Also, optimise away calls to Python's builtin int() and
float() if the result is going to be coerced back into a C
type anyway.
"""
self
.
visitchildren
(
node
)
arg
=
node
.
arg
if
not
arg
.
type
.
is_pyobject
:
# no Python conversion left at all, just do a C coercion instead
if
node
.
type
==
arg
.
type
:
return
arg
else
:
return
arg
.
coerce_to
(
node
.
type
,
self
.
env_stack
[
-
1
])
if
not
isinstance
(
arg
,
ExprNodes
.
SimpleCallNode
):
return
node
if
not
(
node
.
type
.
is_int
or
node
.
type
.
is_float
):
return
node
function
=
arg
.
function
if
not
isinstance
(
function
,
ExprNodes
.
NameNode
)
\
or
not
function
.
type
.
is_builtin_type
\
or
not
isinstance
(
arg
.
arg_tuple
,
ExprNodes
.
TupleNode
):
return
node
args
=
arg
.
arg_tuple
.
args
if
len
(
args
)
!=
1
:
return
node
func_arg
=
args
[
0
]
if
isinstance
(
func_arg
,
ExprNodes
.
CoerceToPyTypeNode
):
func_arg
=
func_arg
.
arg
elif
func_arg
.
type
.
is_pyobject
:
# play safe: Python conversion might work on all sorts of things
return
node
if
function
.
name
==
'int'
:
if
func_arg
.
type
.
is_int
or
node
.
type
.
is_int
:
if
func_arg
.
type
==
node
.
type
:
return
func_arg
elif
node
.
type
.
assignable_from
(
func_arg
.
type
)
or
func_arg
.
type
.
is_float
:
return
ExprNodes
.
CastNode
(
func_arg
,
node
.
type
)
elif
function
.
name
==
'float'
:
if
func_arg
.
type
.
is_float
or
node
.
type
.
is_float
:
if
func_arg
.
type
==
node
.
type
:
return
func_arg
elif
node
.
type
.
assignable_from
(
func_arg
.
type
)
or
func_arg
.
type
.
is_float
:
return
ExprNodes
.
CastNode
(
func_arg
,
node
.
type
)
return
node
### dispatch to specific optimisers
def
_find_handler
(
self
,
match_name
,
has_kwargs
):
call_type
=
has_kwargs
and
'general'
or
'simple'
handler
=
getattr
(
self
,
'_handle_%s_%s'
%
(
call_type
,
match_name
),
None
)
...
...
@@ -778,6 +835,7 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
else
:
return
function_handler
(
node
,
arg_tuple
)
elif
function
.
is_attribute
:
attr_name
=
function
.
attribute
arg_list
=
arg_tuple
.
args
self_arg
=
function
.
obj
obj_type
=
self_arg
.
type
...
...
@@ -795,7 +853,12 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
else
:
type_name
=
"object"
# safety measure
method_handler
=
self
.
_find_handler
(
"method_%s_%s"
%
(
type_name
,
function
.
attribute
),
kwargs
)
"method_%s_%s"
%
(
type_name
,
attr_name
),
kwargs
)
if
method_handler
is
None
:
if
attr_name
in
TypeSlots
.
method_name_to_slot
\
or
attr_name
==
'__new__'
:
method_handler
=
self
.
_find_handler
(
"slot%s"
%
attr_name
,
kwargs
)
if
method_handler
is
None
:
return
node
if
self_arg
is
not
None
:
...
...
@@ -976,6 +1039,51 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
)
return
node
### special methods
Pyx_tp_new_func_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
py_object_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"type"
,
Builtin
.
type_type
,
None
)
])
def
_handle_simple_slot__new__
(
self
,
node
,
args
,
is_unbound_method
):
"""Replace 'exttype.__new__(exttype)' by a call to exttype->tp_new()
"""
obj
=
node
.
function
.
obj
if
not
is_unbound_method
or
len
(
args
)
!=
1
:
return
node
type_arg
=
args
[
0
]
if
not
obj
.
is_name
or
not
type_arg
.
is_name
:
# play safe
return
node
if
obj
.
type
!=
Builtin
.
type_type
or
type_arg
.
type
!=
Builtin
.
type_type
:
# not a known type, play safe
return
node
if
not
type_arg
.
type_entry
or
not
obj
.
type_entry
:
if
obj
.
name
!=
type_arg
.
name
:
return
node
# otherwise, we know it's a type and we know it's the same
# type for both - that should do
elif
type_arg
.
type_entry
!=
obj
.
type_entry
:
# different types - may or may not lead to an error at runtime
return
node
# FIXME: we could potentially look up the actual tp_new C method
# of the extension type and call that instead of the generic slot
if
not
type_arg
.
type_entry
:
# arbitrary variable, needs a None check for safety
type_arg
=
ExprNodes
.
NoneCheckNode
(
type_arg
,
"PyExc_TypeError"
,
"object.__new__(X): X is not a type object (NoneType)"
)
return
ExprNodes
.
PythonCapiCallNode
(
node
.
pos
,
"__Pyx_tp_new"
,
self
.
Pyx_tp_new_func_type
,
args
=
[
type_arg
],
utility_code
=
tpnew_utility_code
,
is_temp
=
node
.
is_temp
)
### methods of builtin types
PyObject_Append_func_type
=
PyrexTypes
.
CFuncType
(
...
...
@@ -1263,6 +1371,16 @@ static INLINE PyObject* __Pyx_Type(PyObject* o) {
)
tpnew_utility_code
=
UtilityCode
(
proto
=
"""
static INLINE PyObject* __Pyx_tp_new(PyObject* type_obj) {
return (PyObject*) (((PyTypeObject*)(type_obj))->tp_new(
(PyTypeObject*)(type_obj), %(TUPLE)s, NULL));
}
"""
%
{
'TUPLE'
:
Naming
.
empty_tuple
}
)
class
ConstantFolding
(
Visitor
.
VisitorTransform
,
SkipDeclarations
):
"""Calculate the result of constant expressions to store it in
``expr_node.constant_result``, and replace trivial cases by their
...
...
Cython/Compiler/Options.py
View file @
c8b85056
...
...
@@ -10,12 +10,6 @@ gcc_branch_hints = 1
pre_import
=
None
docstrings
=
True
# This is a SAGE-specific option that will
# cause Cython to incref local variables before
# performing a binary operation on them, for
# safe detection of inplace operators.
incref_local_binop
=
0
# Decref global variables in this module on exit for garbage collection.
# 0: None, 1+: interned objects, 2+: cdef globals, 3+: types objects
# Mostly for reducing noise for Valgrind, only executes at process exit
...
...
Cython/Compiler/PyrexTypes.py
View file @
c8b85056
...
...
@@ -621,8 +621,8 @@ static INLINE %(type)s __Pyx_PyInt_As%(SignWord)s%(TypeName)s(PyObject *);
"""
,
impl
=
"""
static INLINE %(type)s __Pyx_PyInt_As%(SignWord)s%(TypeName)s(PyObject* x) {
const %(type)s neg_one = (%(type)s)-1, zero = 0;
const int is_unsigned = neg_one > zero;
const %(type)s neg_one = (%(type)s)-1,
const_
zero = 0;
const int is_unsigned = neg_one >
const_
zero;
if (sizeof(%(type)s) < sizeof(long)) {
long val = __Pyx_PyInt_AsLong(x);
if (unlikely(val != (long)(%(type)s)val)) {
...
...
@@ -646,8 +646,8 @@ static INLINE %(type)s __Pyx_PyInt_As%(SignWord)s%(TypeName)s(PyObject *);
"""
,
impl
=
"""
static INLINE %(type)s __Pyx_PyInt_As%(SignWord)s%(TypeName)s(PyObject* x) {
const %(type)s neg_one = (%(type)s)-1, zero = 0;
const int is_unsigned = neg_one > zero;
const %(type)s neg_one = (%(type)s)-1,
const_
zero = 0;
const int is_unsigned = neg_one >
const_
zero;
#if PY_VERSION_HEX < 0x03000000
if (likely(PyInt_Check(x))) {
long val = PyInt_AS_LONG(x);
...
...
@@ -687,8 +687,8 @@ static INLINE %(type)s __Pyx_PyInt_from_py_%(TypeName)s(PyObject *);
"""
,
impl
=
"""
static INLINE %(type)s __Pyx_PyInt_from_py_%(TypeName)s(PyObject* x) {
const %(type)s neg_one = (%(type)s)-1, zero = 0;
const int is_unsigned = neg_one > zero;
const %(type)s neg_one = (%(type)s)-1,
const_
zero = 0;
const int is_unsigned = neg_one >
const_
zero;
if (sizeof(%(type)s) == sizeof(char)) {
if (is_unsigned)
return (%(type)s)__Pyx_PyInt_AsUnsignedChar(x);
...
...
@@ -734,8 +734,8 @@ static INLINE PyObject *__Pyx_PyInt_to_py_%(TypeName)s(%(type)s);
"""
,
impl
=
"""
static INLINE PyObject *__Pyx_PyInt_to_py_%(TypeName)s(%(type)s val) {
const %(type)s neg_one = (%(type)s)-1, zero = 0;
const int is_unsigned = neg_one > zero;
const %(type)s neg_one = (%(type)s)-1,
const_
zero = 0;
const int is_unsigned = neg_one >
const_
zero;
if (sizeof(%(type)s) < sizeof(long)) {
return PyInt_FromLong((long)val);
} else if (sizeof(%(type)s) == sizeof(long)) {
...
...
@@ -883,6 +883,12 @@ class CComplexType(CNumericType):
else
:
return
False
def
__ne__
(
self
,
other
):
if
isinstance
(
self
,
CComplexType
)
and
isinstance
(
other
,
CComplexType
):
return
self
.
real_type
!=
other
.
real_type
else
:
return
True
def
__lt__
(
self
,
other
):
if
isinstance
(
self
,
CComplexType
)
and
isinstance
(
other
,
CComplexType
):
return
self
.
real_type
<
other
.
real_type
...
...
Demos/embed/Makefile
View file @
c8b85056
# Makefile for creating our standalone Cython program
PYVERSION
=
2.3
PYPREFIX
=
/usr
PYVERSION
=
$(
shell
python
-c
"import sys; print sys.version[:3]"
)
PYPREFIX
=
$(
shell
python
-c
"import sys; print sys.prefix"
)
INCLUDES
=
-I
$(PYPREFIX)
/include/python
$(PYVERSION)
embedded
:
embedded.o
...
...
@@ -16,4 +16,8 @@ all: embedded
clean
:
@
echo
Cleaning Demos/embed
@
rm
-f
*
~
*
.o
*
.so core core.
*
*
.c embedded
@
rm
-f
*
~
*
.o
*
.so core core.
*
*
.c embedded test.output
test
:
clean all
./embedded
>
test.output
python assert_equal.py embedded.output test.output
Demos/embed/assert_equal.py
0 → 100644
View file @
c8b85056
import
sys
if
open
(
sys
.
argv
[
1
]).
read
()
!=
open
(
sys
.
argv
[
2
]).
read
():
print
"Files differ"
sys
.
exit
(
1
)
else
:
print
"Files identical"
Demos/embed/embedded.output
0 → 100644
View file @
c8b85056
__main__
Hi, I'm embedded.
bin/cython_freeze
View file @
c8b85056
...
...
@@ -148,7 +148,7 @@ char2wchar(char* arg)
mbstate_t mbs;
#endif
if (argsize != (size_t)-1) {
res = (wchar_t *)
PyMem_M
alloc((argsize+1)*sizeof(wchar_t));
res = (wchar_t *)
m
alloc((argsize+1)*sizeof(wchar_t));
if (!res)
goto oom;
count = mbstowcs(res, arg, argsize+1);
...
...
@@ -162,7 +162,7 @@ char2wchar(char* arg)
if (*tmp == 0)
return res;
}
PyMem_F
ree(res);
f
ree(res);
}
/* Conversion failed. Fall back to escaping with surrogateescape. */
#ifdef HAVE_MBRTOWC
...
...
@@ -171,7 +171,7 @@ char2wchar(char* arg)
/* Overallocate; as multi-byte characters are in the argument, the
actual output could use less memory. */
argsize = strlen(arg) + 1;
res =
PyMem_M
alloc(argsize*sizeof(wchar_t));
res =
m
alloc(argsize*sizeof(wchar_t));
if (!res) goto oom;
in = (unsigned char*)arg;
out = res;
...
...
@@ -214,7 +214,7 @@ char2wchar(char* arg)
/* Cannot use C locale for escaping; manually escape as if charset
is ASCII (i.e. escape all bytes > 128. This will still roundtrip
correctly in the locale's charset, which must be an ASCII superset. */
res =
PyMem_M
alloc((strlen(arg)+1)*sizeof(wchar_t));
res =
m
alloc((strlen(arg)+1)*sizeof(wchar_t));
if (!res) goto oom;
in = (unsigned char*)arg;
out = res;
...
...
@@ -234,9 +234,9 @@ oom:
int
main(int argc, char **argv)
{
wchar_t **argv_copy = (wchar_t **)
PyMem_M
alloc(sizeof(wchar_t*)*argc);
wchar_t **argv_copy = (wchar_t **)
m
alloc(sizeof(wchar_t*)*argc);
/* We need a second copies, as Python might modify the first one. */
wchar_t **argv_copy2 = (wchar_t **)
PyMem_M
alloc(sizeof(wchar_t*)*argc);
wchar_t **argv_copy2 = (wchar_t **)
m
alloc(sizeof(wchar_t*)*argc);
int i, res;
char *oldloc;
if (!argv_copy || !argv_copy2) {
...
...
@@ -254,10 +254,10 @@ main(int argc, char **argv)
free(oldloc);
res = python_main(argc, argv_copy);
for (i = 0; i < argc; i++) {
PyMem_F
ree(argv_copy2[i]);
f
ree(argv_copy2[i]);
}
PyMem_F
ree(argv_copy);
PyMem_F
ree(argv_copy2);
f
ree(argv_copy);
f
ree(argv_copy2);
return res;
}
#endif"""
runtests.py
View file @
c8b85056
...
...
@@ -127,6 +127,10 @@ class TestBuilder(object):
continue
suite
.
addTest
(
self
.
handle_directory
(
path
,
filename
))
if
sys
.
platform
not
in
[
'win32'
]
and
sys
.
version_info
[
0
]
<
3
:
# Non-Windows makefile, can't run Cython under Py3.
if
[
1
for
selector
in
self
.
selectors
if
selector
(
"embedded"
)]:
suite
.
addTest
(
unittest
.
makeSuite
(
EmbedTest
))
return
suite
def
handle_directory
(
self
,
path
,
context
):
...
...
@@ -429,6 +433,7 @@ is_private_field = re.compile('^_[^_]').match
class
_FakeClass
(
object
):
def
__init__
(
self
,
**
kwargs
):
self
.
shortDescription
=
lambda
x
:
kwargs
.
get
(
'module_name'
)
self
.
__dict__
.
update
(
kwargs
)
try
:
# Py2.7+ and Py3.2+
...
...
@@ -555,6 +560,28 @@ def collect_doctests(path, module_prefix, suite, selectors):
except
ValueError
:
# no tests
pass
# TODO: Support cython_freeze needed here as well.
# TODO: Windows support.
class
EmbedTest
(
unittest
.
TestCase
):
working_dir
=
"Demos/embed"
def
setUp
(
self
):
self
.
old_dir
=
os
.
getcwd
()
os
.
chdir
(
self
.
working_dir
)
os
.
system
(
"make clean > /dev/null"
)
def
tearDown
(
self
):
try
:
os
.
system
(
"make clean > /dev/null"
)
except
:
pass
os
.
chdir
(
self
.
old_dir
)
def
test_embed
(
self
):
self
.
assert_
(
os
.
system
(
"make test > make.output"
)
==
0
)
class
MissingDependencyExcluder
:
def
__init__
(
self
,
deps
):
# deps: { module name : matcher func }
...
...
tests/run/addloop.pyx
View file @
c8b85056
...
...
@@ -5,27 +5,33 @@ __doc__ = u"""
>>> x
46
>>> add_pyrange(10)
46
>>> add_py(10)
46
>>> add_c(10)
46
"""
def
add_pyrange
(
max
):
"""
>>> add_pyrange(10)
46
"""
x
=
1
for
i
in
range
(
max
):
x
=
x
+
i
return
x
def
add_py
(
max
):
"""
>>> add_py(10)
46
"""
x
=
1
for
i
from
0
<=
i
<
max
:
x
=
x
+
i
return
x
def
add_c
(
max
):
"""
>>> add_c(10)
46
"""
cdef
int
x
,
i
x
=
1
for
i
from
0
<=
i
<
max
:
...
...
tests/run/addop.pyx
View file @
c8b85056
__doc__
=
u"""
def
f
():
"""
>>> f()
(30, 22)
"""
def
f
():
"""
cdef
int
int1
,
int2
,
int3
cdef
char
*
ptr1
,
*
ptr2
=
"test"
,
*
ptr3
=
"toast"
int2
=
10
...
...
tests/run/addressof.pyx
View file @
c8b85056
__doc__
=
u"""
def
f
(
int
a
):
"""
>>> f(5)
5
"""
def
f
(
int
a
):
"""
cdef
int
i
,
j
cdef
int
*
p
i
=
a
...
...
tests/run/always_allow_keywords_T295.pyx
View file @
c8b85056
__doc__
=
u"""
>>> 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
):
"""
>>> func1(None)
>>> func1(*[None])
>>> func1(arg=None)
Traceback (most recent call last):
...
TypeError: func1() takes no keyword arguments
"""
pass
@
cython
.
always_allow_keywords
(
False
)
def
func2
(
arg
):
"""
>>> func2(None)
>>> func2(*[None])
>>> func2(arg=None)
Traceback (most recent call last):
...
TypeError: func2() takes no keyword arguments
"""
pass
@
cython
.
always_allow_keywords
(
True
)
def
func3
(
arg
):
"""
>>> func3(None)
>>> func3(*[None])
>>> func3(arg=None)
"""
pass
cdef
class
A
:
"""
>>> 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)
"""
def
meth1
(
self
,
arg
):
pass
...
...
tests/run/and.pyx
View file @
c8b85056
__doc__
=
u"""
>>> a,b = 'a *','b *' # use non-interned strings
>>> and2_assign(2,3) == (2 and 3)
True
>>> and2_assign('a', 'b') == ('a' and 'b')
True
>>> and2_assign(a, b) == (a and b)
True
>>> and2(2,3) == (2 and 3)
True
>>> and2(0,2) == (0 and 2)
True
>>> and2('a', 'b') == ('a' and 'b')
True
>>> and2(a, b) == (a and b)
True
>>> and2('', 'b') == ('' and 'b')
True
>>> and2([], [1]) == ([] and [1])
True
>>> and2([], [a]) == ([] and [a])
True
>>> and3(0,1,2) == (0 and 1 and 2)
True
>>> and3([],(),[1]) == ([] and () and [1])
True
>>> and2_no_result(2,3)
>>> and2_no_result(0,2)
>>> and2_no_result('a','b')
>>> and2_no_result(a,b)
>>> a and b
'b *'
"""
a
,
b
=
'a *'
,
'b *'
# use non-interned strings
def
and2_assign
(
a
,
b
):
"""
>>> a,b = 'a *','b *' # use non-interned strings
>>> and2_assign(2,3) == (2 and 3)
True
>>> and2_assign('a', 'b') == ('a' and 'b')
True
>>> and2_assign(a, b) == (a and b)
True
"""
c
=
a
and
b
return
c
def
and2
(
a
,
b
):
"""
>>> and2(2,3) == (2 and 3)
True
>>> and2(0,2) == (0 and 2)
True
>>> and2('a', 'b') == ('a' and 'b')
True
>>> and2(a, b) == (a and b)
True
>>> and2('', 'b') == ('' and 'b')
True
>>> and2([], [1]) == ([] and [1])
True
>>> and2([], [a]) == ([] and [a])
True
"""
return
a
and
b
def
and3
(
a
,
b
,
c
):
"""
>>> and3(0,1,2) == (0 and 1 and 2)
True
>>> and3([],(),[1]) == ([] and () and [1])
True
"""
d
=
a
and
b
and
c
return
d
def
and2_no_result
(
a
,
b
):
"""
>>> and2_no_result(2,3)
>>> and2_no_result(0,2)
>>> and2_no_result('a','b')
>>> and2_no_result(a,b)
>>> a and b
'b *'
"""
a
and
b
tests/run/append.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test_append([])
None
None
None
got error
[1, 2, (3, 4)]
>>> _ = test_append(A())
appending
1
appending
2
appending
(3, 4)
got error
>>> test_append(B())
None
None
None
None
[1, 2, (3, 4), 5, 6]
"""
class
A
:
def
append
(
self
,
x
):
print
u"appending"
...
...
@@ -32,6 +9,28 @@ class B(list):
list
.
append
(
self
,
arg
)
def
test_append
(
L
):
"""
>>> test_append([])
None
None
None
got error
[1, 2, (3, 4)]
>>> _ = test_append(A())
appending
1
appending
2
appending
(3, 4)
got error
>>> test_append(B())
None
None
None
None
[1, 2, (3, 4), 5, 6]
"""
print
L
.
append
(
1
)
print
L
.
append
(
2
)
print
L
.
append
((
3
,
4
))
...
...
@@ -40,4 +39,3 @@ def test_append(L):
except
TypeError
:
print
u"got error"
return
L
tests/run/argdefault.pyx
View file @
c8b85056
__doc__
=
u"""
>>> f0()
(1, 2)
>>> g0()
(1, 2)
>>> f1()
[1, 2]
>>> g1()
[1, 2]
>>> f2()
{1: 2}
>>> g2()
{1: 2}
>>> f3() #doctest: +ELLIPSIS
<argdefault.Foo object at ...>
>>> g3() #doctest: +ELLIPSIS
<argdefault.Foo object at ...>
>>> f4() #doctest: +ELLIPSIS
<argdefault.Bar object at ...>
>>> g4() #doctest: +ELLIPSIS
<argdefault.Bar object at ...>
>>> f5() #doctest: +ELLIPSIS
<argdefault.Bla object at ...>
>>> g5() #doctest: +ELLIPSIS
<argdefault.Bla object at ...>
>>> f6()
7
>>> g6()
7
"""
GLB0
=
(
1
,
2
)
def
f0
(
arg
=
GLB0
):
"""
>>> f0()
(1, 2)
"""
return
arg
def
g0
(
arg
=
(
1
,
2
)):
"""
>>> g0()
(1, 2)
"""
return
arg
GLB1
=
[
1
,
2
]
def
f1
(
arg
=
GLB1
):
"""
>>> f1()
[1, 2]
"""
return
arg
def
g1
(
arg
=
[
1
,
2
]):
"""
>>> g1()
[1, 2]
"""
return
arg
cdef
GLB2
=
{
1
:
2
}
def
f2
(
arg
=
GLB2
):
"""
>>> f2()
{1: 2}
"""
return
arg
def
g2
(
arg
=
{
1
:
2
}):
"""
>>> g2()
{1: 2}
"""
return
arg
...
...
@@ -60,8 +47,16 @@ class Foo(object):
pass
cdef
GLB3
=
Foo
()
def
f3
(
arg
=
GLB3
):
"""
>>> f3() #doctest: +ELLIPSIS
<argdefault.Foo object at ...>
"""
return
arg
def
g3
(
arg
=
Foo
()):
"""
>>> g3() #doctest: +ELLIPSIS
<argdefault.Foo object at ...>
"""
return
arg
...
...
@@ -69,8 +64,16 @@ cdef class Bar:
pass
cdef
Bar
GLB4
=
Bar
()
def
f4
(
arg
=
GLB4
):
"""
>>> f4() #doctest: +ELLIPSIS
<argdefault.Bar object at ...>
"""
return
arg
def
g4
(
arg
=
Bar
()):
"""
>>> g4() #doctest: +ELLIPSIS
<argdefault.Bar object at ...>
"""
return
arg
...
...
@@ -78,13 +81,29 @@ cdef class Bla:
pass
cdef
Bla
GLB5
=
Bla
()
def
f5
(
Bla
arg
=
GLB5
):
"""
>>> f5() #doctest: +ELLIPSIS
<argdefault.Bla object at ...>
"""
return
arg
def
g5
(
Bla
arg
=
Bla
()):
"""
>>> g5() #doctest: +ELLIPSIS
<argdefault.Bla object at ...>
"""
return
arg
cdef
int
GLB6
=
7
def
f6
(
int
arg
=
GLB6
):
"""
>>> f6()
7
"""
return
arg
def
g6
(
int
arg
=
7
):
"""
>>> g6()
7
"""
return
arg
tests/run/arrayassign.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test_literal_list_slice_all()
(1, 2, 3, 4, 5)
>>> test_literal_list_slice_start()
(1, 2, 3, 4, 5)
>>> test_literal_list_slice_end()
(1, 2, 3, 4, 5)
>>> test_literal_list_slice_start_end()
(1, 2, 3, 4, 5)
>>> test_literal_list_slice_start_param(4)
(1, 2, 3, 4, 5)
>>> test_literal_list_slice_start_param(3)
Traceback (most recent call last):
ValueError: Assignment to slice of wrong length, expected 5, got 6
>>> test_literal_list_slice_start_param(5)
Traceback (most recent call last):
ValueError: Assignment to slice of wrong length, expected 5, got 4
>>> test_literal_list_slice_end_param(5)
(1, 2, 3, 4, 5)
>>> test_literal_list_slice_end_param(4)
Traceback (most recent call last):
ValueError: Assignment to slice of wrong length, expected 5, got 4
>>> test_literal_list_slice_end_param(6)
Traceback (most recent call last):
ValueError: Assignment to slice of wrong length, expected 5, got 6
>>> test_literal_list_slice_start_end_param(2,7)
(1, 2, 3, 4, 5)
>>> test_literal_list_slice_start_end_param(3,7)
Traceback (most recent call last):
ValueError: Assignment to slice of wrong length, expected 5, got 4
>>> test_literal_list_slice_start_end_param(1,7)
Traceback (most recent call last):
ValueError: Assignment to slice of wrong length, expected 5, got 6
>>> test_literal_list_slice_start_end_param(2,6)
Traceback (most recent call last):
ValueError: Assignment to slice of wrong length, expected 5, got 4
>>> test_literal_list_slice_start_end_param(2,8)
Traceback (most recent call last):
ValueError: Assignment to slice of wrong length, expected 5, got 6
>>> test_literal_list_slice_start_end_param(3,6)
Traceback (most recent call last):
ValueError: Assignment to slice of wrong length, expected 5, got 3
>>> test_literal_list_slice_start_end_param(1,8)
Traceback (most recent call last):
ValueError: Assignment to slice of wrong length, expected 5, got 7
>>> test_ptr_literal_list_slice_all()
(1, 2, 3, 4, 5)
>>> test_ptr_literal_list_slice_start()
(1, 2, 3, 4, 5)
>>> test_ptr_literal_list_slice_end()
(1, 2, 3, 4, 5)
"""
# this doesn't work - it would reassign the array address!
#
#def test_literal_list():
...
...
@@ -63,54 +6,124 @@ ValueError: Assignment to slice of wrong length, expected 5, got 7
# return (a[0], a[1], a[2], a[3], a[4])
def
test_literal_list_slice_all
():
"""
>>> test_literal_list_slice_all()
(1, 2, 3, 4, 5)
"""
cdef
int
a
[
5
]
# = [5,4,3,2,1]
a
[:]
=
[
1
,
2
,
3
,
4
,
5
]
return
(
a
[
0
],
a
[
1
],
a
[
2
],
a
[
3
],
a
[
4
])
def
test_literal_list_slice_start
():
"""
>>> test_literal_list_slice_start()
(1, 2, 3, 4, 5)
"""
cdef
int
a
[
7
]
# = [7,6,5,4,3,2,1]
a
[
2
:]
=
[
1
,
2
,
3
,
4
,
5
]
return
(
a
[
2
],
a
[
3
],
a
[
4
],
a
[
5
],
a
[
6
])
def
test_literal_list_slice_end
():
"""
>>> test_literal_list_slice_end()
(1, 2, 3, 4, 5)
"""
cdef
int
a
[
7
]
# = [7,6,5,4,3,2,1]
a
[:
5
]
=
[
1
,
2
,
3
,
4
,
5
]
return
(
a
[
0
],
a
[
1
],
a
[
2
],
a
[
3
],
a
[
4
])
def
test_literal_list_slice_start_end
():
"""
>>> test_literal_list_slice_start_end()
(1, 2, 3, 4, 5)
"""
cdef
int
a
[
9
]
# = [9,8,7,6,5,4,3,2,1]
a
[
2
:
7
]
=
[
1
,
2
,
3
,
4
,
5
]
return
(
a
[
2
],
a
[
3
],
a
[
4
],
a
[
5
],
a
[
6
])
def
test_literal_list_slice_start_param
(
s
):
"""
>>> test_literal_list_slice_start_param(4)
(1, 2, 3, 4, 5)
>>> test_literal_list_slice_start_param(3)
Traceback (most recent call last):
ValueError: Assignment to slice of wrong length, expected 5, got 6
>>> test_literal_list_slice_start_param(5)
Traceback (most recent call last):
ValueError: Assignment to slice of wrong length, expected 5, got 4
"""
cdef
int
a
[
9
]
# = [9,8,7,6,5,4,3,2,1]
a
[
s
:]
=
[
1
,
2
,
3
,
4
,
5
]
return
(
a
[
4
],
a
[
5
],
a
[
6
],
a
[
7
],
a
[
8
])
# return a[s:]
def
test_literal_list_slice_end_param
(
e
):
"""
>>> test_literal_list_slice_end_param(5)
(1, 2, 3, 4, 5)
>>> test_literal_list_slice_end_param(4)
Traceback (most recent call last):
ValueError: Assignment to slice of wrong length, expected 5, got 4
>>> test_literal_list_slice_end_param(6)
Traceback (most recent call last):
ValueError: Assignment to slice of wrong length, expected 5, got 6
"""
cdef
int
a
[
9
]
# = [9,8,7,6,5,4,3,2,1]
a
[:
e
]
=
[
1
,
2
,
3
,
4
,
5
]
return
(
a
[
0
],
a
[
1
],
a
[
2
],
a
[
3
],
a
[
4
])
# return a[:e]
def
test_literal_list_slice_start_end_param
(
s
,
e
):
"""
>>> test_literal_list_slice_start_end_param(2,7)
(1, 2, 3, 4, 5)
>>> test_literal_list_slice_start_end_param(3,7)
Traceback (most recent call last):
ValueError: Assignment to slice of wrong length, expected 5, got 4
>>> test_literal_list_slice_start_end_param(1,7)
Traceback (most recent call last):
ValueError: Assignment to slice of wrong length, expected 5, got 6
>>> test_literal_list_slice_start_end_param(2,6)
Traceback (most recent call last):
ValueError: Assignment to slice of wrong length, expected 5, got 4
>>> test_literal_list_slice_start_end_param(2,8)
Traceback (most recent call last):
ValueError: Assignment to slice of wrong length, expected 5, got 6
>>> test_literal_list_slice_start_end_param(3,6)
Traceback (most recent call last):
ValueError: Assignment to slice of wrong length, expected 5, got 3
>>> test_literal_list_slice_start_end_param(1,8)
Traceback (most recent call last):
ValueError: Assignment to slice of wrong length, expected 5, got 7
"""
cdef
int
a
[
9
]
# = [9,8,7,6,5,4,3,2,1]
a
[
s
:
e
]
=
[
1
,
2
,
3
,
4
,
5
]
return
(
a
[
2
],
a
[
3
],
a
[
4
],
a
[
5
],
a
[
6
])
# return a[s:e]
def
test_ptr_literal_list_slice_all
():
"""
>>> test_ptr_literal_list_slice_all()
(1, 2, 3, 4, 5)
"""
cdef
int
*
a
=
[
6
,
5
,
4
,
3
,
2
]
a
[:]
=
[
1
,
2
,
3
,
4
,
5
]
return
(
a
[
0
],
a
[
1
],
a
[
2
],
a
[
3
],
a
[
4
])
def
test_ptr_literal_list_slice_start
():
"""
>>> test_ptr_literal_list_slice_start()
(1, 2, 3, 4, 5)
"""
cdef
int
*
a
=
[
6
,
5
,
4
,
3
,
2
,
1
]
a
[
1
:]
=
[
1
,
2
,
3
,
4
,
5
]
return
(
a
[
1
],
a
[
2
],
a
[
3
],
a
[
4
],
a
[
5
])
def
test_ptr_literal_list_slice_end
():
"""
>>> test_ptr_literal_list_slice_end()
(1, 2, 3, 4, 5)
"""
cdef
int
*
a
=
[
6
,
5
,
4
,
3
,
2
,
1
]
a
[:
5
]
=
[
1
,
2
,
3
,
4
,
5
]
return
(
a
[
0
],
a
[
1
],
a
[
2
],
a
[
3
],
a
[
4
])
...
...
tests/run/ass2local.pyx
View file @
c8b85056
__doc__
=
u"""
def
f
():
"""
>>> f()
42
"""
def
f
():
"""
a
=
42
return
a
tests/run/assert.pyx
View file @
c8b85056
__doc__
=
u"""
def
f
(
a
,
b
,
int
i
):
"""
>>> f(1, 2, 1)
>>> f(0, 2, 1)
Traceback (most recent call last):
...
...
@@ -9,17 +10,16 @@ __doc__ = u"""
>>> f(1, 2, 0)
Traceback (most recent call last):
AssertionError
>>> g(1, "works")
>>> g(0, "fails")
Traceback (most recent call last):
AssertionError: fails
"""
def
f
(
a
,
b
,
int
i
):
"""
assert
a
assert
a
+
b
assert
i
def
g
(
a
,
b
):
"""
>>> g(1, "works")
>>> g(0, "fails")
Traceback (most recent call last):
AssertionError: fails
"""
assert
a
,
b
tests/run/autotestdict.pyx
View file @
c8b85056
...
...
@@ -109,5 +109,3 @@ cdef class MyCdefClass:
>>> True
False
"""
tests/run/backquote.pyx
View file @
c8b85056
__doc__
=
u"""
def
f
(
obj2
):
"""
>>> f(20)
'20'
>>> f('test')
"'test'"
>>> g()
'42'
"""
def
f
(
obj2
):
"""
obj1
=
`obj2`
return
obj1
def
g
():
"""
>>> g()
'42'
"""
obj1
=
`42`
return
obj1
tests/run/bad_c_struct_T252.pyx
View file @
c8b85056
cdef
cf
(
default
=
None
):
return
default
...
...
tests/run/behnel1.pyx
View file @
c8b85056
__doc__
=
u"""
>>> viking(5)
5
"""
cdef
class
Spam
:
cdef
eggs
(
self
,
a
):
return
a
...
...
@@ -11,4 +6,8 @@ cdef Spam spam():
return
Spam
()
def
viking
(
a
):
"""
>>> viking(5)
5
"""
return
spam
().
eggs
(
a
)
tests/run/big_indices.pyx
View file @
c8b85056
__doc__
=
u"""
def
test
():
"""
>>> test()
neg False
pos True
...
...
@@ -6,9 +7,7 @@ __doc__ = u"""
pos
neg
pos
"""
def
test
():
"""
cdef
long
neg
=
-
1
cdef
unsigned
long
pos
=
-
2
# will be a large positive number
...
...
@@ -22,4 +21,3 @@ def test():
print
D
[
neg
]
print
D
[
pos
]
tests/run/bint.pyx
View file @
c8b85056
__doc__
=
u"""
>>> call_test()
False
True
False
True
True
True
True
"""
cdef
test
(
bint
value
):
print
value
def
call_test
():
"""
>>> call_test()
False
True
False
True
True
True
True
"""
test
(
False
)
test
(
True
)
test
(
0
)
...
...
tests/run/boolop.pyx
View file @
c8b85056
__doc__
=
u"""
def
foo
(
obj1
,
obj2
,
obj3
,
obj4
,
obj5
):
"""
>>> foo(True, False, 23, 'test', 1)
(0.0, 1.0, False, False)
"""
def
foo
(
obj1
,
obj2
,
obj3
,
obj4
,
obj5
):
"""
cdef
int
bool1
,
bool2
cdef
float
bool3
,
bool4
cdef
char
*
ptr1
,
*
ptr2
,
*
ptr0
...
...
tests/run/bufaccess.pyx
View file @
c8b85056
...
...
@@ -1392,4 +1392,3 @@ def buffer_nogil():
with
nogil
:
buf
[
1
]
=
10
return
buf
[
1
]
tests/run/builtin_types_none_T166.pyx
View file @
c8b85056
...
...
@@ -4,11 +4,13 @@ __doc__ = u"""
Traceback (most recent call last):
AttributeError: 'NoneType' object has no attribute 'append'
>>> append_to_none()
Traceback (most recent call last):
AttributeError: 'NoneType' object has no attribute 'append'
"""
def
append_to_none
():
"""
>>> append_to_none()
Traceback (most recent call last):
AttributeError: 'NoneType' object has no attribute 'append'
"""
cdef
list
l
=
None
l
.
append
(
2
)
tests/run/builtinnames.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test_c('abc')
fileabc
typeabc
>>> print(test_file_py('abc'))
abc
>>> print(range('abc'))
rangeabc
"""
def
test_file_py
(
file
):
assert
isinstance
(
file
,
(
str
,
unicode
)),
\
u"not a string, found '%s' instead"
%
file
.
__class__
.
__name__
...
...
@@ -28,5 +17,14 @@ cdef type(arg):
def
test_c
(
arg
):
"""
>>> test_c('abc')
fileabc
typeabc
>>> print(test_file_py('abc'))
abc
>>> print(range('abc'))
rangeabc
"""
print
test_file_c
(
arg
)
print
type
(
arg
)
tests/run/call_crash.pyx
View file @
c8b85056
__doc__
=
u"""
cdef
class
A
:
"""
>>> A().test(3)
9
"""
cdef
class
A
:
"""
cdef
int
(
*
func_ptr
)(
int
)
...
...
tests/run/callargs.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test_pos_args(h)
1 2 3 * 0 0
1 2 9 * 2 0
1 2 7 * 2 0
9 8 7 * 0 0
7 8 9 * 0 0
>>> test_kw_args(h)
1 2 3 * 0 0
1 2 9 * 2 1
1 2 7 * 2 1
1 2 9 * 2 2
1 2 9 * 2 2
1 2 9 * 2 3
>>> test_kw_args(e)
2 1
5 1
5 1
5 2
5 2
5 3
>>> test_kw(e)
0 1
0 2
0 2
0 1
>>> test_kw(g)
1
2
2
1
>>> test_pos_args(f)
3
5
5
3
3
>>> test_noargs(e)
0 0
>>> test_noargs(f)
0
>>> test_noargs(g)
0
# and some errors:
>>> test_noargs(h)
Traceback (most recent call last):
TypeError: h() takes at least 3 positional arguments (0 given)
>>> h(1,2, d=5)
Traceback (most recent call last):
TypeError: h() takes at least 3 positional arguments (2 given)
>>> f(1,2, d=5)
Traceback (most recent call last):
TypeError: f() got an unexpected keyword argument 'd'
>>> f(1, d=5)
Traceback (most recent call last):
TypeError: f() got an unexpected keyword argument 'd'
>>> f(d=5)
Traceback (most recent call last):
TypeError: f() got an unexpected keyword argument 'd'
>>> g(1,2, d=5)
Traceback (most recent call last):
TypeError: g() takes exactly 0 positional arguments (2 given)
>>> g(1,2)
Traceback (most recent call last):
TypeError: g() takes exactly 0 positional arguments (2 given)
>>> g(1)
Traceback (most recent call last):
TypeError: g() takes exactly 0 positional arguments (1 given)
>>> test_int_kwargs(e)
Traceback (most recent call last):
TypeError: e() keywords must be strings
>>> test_int_kwargs(f)
Traceback (most recent call last):
TypeError: f() keywords must be strings
>>> test_int_kwargs(g)
Traceback (most recent call last):
TypeError: g() keywords must be strings
>>> test_int_kwargs(h)
Traceback (most recent call last):
TypeError: h() keywords must be strings
def
c
(
a
=
10
,
b
=
20
,
**
kwds
):
"""
>>> c()
10 20 0
>>> c(1)
1 20 0
>>> c(1,2)
1 2 0
>>> c(key=None)
10 20 1
>>> c(1, key=None)
1 20 1
>>> c(1,2, key=None)
1 2 1
"""
print
a
,
b
,
len
(
kwds
)
def
d
(
a
,
b
=
1
,
*
args
,
**
kwds
):
"""
>>> d()
Traceback (most recent call last):
TypeError: d() takes at least 1 positional argument (0 given)
...
...
@@ -100,7 +26,6 @@ __doc__ = u"""
1 2 0 0
>>> d(1,2,3)
1 2 1 0
>>> d(key=None)
Traceback (most recent call last):
TypeError: d() takes at least 1 positional argument (0 given)
...
...
@@ -110,38 +35,46 @@ __doc__ = u"""
1 2 0 1
>>> d(1,2,3, key=None)
1 2 1 1
>>> c()
10 20 0
>>> c(1)
1 20 0
>>> c(1,2)
1 2 0
>>> c(key=None)
10 20 1
>>> c(1, key=None)
1 20 1
>>> c(1,2, key=None)
1 2 1
"""
def
c
(
a
=
10
,
b
=
20
,
**
kwds
):
print
a
,
b
,
len
(
kwds
)
def
d
(
a
,
b
=
1
,
*
args
,
**
kwds
):
"""
print
a
,
b
,
len
(
args
),
len
(
kwds
)
def
e
(
*
args
,
**
kwargs
):
print
len
(
args
),
len
(
kwargs
)
def
f
(
*
args
):
"""
>>> f(1,2, d=5)
Traceback (most recent call last):
TypeError: f() got an unexpected keyword argument 'd'
>>> f(1, d=5)
Traceback (most recent call last):
TypeError: f() got an unexpected keyword argument 'd'
>>> f(d=5)
Traceback (most recent call last):
TypeError: f() got an unexpected keyword argument 'd'
"""
print
len
(
args
)
def
g
(
**
kwargs
):
"""
>>> g(1,2, d=5)
Traceback (most recent call last):
TypeError: g() takes exactly 0 positional arguments (2 given)
>>> g(1,2)
Traceback (most recent call last):
TypeError: g() takes exactly 0 positional arguments (2 given)
>>> g(1)
Traceback (most recent call last):
TypeError: g() takes exactly 0 positional arguments (1 given)
"""
print
len
(
kwargs
)
def
h
(
a
,
b
,
c
,
*
args
,
**
kwargs
):
"""
>>> h(1,2, d=5)
Traceback (most recent call last):
TypeError: h() takes at least 3 positional arguments (2 given)
"""
print
a
,
b
,
c
,
u'*'
,
len
(
args
),
len
(
kwargs
)
args
=
(
9
,
8
,
7
)
...
...
@@ -153,6 +86,22 @@ else:
kwargs
=
{
"test"
:
u"toast"
}
def
test_kw_args
(
f
):
"""
>>> test_kw_args(h)
1 2 3 * 0 0
1 2 9 * 2 1
1 2 7 * 2 1
1 2 9 * 2 2
1 2 9 * 2 2
1 2 9 * 2 3
>>> test_kw_args(e)
2 1
5 1
5 1
5 2
5 2
5 3
"""
f
(
1
,
2
,
c
=
3
)
f
(
1
,
2
,
d
=
3
,
*
args
)
f
(
1
,
2
,
d
=
3
,
*
(
7
,
8
,
9
))
...
...
@@ -161,6 +110,20 @@ def test_kw_args(f):
f
(
1
,
2
,
d
=
3
,
*
args
,
e
=
5
,
**
kwargs
)
def
test_pos_args
(
f
):
"""
>>> test_pos_args(h)
1 2 3 * 0 0
1 2 9 * 2 0
1 2 7 * 2 0
9 8 7 * 0 0
7 8 9 * 0 0
>>> test_pos_args(f)
3
5
5
3
3
"""
f
(
1
,
2
,
3
)
f
(
1
,
2
,
*
args
)
f
(
1
,
2
,
*
(
7
,
8
,
9
))
...
...
@@ -168,13 +131,52 @@ def test_pos_args(f):
f
(
*
(
7
,
8
,
9
))
def
test_kw
(
f
):
"""
>>> test_kw(e)
0 1
0 2
0 2
0 1
>>> test_kw(g)
1
2
2
1
"""
f
(
c
=
3
)
f
(
d
=
3
,
e
=
5
)
f
(
d
=
3
,
**
kwargs
)
f
(
**
kwargs
)
def
test_noargs
(
f
):
"""
>>> test_noargs(e)
0 0
>>> test_noargs(f)
0
>>> test_noargs(g)
0
# and some errors:
>>> test_noargs(h)
Traceback (most recent call last):
TypeError: h() takes at least 3 positional arguments (0 given)
"""
f
()
def
test_int_kwargs
(
f
):
"""
>>> test_int_kwargs(e)
Traceback (most recent call last):
TypeError: e() keywords must be strings
>>> test_int_kwargs(f)
Traceback (most recent call last):
TypeError: f() keywords must be strings
>>> test_int_kwargs(g)
Traceback (most recent call last):
TypeError: g() keywords must be strings
>>> test_int_kwargs(h)
Traceback (most recent call last):
TypeError: h() keywords must be strings
"""
f
(
a
=
1
,
b
=
2
,
c
=
3
,
**
{
10
:
20
,
30
:
40
})
tests/run/carray_slicing.pyx
View file @
c8b85056
...
...
@@ -75,6 +75,42 @@ def slice_charptr_for_loop_c():
print
[
chr
(
c
)
for
c
in
cstring
[
1
:
5
]
]
print
[
chr
(
c
)
for
c
in
cstring
[
4
:
9
]
]
## @cython.test_assert_path_exists("//ForFromStatNode",
## "//ForFromStatNode//IndexNode")
## @cython.test_fail_if_path_exists("//ForInStatNode")
## def slice_charptr_for_loop_c_step():
## """
## >>> slice_charptr_for_loop_c()
## ['c', 'b', 'a']
## ['b', 'c', 'A', 'B']
## ['p', 't', 'q', 'C', 'B']
## """
## cdef char c
## print [ chr(c) for c in cstring[:3:-1] ]
## print [ chr(c) for c in cstring[1:5:2] ]
## print [ chr(c) for c in cstring[4:9:-1] ]
@
cython
.
test_assert_path_exists
(
"//ForFromStatNode"
,
"//ForFromStatNode//IndexNode"
)
@
cython
.
test_fail_if_path_exists
(
"//ForInStatNode"
)
def
slice_charptr_for_loop_c_dynamic_bounds
():
"""
>>> slice_charptr_for_loop_c()
['a', 'b', 'c']
['b', 'c', 'A', 'B']
['B', 'C', 'q', 't', 'p']
"""
cdef
char
c
print
[
chr
(
c
)
for
c
in
cstring
[
0
:
return3
()]
]
print
[
chr
(
c
)
for
c
in
cstring
[
return1
():
return5
()]
]
print
[
chr
(
c
)
for
c
in
cstring
[
return4
():
return9
()]
]
cdef
return1
():
return
1
cdef
return3
():
return
3
cdef
return4
():
return
4
cdef
return5
():
return
5
cdef
return9
():
return
9
@
cython
.
test_assert_path_exists
(
"//ForFromStatNode"
,
"//ForFromStatNode//SliceIndexNode"
)
@
cython
.
test_fail_if_path_exists
(
"//ForInStatNode"
)
...
...
tests/run/carrays.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test1()
2
>>> test2()
0
>>> test3()
(2, 3)
"""
def
test1
():
"""
>>> test1()
2
"""
cdef
int
x
[
2
][
2
]
x
[
0
][
0
]
=
1
x
[
0
][
1
]
=
2
...
...
@@ -20,6 +15,10 @@ cdef int* f(int x[2][2]):
def
test2
():
"""
>>> test2()
0
"""
cdef
int
a1
[
5
]
cdef
int
a2
[
2
+
3
]
return
sizeof
(
a1
)
-
sizeof
(
a2
)
...
...
@@ -29,6 +28,10 @@ cdef enum:
MY_SIZE_B
=
3
def
test3
():
"""
>>> test3()
(2, 3)
"""
cdef
int
a
[
MY_SIZE_A
]
cdef
int
b
[
MY_SIZE_B
]
return
sizeof
(
a
)
/
sizeof
(
int
),
sizeof
(
b
)
/
sizeof
(
int
)
tests/run/cdef_bool_T227.pyx
View file @
c8b85056
__doc__
=
u"""
>>> foo(True)
True
>>> foo(False)
False
>>> foo('abc') # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...
>>> call_cfoo(True)
True
>>> call_cfoo(False)
False
>>> call_cfoo('abc') # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...
"""
def
foo
(
bool
a
):
"""
>>> foo(True)
True
>>> foo(False)
False
>>> foo('abc') # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...
"""
return
a
==
True
def
call_cfoo
(
a
):
"""
>>> call_cfoo(True)
True
>>> call_cfoo(False)
False
>>> call_cfoo('abc') # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...
"""
return
cfoo
(
a
)
cdef
cfoo
(
bool
a
):
...
...
tests/run/cdef_decorator_directives_T183.pyx
View file @
c8b85056
__doc__
=
u"""
>>> cdiv_decorator(-12, 5)
-2
>>> pydiv_decorator(-12, 5)
-3
"""
cimport
cython
@
cython
.
cdivision
(
True
)
cpdef
cdiv_decorator
(
int
a
,
int
b
):
"""
>>> cdiv_decorator(-12, 5)
-2
"""
return
a
/
b
@
cython
.
cdivision
(
False
)
cpdef
pydiv_decorator
(
int
a
,
int
b
):
"""
>>> pydiv_decorator(-12, 5)
-3
"""
return
a
/
b
tests/run/cdef_opt.pyx
View file @
c8b85056
...
...
@@ -7,12 +7,6 @@ __doc__ = u"""
>>> a.foo(10, u'yes')
(True, u'yes')
>>> call0()
(True, u'yo')
>>> call1()
(False, u'yo')
>>> call2()
(False, u'go')
"""
import
sys
...
...
@@ -25,13 +19,25 @@ cdef class A:
return
a
,
b
def
call0
():
"""
>>> call0()
(True, u'yo')
"""
a
=
A
()
return
a
.
foo
()
def
call1
():
"""
>>> call1()
(False, u'yo')
"""
a
=
A
()
return
a
.
foo
(
False
)
def
call2
():
"""
>>> call2()
(False, u'go')
"""
a
=
A
()
return
a
.
foo
(
False
,
u"go"
)
tests/run/cdef_setitem_T284.pyx
View file @
c8b85056
__doc__
=
u'''
>>> no_cdef()
>>> with_cdef()
>>> test_list(list(range(11)), -2, None)
[0, 1, 2, 3, 4, 5, 6, 7, 8, None, 10]
>>> test_list(list(range(11)), "invalid index", None) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
TypeError: list indices must be integers...
'''
def
no_cdef
():
"""
>>> no_cdef()
"""
lst
=
list
(
range
(
11
))
ob
=
10L
lst
[
ob
]
=
-
10
...
...
@@ -17,6 +9,9 @@ def no_cdef():
dd
[
ob
]
=
-
10
def
with_cdef
():
"""
>>> with_cdef()
"""
cdef
list
lst
=
list
(
range
(
11
))
ob
=
10L
lst
[
ob
]
=
-
10
...
...
@@ -24,5 +19,13 @@ def with_cdef():
dd
[
ob
]
=
-
10
def
test_list
(
list
L
,
object
i
,
object
a
):
"""
>>> test_list(list(range(11)), -2, None)
[0, 1, 2, 3, 4, 5, 6, 7, 8, None, 10]
>>> test_list(list(range(11)), "invalid index", None) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
TypeError: list indices must be integers...
"""
L
[
i
]
=
a
return
L
tests/run/cdefassign.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test(1, 2)
4 1 2 2 0 7 8
"""
cdef
int
g
=
7
def
test
(
x
,
int
y
):
"""
>>> test(1, 2)
4 1 2 2 0 7 8
"""
if
True
:
before
=
0
cdef
int
a
=
4
,
b
=
x
,
c
=
y
,
*
p
=
&
y
...
...
tests/run/cdefoptargs.pyx
View file @
c8b85056
__doc__
=
u"""
>>> call2()
>>> call3()
>>> call4()
>>> test_foo()
2
3
7
26
"""
# the calls:
def
call2
():
"""
>>> call2()
"""
b
(
1
,
2
)
def
call3
():
"""
>>> call3()
"""
b
(
1
,
2
,
3
)
def
call4
():
"""
>>> call4()
"""
b
(
1
,
2
,
3
,
4
)
# the called function:
...
...
@@ -30,6 +28,13 @@ cdef int foo(int a, int b=1, int c=1):
return
a
+
b
*
c
def
test_foo
():
"""
>>> test_foo()
2
3
7
26
"""
print
foo
(
1
)
print
foo
(
1
,
2
)
print
foo
(
1
,
2
,
3
)
...
...
tests/run/cdivision_CEP_516.pyx
View file @
c8b85056
...
...
@@ -31,51 +31,17 @@ True
True
>>> all([div_int_py(a,b) == a // b for a in range(-10, 10) for b in range(-10, 10) if b != 0])
True
>>> def simple_warn(msg, *args): print(msg)
>>> import warnings
>>> warnings.showwarning = simple_warn
>>> mod_int_c_warn(-17, 10)
division with oppositely signed operands, C and Python semantics differ
-7
>>> div_int_c_warn(-17, 10)
division with oppositely signed operands, C and Python semantics differ
-1
>>> complex_expression(-150, 20, 19, -7)
verbose_call(20)
division with oppositely signed operands, C and Python semantics differ
verbose_call(19)
division with oppositely signed operands, C and Python semantics differ
-2
>>> mod_div_zero_int(25, 10, 2)
verbose_call(5)
2
>>> print(mod_div_zero_int(25, 10, 0))
verbose_call(5)
integer division or modulo by zero
>>> print(mod_div_zero_int(25, 0, 0))
integer division or modulo by zero
>>> mod_div_zero_float(25, 10, 2)
2.5
>>> print(mod_div_zero_float(25, 10, 0))
float division
>>> print(mod_div_zero_float(25, 0, 0))
float divmod()
>>> py_div_long(-5, -1)
5
>>> import sys
>>> maxint = getattr(sys, ((sys.version_info[0] >= 3) and 'maxsize' or 'maxint'))
>>> py_div_long(-maxint-1, -1)
Traceback (most recent call last):
...
OverflowError: value too large to perform division
"""
import
warnings
orig_showwarning
=
warnings
.
showwarning
true_py_functions
=
{}
exec
"def simple_warn(msg, *args): print(msg)"
in
true_py_functions
simple_warn
=
true_py_functions
[
'simple_warn'
]
del
true_py_functions
def
_all
(
seq
):
for
x
in
seq
:
if
not
x
:
...
...
@@ -137,16 +103,40 @@ def test_cdiv_cmod(short a, short b):
@
cython
.
cdivision
(
True
)
@
cython
.
cdivision_warnings
(
True
)
def
mod_int_c_warn
(
int
a
,
int
b
):
"""
>>> warnings.showwarning = simple_warn
>>> mod_int_c_warn(-17, 10)
division with oppositely signed operands, C and Python semantics differ
-7
>>> warnings.showwarning = orig_showwarning
"""
return
a
%
b
@
cython
.
cdivision
(
True
)
@
cython
.
cdivision_warnings
(
True
)
def
div_int_c_warn
(
int
a
,
int
b
):
"""
>>> warnings.showwarning = simple_warn
>>> div_int_c_warn(-17, 10)
division with oppositely signed operands, C and Python semantics differ
-1
>>> warnings.showwarning = orig_showwarning
"""
return
a
//
b
@
cython
.
cdivision
(
False
)
@
cython
.
cdivision_warnings
(
True
)
def
complex_expression
(
int
a
,
int
b
,
int
c
,
int
d
):
"""
>>> warnings.showwarning = simple_warn
>>> complex_expression(-150, 20, 19, -7)
verbose_call(20)
division with oppositely signed operands, C and Python semantics differ
verbose_call(19)
division with oppositely signed operands, C and Python semantics differ
-2
>>> warnings.showwarning = orig_showwarning
"""
return
(
a
//
verbose_call
(
b
))
%
(
verbose_call
(
c
)
//
d
)
cdef
int
verbose_call
(
int
x
):
...
...
@@ -158,6 +148,16 @@ cdef int verbose_call(int x):
@
cython
.
cdivision
(
False
)
def
mod_div_zero_int
(
int
a
,
int
b
,
int
c
):
"""
>>> mod_div_zero_int(25, 10, 2)
verbose_call(5)
2
>>> print(mod_div_zero_int(25, 10, 0))
verbose_call(5)
integer division or modulo by zero
>>> print(mod_div_zero_int(25, 0, 0))
integer division or modulo by zero
"""
try
:
return
verbose_call
(
a
%
b
)
/
c
except
ZeroDivisionError
,
ex
:
...
...
@@ -165,6 +165,14 @@ def mod_div_zero_int(int a, int b, int c):
@
cython
.
cdivision
(
False
)
def
mod_div_zero_float
(
float
a
,
float
b
,
float
c
):
"""
>>> mod_div_zero_float(25, 10, 2)
2.5
>>> print(mod_div_zero_float(25, 10, 0))
float division
>>> print(mod_div_zero_float(25, 0, 0))
float divmod()
"""
try
:
return
(
a
%
b
)
/
c
except
ZeroDivisionError
,
ex
:
...
...
@@ -172,4 +180,14 @@ def mod_div_zero_float(float a, float b, float c):
@
cython
.
cdivision
(
False
)
def
py_div_long
(
long
a
,
long
b
):
"""
>>> py_div_long(-5, -1)
5
>>> import sys
>>> maxint = getattr(sys, ((sys.version_info[0] >= 3) and 'maxsize' or 'maxint'))
>>> py_div_long(-maxint-1, -1)
Traceback (most recent call last):
...
OverflowError: value too large to perform division
"""
return
a
/
b
tests/run/cfuncdef.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test()
"""
cdef
void
ftang
():
cdef
int
x
x
=
0
...
...
@@ -16,6 +12,9 @@ cdef spam(int i, obj, object object):
c
=
0
def
test
():
"""
>>> test()
"""
ftang
()
foo
(
0
,
c
'f'
)
spam
(
25
,
None
,
None
)
tests/run/char_constants_T99.pyx
View file @
c8b85056
__doc__
=
u"""
>>> global_c_and_s()
99
abcdef
>>> local_c_and_s()
98
bcdefg
"""
cdef
char
c
=
'c'
cdef
char
*
s
=
'abcdef'
def
global_c_and_s
():
"""
>>> global_c_and_s()
99
abcdef
"""
pys
=
s
print
c
print
(
pys
.
decode
(
u'ASCII'
))
def
local_c_and_s
():
"""
>>> local_c_and_s()
98
bcdefg
"""
cdef
char
c
=
'b'
cdef
char
*
s
=
'bcdefg'
pys
=
s
...
...
tests/run/cintop.pyx
View file @
c8b85056
...
...
@@ -13,11 +13,13 @@ __doc__ = u"""
>>> (int1, long1) == f()
True
>>> f()
(45, 111)
"""
def
f
():
"""
>>> f()
(45, 111)
"""
cdef
int
int1
,
int2
,
int3
cdef
char
char1
cdef
long
long1
,
long2
...
...
tests/run/cmp.pyx
View file @
c8b85056
__doc__
=
u"""
def
single_py
(
a
,
b
):
"""
>>> single_py(1, 2)
True
>>> single_py(2, 1)
False
"""
return
a
<
b
def
cascaded_py
(
a
,
b
,
c
):
"""
>>> cascaded_py(1, 2, 3)
True
>>> cascaded_py(1, 2, -1)
False
>>> cascaded_py(10, 2, 3)
False
"""
return
a
<
b
<
c
def
single_c
(
int
a
,
int
b
):
"""
>>> single_c(1, 2)
True
>>> single_c(2, 1)
False
"""
return
a
<
b
def
cascaded_c
(
double
a
,
double
b
,
double
c
):
"""
>>> cascaded_c(1, 2, 3)
True
>>> cascaded_c(1, 2, -1)
False
>>> cascaded_c(10, 2, 3)
False
"""
def
single_py
(
a
,
b
):
return
a
<
b
def
cascaded_py
(
a
,
b
,
c
):
return
a
<
b
<
c
def
single_c
(
int
a
,
int
b
):
return
a
<
b
def
cascaded_c
(
double
a
,
double
b
,
double
c
):
"""
return
a
<
b
<
c
def
typed_cmp
(
list
L
):
...
...
tests/run/coercearraytoptr.pyx
View file @
c8b85056
cdef
char
*
cstring
=
"abcdefg"
cdef
void
spam
(
char
*
target
):
...
...
tests/run/complex_numbers_T305.pyx
View file @
c8b85056
__doc__
=
u"""
cimport
cython
def
test_object_conversion
(
o
):
"""
>>> test_object_conversion(2)
((2+0j), (2+0j), (2+0j))
>>> test_object_conversion(2j - 0.5)
((-0.5+2j), (-0.5+2j), (-0.5+2j))
"""
cdef
float
complex
a
=
o
cdef
double
complex
b
=
o
cdef
long
double
complex
c
=
o
return
(
a
,
b
,
c
)
def
test_arithmetic
(
double
complex
z
,
double
complex
w
):
"""
>>> test_arithmetic(2j, 4j)
(2j, -2j, 6j, -2j, (-8+0j), (0.5+0j))
>>> test_arithmetic(6+12j, 3j)
((6+12j), (-6-12j), (6+15j), (6+9j), (-36+18j), (4-2j))
>>> test_arithmetic(5-10j, 3+4j)
((5-10j), (-5+10j), (8-6j), (2-14j), (55-10j), (-1-2j))
"""
return
+
z
,
-
z
,
z
+
w
,
z
-
w
,
z
*
w
,
z
/
w
## XXX this is not working
## >>> test_div_by_zero(4j)
## -0.25j
## >>> test_div_by_zero(0)
## Traceback (most recent call last):
## ...
## ZeroDivisionError: float division
@
cython
.
cdivision
(
False
)
def
test_div_by_zero
(
double
complex
z
):
"""
>>> test_div_by_zero(4j)
-0.25j
>>> test_div_by_zero(0)
Traceback (most recent call last):
...
ZeroDivisionError: float division
"""
return
1
/
z
def
test_coercion
(
int
a
,
float
b
,
double
c
,
float
complex
d
,
double
complex
e
):
"""
>>> test_coercion(1, 1.5, 2.5, 4+1j, 10j)
(1+0j)
(1.5+0j)
...
...
@@ -26,7 +44,17 @@ __doc__ = u"""
(4+1j)
10j
(9+21j)
"""
cdef
double
complex
z
z
=
a
;
print
z
z
=
b
;
print
z
z
=
c
;
print
z
z
=
d
;
print
z
z
=
e
;
print
z
return
z
+
a
+
b
+
c
+
d
+
e
def
test_compare
(
double
complex
a
,
double
complex
b
):
"""
>>> test_compare(3, 3)
(True, False)
>>> test_compare(3j, 3j)
...
...
@@ -35,93 +63,62 @@ __doc__ = u"""
(False, True)
>>> test_compare(3, 4)
(False, True)
"""
return
a
==
b
,
a
!=
b
def
test_compare_coerce
(
double
complex
a
,
int
b
):
"""
>>> test_compare_coerce(3, 4)
(False, True)
>>> test_compare_coerce(4+1j, 4)
(False, True)
>>> test_compare_coerce(4, 4)
(True, False)
"""
return
a
==
b
,
a
!=
b
def
test_literal
():
"""
>>> test_literal()
(5j, (1-2.5j))
"""
return
5j
,
1
-
2.5j
def
test_real_imag
(
double
complex
z
):
"""
>>> test_real_imag(1-3j)
(1.0, -3.0)
>>> test_real_imag(5)
(5.0, 0.0)
>>> test_real_imag(1.5j)
(0.0, 1.5)
"""
return
z
.
real
,
z
.
imag
def
test_real_imag_assignment
(
object
a
,
double
b
):
"""
>>> test_real_imag_assignment(1, 2)
(1+2j)
>>> test_real_imag_assignment(1.5, -3.5)
(1.5-3.5j)
>>> test_conjugate(2+3j)
(2-3j)
>>> test_conjugate_double(2+3j)
(2-3j)
>>> test_coerce_typedef_multiply(3, 1j)
(3j)
>>> complex_retval()
1j
"""
#cdef extern from "complex.h":
# pass
cimport
cython
def
test_object_conversion
(
o
):
cdef
float
complex
a
=
o
cdef
double
complex
b
=
o
cdef
long
double
complex
c
=
o
return
(
a
,
b
,
c
)
def
test_arithmetic
(
double
complex
z
,
double
complex
w
):
return
+
z
,
-
z
,
z
+
w
,
z
-
w
,
z
*
w
,
z
/
w
## XXX this is not working
## @cython.cdivision(False)
## def test_div_by_zero(double complex z):
## return 1/z
def
test_coercion
(
int
a
,
float
b
,
double
c
,
float
complex
d
,
double
complex
e
):
cdef
double
complex
z
z
=
a
;
print
z
z
=
b
;
print
z
z
=
c
;
print
z
z
=
d
;
print
z
z
=
e
;
print
z
return
z
+
a
+
b
+
c
+
d
+
e
def
test_compare
(
double
complex
a
,
double
complex
b
):
return
a
==
b
,
a
!=
b
def
test_compare_coerce
(
double
complex
a
,
int
b
):
return
a
==
b
,
a
!=
b
def
test_literal
():
return
5j
,
1
-
2.5j
def
test_real_imag
(
double
complex
z
):
return
z
.
real
,
z
.
imag
def
test_real_imag_assignment
(
object
a
,
double
b
):
"""
cdef
double
complex
z
z
.
real
=
a
z
.
imag
=
b
return
z
def
test_conjugate
(
float
complex
z
):
"""
>>> test_conjugate(2+3j)
(2-3j)
"""
return
z
.
conjugate
()
def
test_conjugate_double
(
double
complex
z
):
"""
>>> test_conjugate_double(2+3j)
(2-3j)
"""
return
z
.
conjugate
()
ctypedef
double
complex
cdouble
...
...
@@ -130,7 +127,15 @@ def test_conjugate_typedef(cdouble z):
ctypedef
double
mydouble
def
test_coerce_typedef_multiply
(
mydouble
x
,
double
complex
z
):
"""
>>> test_coerce_typedef_multiply(3, 1j)
(3j)
"""
return
x
*
z
cpdef
double
complex
complex_retval
():
"""
>>> complex_retval()
1j
"""
return
1j
tests/run/concatcstrings.pyx
View file @
c8b85056
...
...
@@ -8,4 +8,3 @@ if sys.version_info[0] >= 3:
__doc__
=
__doc__
.
replace
(
u" u'"
,
u" '"
)
spam
=
u"C string 1"
+
u"C string 2"
tests/run/consts.pyx
View file @
c8b85056
__doc__
=
u"""
>>> add() == 1+2+3+4
True
>>> add_var(10) == 1+2+10+3+4
True
>>> neg() == -1 -2 - (-3+4)
True
>>> long_int_mix() == 1 + (2 * 3) // 2
True
>>> if IS_PY3: type(long_int_mix()) is int
... else: type(long_int_mix()) is long
True
>>> char_int_mix() == 1 + (ord(' ') * 3) // 2 + ord('A')
True
>>> int_cast() == 1 + 2 * 6000
True
>>> mul() == 1*60*1000
True
>>> arithm() == 9*2+3*8//6-10
True
>>> parameters() == _func(-1 -2, - (-3+4), 1*2*3)
True
>>> lists() == [1,2,3] + [4,5,6]
True
"""
import
sys
IS_PY3
=
sys
.
version_info
[
0
]
>=
3
...
...
@@ -31,31 +5,74 @@ def _func(a,b,c):
return
a
+
b
+
c
def
add
():
"""
>>> add() == 1+2+3+4
True
"""
return
1
+
2
+
3
+
4
def
add_var
(
a
):
"""
>>> add_var(10) == 1+2+10+3+4
True
"""
return
1
+
2
+
a
+
3
+
4
def
neg
():
"""
>>> neg() == -1 -2 - (-3+4)
True
"""
return
-
1
-
2
-
(
-
3
+
4
)
def
long_int_mix
():
"""
>>> long_int_mix() == 1 + (2 * 3) // 2
True
>>> if IS_PY3: type(long_int_mix()) is int
... else: type(long_int_mix()) is long
True
"""
return
1L
+
(
2
*
3L
)
//
2
def
char_int_mix
():
"""
>>> char_int_mix() == 1 + (ord(' ') * 3) // 2 + ord('A')
True
"""
return
1L
+
(
c
' '
*
3L
)
//
2
+
c
'A'
def
int_cast
():
"""
>>> int_cast() == 1 + 2 * 6000
True
"""
return
<
int
>
(
1
+
2
*
6000
)
def
mul
():
"""
>>> mul() == 1*60*1000
True
"""
return
1
*
60
*
1000
def
arithm
():
"""
>>> arithm() == 9*2+3*8//6-10
True
"""
return
9
*
2
+
3
*
8
//
6
-
10
def
parameters
():
"""
>>> parameters() == _func(-1 -2, - (-3+4), 1*2*3)
True
"""
return
_func
(
-
1
-
2
,
-
(
-
3
+
4
),
1
*
2
*
3
)
def
lists
():
"""
>>> lists() == [1,2,3] + [4,5,6]
True
"""
return
[
1
,
2
,
3
]
+
[
4
,
5
,
6
]
tests/run/cpdef_temps_T411.pyx
View file @
c8b85056
__doc__
=
"""
cdef
class
A
:
"""
>>> A().is_True()
True
>>> A().is_False()
False
>>> B().is_True()
True
>>> B().is_False()
False
"""
cdef
class
A
:
"""
cpdef
is_True
(
self
):
return
True
cpdef
is_False
(
self
):
return
not
self
.
is_True
()
class
B
(
A
):
"""
>>> B().is_True()
True
>>> B().is_False()
False
"""
def
is_True
(
self
):
return
True
tests/run/crashT245.pyx
View file @
c8b85056
__doc__
=
"""
>>> f()
{'x': 1}
"""
cimport
crashT245_pxd
def
f
():
"""
>>> f()
{'x': 1}
"""
cdef
crashT245_pxd
.
MyStruct
s
s
.
x
=
1
print
s
tests/run/cstruct.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test_i()
>>> test_c()
>>> test_p()
>>> test_g()
"""
cdef
struct
Grail
cdef
struct
Spam
:
...
...
@@ -41,19 +34,31 @@ cdef void eggs_g(Spam s):
spam
=
ham
def
test_i
():
"""
>>> test_i()
"""
spam
.
i
=
1
eggs_i
(
spam
)
def
test_c
():
"""
>>> test_c()
"""
spam
.
c
=
c
'a'
eggs_c
(
spam
)
def
test_p
():
"""
>>> test_p()
"""
cdef
float
f
spam
.
p
[
0
]
=
&
f
eggs_p
(
spam
)
def
test_g
():
"""
>>> test_g()
"""
cdef
Grail
l
spam
.
g
=
&
l
eggs_g
(
spam
)
tests/run/ct_IF.pyx
View file @
c8b85056
__doc__
=
u"""
>>> f()
1
>>> g()
2
>>> h()
3
"""
DEF
NO
=
0
DEF
YES
=
1
def
f
():
"""
>>> f()
1
"""
cdef
int
i
IF
YES
:
i
=
1
...
...
@@ -21,6 +16,10 @@ def f():
return
i
def
g
():
"""
>>> g()
2
"""
cdef
int
i
IF
NO
:
i
=
1
...
...
@@ -31,6 +30,10 @@ def g():
return
i
def
h
():
"""
>>> h()
3
"""
cdef
int
i
IF
NO
:
i
=
1
...
...
tests/run/ctruthtests.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test_int(0)
False
>>> test_int(1)
True
>>> test_short(0)
False
>>> test_short(1)
True
>>> test_Py_ssize_t(0)
False
>>> test_Py_ssize_t(1)
True
>>> test_ptr()
False
>>> test_ptr2()
2
>>> test_attr_int(TestExtInt(0))
False
>>> test_attr_int(TestExtInt(1))
True
>>> test_attr_ptr(TestExtPtr(0))
False
>>> test_attr_ptr(TestExtPtr(1))
True
"""
def
test_ptr
():
"""
>>> test_ptr()
False
"""
cdef
void
*
p
=
NULL
if
p
:
return
True
...
...
@@ -38,6 +10,10 @@ def test_ptr():
return
False
def
test_ptr2
():
"""
>>> test_ptr2()
2
"""
cdef
char
*
p1
=
NULL
cdef
char
*
p2
=
NULL
p1
+=
1
...
...
@@ -50,18 +26,36 @@ def test_ptr2():
return
3
def
test_int
(
int
i
):
"""
>>> test_int(0)
False
>>> test_int(1)
True
"""
if
i
:
return
True
else
:
return
False
def
test_short
(
short
i
):
"""
>>> test_short(0)
False
>>> test_short(1)
True
"""
if
i
:
return
True
else
:
return
False
def
test_Py_ssize_t
(
Py_ssize_t
i
):
"""
>>> test_Py_ssize_t(0)
False
>>> test_Py_ssize_t(1)
True
"""
if
i
:
return
True
else
:
...
...
@@ -72,6 +66,12 @@ cdef class TestExtInt:
def
__init__
(
self
,
i
):
self
.
i
=
i
def
test_attr_int
(
TestExtInt
e
):
"""
>>> test_attr_int(TestExtInt(0))
False
>>> test_attr_int(TestExtInt(1))
True
"""
if
e
.
i
:
return
True
else
:
...
...
@@ -82,6 +82,12 @@ cdef class TestExtPtr:
def
__init__
(
self
,
int
i
):
self
.
p
=
<
void
*>
i
def
test_attr_ptr
(
TestExtPtr
e
):
"""
>>> test_attr_ptr(TestExtPtr(0))
False
>>> test_attr_ptr(TestExtPtr(1))
True
"""
if
e
.
p
:
return
True
else
:
...
...
tests/run/cunion.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test_i()
>>> test_c()
>>> test_p()
"""
cdef
union
Spam
:
int
i
char
c
...
...
@@ -29,14 +23,23 @@ cdef void eggs_p(Spam s):
spam
=
ham
def
test_i
():
"""
>>> test_i()
"""
spam
.
i
=
1
eggs_i
(
spam
)
def
test_c
():
"""
>>> test_c()
"""
spam
.
c
=
c
'a'
eggs_c
(
spam
)
def
test_p
():
"""
>>> test_p()
"""
cdef
float
f
spam
.
p
[
0
]
=
&
f
eggs_p
(
spam
)
tests/run/cvardef.pyx
View file @
c8b85056
__doc__
=
u"""
>>> f()
"""
def
f
():
"""
>>> f()
"""
cdef
char
a_char
cdef
short
a_short
cdef
int
i1
,
i2
...
...
tests/run/dict.pyx
View file @
c8b85056
__doc__
=
u"""
def
empty
():
"""
>>> empty()
{}
"""
d
=
{}
return
d
def
keyvalue
(
key
,
value
):
"""
>>> keyvalue(1, 2)
{1: 2}
"""
d
=
{
key
:
value
}
return
d
def
keyvalues
(
key1
,
value1
,
key2
,
value2
):
"""
>>> keyvalues(1, 2, 3, 4)
{1: 2, 3: 4}
"""
d
=
{
key1
:
value1
,
key2
:
value2
}
return
d
def
keyvalues2
(
key1
,
value1
,
key2
,
value2
):
"""
>>> keyvalues2(1, 2, 3, 4)
{1: 2, 3: 4}
"""
d
=
{
key1
:
value1
,
key2
:
value2
,}
return
d
def
constant
():
"""
>>> len(constant())
2
>>> print(constant()['parrot'])
resting
>>> print(constant()['answer'])
42
"""
d
=
{
u"parrot"
:
u"resting"
,
u"answer"
:
42
}
return
d
def
dict_call
():
"""
>>> print(dict_call()['parrot'])
resting
>>> print(dict_call()['answer'])
42
"""
d
=
dict
(
parrot
=
u"resting"
,
answer
=
42
)
return
d
def
dict_call_dict
():
"""
>>> print(dict_call_dict()['parrot'])
resting
>>> print(dict_call_dict()['answer'])
42
"""
d
=
dict
(
dict
(
parrot
=
u"resting"
,
answer
=
42
))
return
d
def
dict_call_kwargs
():
"""
>>> print(dict_call_kwargs()['parrot1'])
resting
>>> print(dict_call_kwargs()['parrot2'])
...
...
@@ -34,37 +72,7 @@ __doc__ = u"""
42
>>> print(dict_call_kwargs()['answer2'])
42
"""
def
empty
():
d
=
{}
return
d
def
keyvalue
(
key
,
value
):
d
=
{
key
:
value
}
return
d
def
keyvalues
(
key1
,
value1
,
key2
,
value2
):
d
=
{
key1
:
value1
,
key2
:
value2
}
return
d
def
keyvalues2
(
key1
,
value1
,
key2
,
value2
):
d
=
{
key1
:
value1
,
key2
:
value2
,}
return
d
def
constant
():
d
=
{
u"parrot"
:
u"resting"
,
u"answer"
:
42
}
return
d
def
dict_call
():
d
=
dict
(
parrot
=
u"resting"
,
answer
=
42
)
return
d
def
dict_call_dict
():
d
=
dict
(
dict
(
parrot
=
u"resting"
,
answer
=
42
))
return
d
def
dict_call_kwargs
():
"""
kwargs
=
dict
(
parrot1
=
u"resting"
,
answer1
=
42
)
d
=
dict
(
parrot2
=
u"resting"
,
answer2
=
42
,
**
kwargs
)
return
d
tests/run/dictintindex.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test_get_char_neg()
0
>>> test_get_char_zero()
1
>>> test_get_char_pos()
2
>>> test_get_uchar_zero()
1
>>> test_get_uchar_pos()
2
>>> test_get_int_neg()
0
>>> test_get_int_zero()
1
>>> test_get_int_pos()
2
>>> test_get_uint_zero()
1
>>> test_get_uint_pos()
2
>>> test_get_longlong_neg()
0
>>> test_get_longlong_zero()
1
>>> test_get_longlong_pos()
2
>>> test_get_longlong_big()
3
>>> test_get_ulonglong_zero()
1
>>> test_get_ulonglong_pos()
2
>>> test_get_ulonglong_big()
3
>>> test_del_char()
Traceback (most recent call last):
KeyError: 0
>>> test_del_uchar()
Traceback (most recent call last):
KeyError: 0
>>> test_del_int()
Traceback (most recent call last):
KeyError: 0
>>> test_del_uint() #doctest: +ELLIPSIS
Traceback (most recent call last):
KeyError: 0...
>>> test_del_longlong() #doctest: +ELLIPSIS
Traceback (most recent call last):
KeyError: 0...
>>> test_del_longlong_big() #doctest: +ELLIPSIS
Traceback (most recent call last):
KeyError: ...
>>> test_del_ulonglong() #doctest: +ELLIPSIS
Traceback (most recent call last):
KeyError: 0...
>>> test_del_ulonglong_big() #doctest: +ELLIPSIS
Traceback (most recent call last):
KeyError: ...
"""
def
test_get_char_neg
():
"""
>>> test_get_char_neg()
0
"""
cdef
char
key
=
-
1
d
=
{
-
1
:
0
}
return
d
[
key
]
def
test_get_char_zero
():
"""
>>> test_get_char_zero()
1
"""
cdef
char
key
=
0
d
=
{
0
:
1
}
return
d
[
key
]
def
test_get_char_pos
():
"""
>>> test_get_char_pos()
2
"""
cdef
char
key
=
1
d
=
{
1
:
2
}
return
d
[
key
]
def
test_get_uchar_zero
():
"""
>>> test_get_uchar_zero()
1
"""
cdef
unsigned
char
key
=
0
d
=
{
0
:
1
}
return
d
[
key
]
def
test_get_uchar_pos
():
"""
>>> test_get_uchar_pos()
2
"""
cdef
unsigned
char
key
=
1
d
=
{
1
:
2
}
return
d
[
key
]
def
test_get_int_neg
():
"""
>>> test_get_int_neg()
0
"""
cdef
int
key
=
-
1
d
=
{
-
1
:
0
}
return
d
[
key
]
def
test_get_int_zero
():
"""
>>> test_get_int_zero()
1
"""
cdef
int
key
=
0
d
=
{
0
:
1
}
return
d
[
key
]
def
test_get_int_pos
():
"""
>>> test_get_int_pos()
2
"""
cdef
int
key
=
1
d
=
{
1
:
2
}
return
d
[
key
]
def
test_get_uint_zero
():
"""
>>> test_get_uint_zero()
1
"""
cdef
unsigned
int
key
=
0
d
=
{
0
:
1
}
return
d
[
key
]
def
test_get_uint_pos
():
"""
>>> test_get_uint_pos()
2
"""
cdef
unsigned
int
key
=
1
d
=
{
1
:
2
}
return
d
[
key
]
def
test_get_longlong_neg
():
"""
>>> test_get_longlong_neg()
0
"""
cdef
long
long
key
=
-
1
d
=
{
-
1
:
0
}
return
d
[
key
]
def
test_get_longlong_zero
():
"""
>>> test_get_longlong_zero()
1
"""
cdef
long
long
key
=
0
d
=
{
0
:
1
}
return
d
[
key
]
def
test_get_longlong_pos
():
"""
>>> test_get_longlong_pos()
2
"""
cdef
long
long
key
=
1
d
=
{
1
:
2
}
return
d
[
key
]
def
test_get_longlong_big
():
"""
>>> test_get_longlong_big()
3
"""
cdef
unsigned
int
shift
=
sizeof
(
long
)
+
2
cdef
long
long
big
=
1
cdef
long
long
key
=
big
<<
shift
...
...
@@ -127,14 +122,26 @@ def test_get_longlong_big():
return
d
[
key
]
def
test_get_ulonglong_zero
():
"""
>>> test_get_ulonglong_zero()
1
"""
cdef
unsigned
long
long
key
=
0
d
=
{
0
:
1
}
return
d
[
key
]
def
test_get_ulonglong_pos
():
"""
>>> test_get_ulonglong_pos()
2
"""
cdef
unsigned
long
long
key
=
1
d
=
{
1
:
2
}
return
d
[
key
]
def
test_get_ulonglong_big
():
"""
>>> test_get_ulonglong_big()
3
"""
cdef
unsigned
int
shift
=
sizeof
(
long
)
+
2
cdef
unsigned
long
long
big
=
1
cdef
unsigned
long
long
key
=
big
<<
shift
...
...
@@ -143,42 +150,77 @@ def test_get_ulonglong_big():
def
test_del_char
():
"""
>>> test_del_char()
Traceback (most recent call last):
KeyError: 0
"""
cdef
char
key
=
0
d
=
{
0
:
1
}
del
d
[
key
]
return
d
[
key
]
def
test_del_uchar
():
"""
>>> test_del_uchar()
Traceback (most recent call last):
KeyError: 0
"""
cdef
unsigned
char
key
=
0
d
=
{
0
:
1
}
del
d
[
key
]
return
d
[
key
]
def
test_del_int
():
"""
>>> test_del_int()
Traceback (most recent call last):
KeyError: 0
"""
cdef
int
key
=
0
d
=
{
0
:
1
}
del
d
[
key
]
return
d
[
key
]
def
test_del_uint
():
"""
>>> test_del_uint() #doctest: +ELLIPSIS
Traceback (most recent call last):
KeyError: 0...
"""
cdef
unsigned
int
key
=
0
d
=
{
0
:
1
}
del
d
[
key
]
return
d
[
key
]
def
test_del_longlong
():
"""
>>> test_del_longlong() #doctest: +ELLIPSIS
Traceback (most recent call last):
KeyError: 0...
"""
cdef
long
long
key
=
0
d
=
{
0
:
1
}
del
d
[
key
]
return
d
[
key
]
def
test_del_ulonglong
():
"""
>>> test_del_ulonglong() #doctest: +ELLIPSIS
Traceback (most recent call last):
KeyError: 0...
"""
cdef
unsigned
long
long
key
=
0
d
=
{
0
:
1
}
del
d
[
key
]
return
d
[
key
]
def
test_del_longlong_big
():
"""
>>> test_del_longlong_big() #doctest: +ELLIPSIS
Traceback (most recent call last):
KeyError: ...
"""
cdef
int
shift
=
sizeof
(
long
)
+
2
cdef
long
long
big
=
1
cdef
long
long
key
=
big
<<
shift
...
...
@@ -187,6 +229,11 @@ def test_del_longlong_big():
return
d
[
key
]
def
test_del_ulonglong_big
():
"""
>>> test_del_ulonglong_big() #doctest: +ELLIPSIS
Traceback (most recent call last):
KeyError: ...
"""
cdef
unsigned
int
shift
=
sizeof
(
long
)
+
2
cdef
unsigned
long
long
big
=
1
cdef
unsigned
long
long
key
=
big
<<
shift
...
...
tests/run/dietachmayer1.pyx
View file @
c8b85056
__doc__
=
u"""
def
test
():
"""
>>> test()
1.0
"""
def
test
():
"""
cdef
float
v
[
10
][
10
]
v
[
1
][
2
]
=
1.0
return
v
[
1
][
2
]
tests/run/empty_for_loop_T208.pyx
View file @
c8b85056
__doc__
=
u"""
def
go_py_empty
():
"""
>>> go_py_empty()
20
>>> go_c_empty()
20
"""
def
go_py_empty
():
"""
i
=
20
for
i
in
range
(
4
,
0
):
print
u"Spam!"
return
i
def
go_c_empty
():
"""
>>> go_c_empty()
20
"""
cdef
int
i
=
20
for
i
in
range
(
4
,
0
):
print
u"Spam!"
...
...
tests/run/enumerate_T316.pyx
View file @
c8b85056
__doc__
=
u"""
>>> go_c_enumerate()
0 1
1 2
2 3
3 4
cimport
cython
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode//NameNode[@name = 'enumerate']"
)
def
go_py_enumerate
():
"""
>>> go_py_enumerate()
0 1
1 2
2 3
3 4
>>> empty_c_enumerate()
(55, 99)
>>> go_c_enumerate_step()
0 1
1 3
2 5
>>> single_target_enumerate()
0 1
1 2
2 3
3 4
>>> multi_enumerate()
0 0 0 1
1 1 1 2
2 2 2 3
3 3 3 4
>>> multi_c_enumerate()
0 0 0 1
1 1 1 2
2 2 2 3
3 3 3 4
>>> py_enumerate_break(1,2,3,4)
0 1
:: 0 1
>>> py_enumerate_return()
:: 55 99
>>> py_enumerate_return(1,2,3,4)
0 1
>>> py_enumerate_continue(1,2,3,4)
0 1
1 2
2 3
3 4
:: 3 4
>>> py_enumerate_dict({})
:: 55 99
>>> py_enumerate_dict(dict(a=1, b=2, c=3))
0 a
1 c
2 b
:: 2 b
"""
cimport
cython
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode//NameNode[@name = 'enumerate']"
)
def
go_py_enumerate
():
"""
for
i
,
k
in
enumerate
(
range
(
1
,
5
)):
print
i
,
k
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode//NameNode[@name = 'enumerate']"
)
def
go_c_enumerate
():
"""
>>> go_c_enumerate()
0 1
1 2
2 3
3 4
"""
cdef
int
i
,
k
for
i
,
k
in
enumerate
(
range
(
1
,
5
)):
print
i
,
k
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode//NameNode[@name = 'enumerate']"
)
def
go_c_enumerate_step
():
"""
>>> go_c_enumerate_step()
0 1
1 3
2 5
"""
cdef
int
i
,
k
for
i
,
k
in
enumerate
(
range
(
1
,
7
,
2
)):
print
i
,
k
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode//NameNode[@name = 'enumerate']"
)
def
py_enumerate_dict
(
dict
d
):
"""
>>> py_enumerate_dict({})
:: 55 99
>>> py_enumerate_dict(dict(a=1, b=2, c=3))
0 a
1 c
2 b
:: 2 b
"""
cdef
int
i
=
55
k
=
99
for
i
,
k
in
enumerate
(
d
):
...
...
@@ -92,6 +56,11 @@ def py_enumerate_dict(dict d):
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode"
)
def
py_enumerate_break
(
*
t
):
"""
>>> py_enumerate_break(1,2,3,4)
0 1
:: 0 1
"""
i
,
k
=
55
,
99
for
i
,
k
in
enumerate
(
t
):
print
i
,
k
...
...
@@ -100,6 +69,12 @@ def py_enumerate_break(*t):
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode"
)
def
py_enumerate_return
(
*
t
):
"""
>>> py_enumerate_return()
:: 55 99
>>> py_enumerate_return(1,2,3,4)
0 1
"""
i
,
k
=
55
,
99
for
i
,
k
in
enumerate
(
t
):
print
i
,
k
...
...
@@ -108,6 +83,14 @@ def py_enumerate_return(*t):
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode"
)
def
py_enumerate_continue
(
*
t
):
"""
>>> py_enumerate_continue(1,2,3,4)
0 1
1 2
2 3
3 4
:: 3 4
"""
i
,
k
=
55
,
99
for
i
,
k
in
enumerate
(
t
):
print
i
,
k
...
...
@@ -116,6 +99,10 @@ def py_enumerate_continue(*t):
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode//NameNode[@name = 'enumerate']"
)
def
empty_c_enumerate
():
"""
>>> empty_c_enumerate()
(55, 99)
"""
cdef
int
i
=
55
,
k
=
99
for
i
,
k
in
enumerate
(
range
(
0
)):
print
i
,
k
...
...
@@ -123,16 +110,49 @@ def empty_c_enumerate():
# not currently optimised
def
single_target_enumerate
():
"""
>>> single_target_enumerate()
0 1
1 2
2 3
3 4
"""
for
t
in
enumerate
(
range
(
1
,
5
)):
print
t
[
0
],
t
[
1
]
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode//NameNode[@name = 'enumerate']"
)
def
multi_enumerate
():
"""
>>> multi_enumerate()
0 0 0 1
1 1 1 2
2 2 2 3
3 3 3 4
"""
for
a
,(
b
,(
c
,
d
))
in
enumerate
(
enumerate
(
enumerate
(
range
(
1
,
5
)))):
print
a
,
b
,
c
,
d
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode"
)
def
multi_c_enumerate
():
"""
>>> multi_c_enumerate()
0 0 0 1
1 1 1 2
2 2 2 3
3 3 3 4
"""
cdef
int
a
,
b
,
c
,
d
for
a
,(
b
,(
c
,
d
))
in
enumerate
(
enumerate
(
enumerate
(
range
(
1
,
5
)))):
print
a
,
b
,
c
,
d
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode"
)
def
convert_target_enumerate
(
L
):
"""
>>> convert_target_enumerate([2,3,5])
0 2
1 3
2 5
"""
cdef
int
a
,
b
for
a
,
b
in
enumerate
(
L
):
print
a
,
b
tests/run/exceptionpropagation.pyx
View file @
c8b85056
__doc__
=
u"""
>>> foo(0)
>>> foo(1)
Traceback (most recent call last):
RuntimeError
"""
cdef
int
CHKERR
(
int
ierr
)
except
-
1
:
if
ierr
==
0
:
return
0
raise
RuntimeError
...
...
@@ -13,6 +6,12 @@ cdef int obj2int(object ob) except *:
return
ob
def
foo
(
a
):
"""
>>> foo(0)
>>> foo(1)
Traceback (most recent call last):
RuntimeError
"""
cdef
int
i
=
obj2int
(
a
)
CHKERR
(
i
)
...
...
tests/run/ext_instance_type_T232.pyx
View file @
c8b85056
__doc__
=
u"""
>>> set_attr(5)
>>> get_attr()
"""
cdef
class
MyExt
:
cdef
object
attr
def
set_attr
(
value
):
"""
>>> set_attr(5)
"""
MyExt
().
attr
=
value
def
get_attr
():
"""
>>> get_attr()
"""
return
MyExt
().
attr
tests/run/extcmethod.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test()
5
0
20
5
"""
cdef
class
Spam
:
cdef
int
tons
...
...
@@ -25,6 +17,13 @@ cdef class SuperSpam(Spam):
self
.
tons
=
self
.
tons
+
2
*
x
def
test
():
"""
>>> test()
5
0
20
5
"""
cdef
Spam
s
cdef
SuperSpam
ss
s
=
Spam
()
...
...
tests/run/extended_unpacking_T235.pyx
View file @
c8b85056
__doc__
=
u"""
>>> class FakeSeq(object):
... def __init__(self, length):
... self._values = list(range(1,length+1))
... def __getitem__(self, i):
... return self._values[i]
>>> unpack([1,2])
(1, 2)
>>> unpack_list([1,2])
(1, 2)
>>> unpack_tuple((1,2))
(1, 2)
>>> unpack( FakeSeq(2) )
(1, 2)
>>> unpack('12')
('1', '2')
>>> unpack_into_list('123')
('1', ['2'], '3')
>>> unpack_into_tuple('123')
('1', ['2'], '3')
>>> unpack_in_loop([(1,2), (1,2,3), (1,2,3,4)])
1
([1], 2)
([1, 2], 3)
([1, 2, 3], 4)
2
(1, [2])
(1, [2, 3])
(1, [2, 3, 4])
3
(1, [], 2)
(1, [2], 3)
(1, [2, 3], 4)
>>> unpack_recursive((1,2,3,4))
(1, [2, 3], 4)
>>> unpack_recursive( FakeSeq(4) )
(1, [2, 3], 4)
>>> unpack_typed((1,2))
([1], 2)
>>> assign()
(1, [2, 3, 4], 5)
>>> unpack_right('')
Traceback (most recent call last):
ValueError: need more than 0 values to unpack
>>> unpack_right_list([])
Traceback (most recent call last):
ValueError: need more than 0 values to unpack
>>> unpack_right_tuple(())
Traceback (most recent call last):
ValueError: need more than 0 values to unpack
>>> unpack_right('1')
('1', [])
>>> unpack_right([1])
(1, [])
>>> unpack_right('12')
('1', ['2'])
>>> unpack_right([1,2])
(1, [2])
>>> unpack_right('123')
('1', ['2', '3'])
>>> unpack_right([1,2,3])
(1, [2, 3])
>>> unpack_right_list([1])
(1, [])
>>> unpack_right_list([1,2])
(1, [2])
>>> unpack_right_list([1,2,3])
(1, [2, 3])
>>> unpack_right_tuple((1,))
(1, [])
>>> unpack_right_tuple((1,2))
(1, [2])
>>> unpack_right_tuple((1,2,3))
(1, [2, 3])
>>> unpack_left('')
Traceback (most recent call last):
ValueError: need more than 0 values to unpack
>>> unpack_left_list([])
Traceback (most recent call last):
ValueError: need more than 0 values to unpack
>>> unpack_left_tuple(())
Traceback (most recent call last):
ValueError: need more than 0 values to unpack
>>> unpack_left('1')
([], '1')
>>> unpack_left([1])
([], 1)
>>> unpack_left('12')
(['1'], '2')
>>> unpack_left([1,2])
([1], 2)
>>> unpack_left('123')
(['1', '2'], '3')
>>> unpack_left([1,2,3])
([1, 2], 3)
>>> unpack_left_list([1])
([], 1)
>>> unpack_left_list([1,2])
([1], 2)
>>> unpack_left_list([1,2,3])
([1, 2], 3)
>>> unpack_left_tuple((1,))
([], 1)
>>> unpack_left_tuple((1,2))
([1], 2)
>>> unpack_left_tuple((1,2,3))
([1, 2], 3)
>>> unpack_middle('')
Traceback (most recent call last):
ValueError: need more than 0 values to unpack
>>> unpack_middle([])
Traceback (most recent call last):
ValueError: need more than 0 values to unpack
>>> unpack_middle(())
Traceback (most recent call last):
ValueError: need more than 0 values to unpack
>>> unpack_middle_list([])
Traceback (most recent call last):
ValueError: need more than 0 values to unpack
>>> unpack_middle_tuple(())
Traceback (most recent call last):
ValueError: need more than 0 values to unpack
>>> unpack_middle('1')
Traceback (most recent call last):
ValueError: need more than 1 value to unpack
>>> unpack_middle([1])
Traceback (most recent call last):
ValueError: need more than 1 value to unpack
>>> unpack_middle_list([1])
Traceback (most recent call last):
ValueError: need more than 1 value to unpack
>>> unpack_middle_tuple((1,))
Traceback (most recent call last):
ValueError: need more than 1 value to unpack
>>> unpack_middle('12')
('1', [], '2')
>>> unpack_middle([1,2])
(1, [], 2)
>>> unpack_middle('123')
('1', ['2'], '3')
>>> unpack_middle([1,2,3])
(1, [2], 3)
>>> unpack_middle_list([1,2])
(1, [], 2)
>>> unpack_middle_list([1,2,3])
(1, [2], 3)
>>> unpack_middle_tuple((1,2))
(1, [], 2)
>>> unpack_middle_tuple((1,2,3))
(1, [2], 3)
>>> a,b,c = unpack_middle(list(range(100)))
>>> a, len(b), c
(0, 98, 99)
>>> a,b,c = unpack_middle_list(list(range(100)))
>>> a, len(b), c
(0, 98, 99)
>>> a,b,c = unpack_middle_tuple(tuple(range(100)))
>>> a, len(b), c
(0, 98, 99)
>>> class FakeSeq(object):
... def __init__(self, length):
... self._values = list(range(1,length+1))
... def __getitem__(self, i):
... return self._values[i]
>>> unpack( FakeSeq(2) )
(1, 2)
>>> unpack_recursive( FakeSeq(4) )
(1, [2, 3], 4)
"""
def
unpack
(
l
):
"""
>>> unpack([1,2])
(1, 2)
>>> unpack('12')
('1', '2')
"""
a
,
b
=
l
return
a
,
b
def
unpack_list
(
list
l
):
"""
>>> unpack_list([1,2])
(1, 2)
"""
a
,
b
=
l
return
a
,
b
def
unpack_tuple
(
tuple
t
):
"""
>>> unpack_tuple((1,2))
(1, 2)
"""
a
,
b
=
t
return
a
,
b
def
assign
():
"""
>>> assign()
(1, [2, 3, 4], 5)
"""
*
a
,
b
=
1
,
2
,
3
,
4
,
5
assert
a
+
[
b
]
==
[
1
,
2
,
3
,
4
,
5
],
(
a
,
b
)
a
,
*
b
=
1
,
2
,
3
,
4
,
5
...
...
@@ -198,6 +50,10 @@ def assign():
return
a
,
b
,
c
def
unpack_into_list
(
l
):
"""
>>> unpack_into_list('123')
('1', ['2'], '3')
"""
[
*
a
,
b
]
=
l
assert
a
+
[
b
]
==
list
(
l
),
repr
((
a
+
[
b
],
list
(
l
)))
[
a
,
*
b
]
=
l
...
...
@@ -206,6 +62,10 @@ def unpack_into_list(l):
return
a
,
b
,
c
def
unpack_into_tuple
(
t
):
"""
>>> unpack_into_tuple('123')
('1', ['2'], '3')
"""
(
*
a
,
b
)
=
t
assert
a
+
[
b
]
==
list
(
t
),
repr
((
a
+
[
b
],
list
(
t
)))
(
a
,
*
b
)
=
t
...
...
@@ -214,6 +74,21 @@ def unpack_into_tuple(t):
return
a
,
b
,
c
def
unpack_in_loop
(
list_of_sequences
):
"""
>>> unpack_in_loop([(1,2), (1,2,3), (1,2,3,4)])
1
([1], 2)
([1, 2], 3)
([1, 2, 3], 4)
2
(1, [2])
(1, [2, 3])
(1, [2, 3, 4])
3
(1, [], 2)
(1, [2], 3)
(1, [2, 3], 4)
"""
print
1
for
*
a
,
b
in
list_of_sequences
:
print
((
a
,
b
))
...
...
@@ -225,49 +100,193 @@ def unpack_in_loop(list_of_sequences):
print
((
a
,
b
,
c
))
def
unpack_recursive
(
t
):
"""
>>> unpack_recursive((1,2,3,4))
(1, [2, 3], 4)
"""
*
(
a
,
*
b
),
c
=
t
return
a
,
b
,
c
def
unpack_typed
(
t
):
"""
>>> unpack_typed((1,2))
([1], 2)
"""
cdef
list
a
*
a
,
b
=
t
return
a
,
b
def
unpack_right
(
l
):
"""
>>> unpack_right('')
Traceback (most recent call last):
ValueError: need more than 0 values to unpack
>>> unpack_right('1')
('1', [])
>>> unpack_right([1])
(1, [])
>>> unpack_right('12')
('1', ['2'])
>>> unpack_right([1,2])
(1, [2])
>>> unpack_right('123')
('1', ['2', '3'])
>>> unpack_right([1,2,3])
(1, [2, 3])
"""
a
,
*
b
=
l
return
a
,
b
def
unpack_right_list
(
list
l
):
"""
>>> unpack_right_list([])
Traceback (most recent call last):
ValueError: need more than 0 values to unpack
>>> unpack_right_list([1])
(1, [])
>>> unpack_right_list([1,2])
(1, [2])
>>> unpack_right_list([1,2,3])
(1, [2, 3])
"""
a
,
*
b
=
l
return
a
,
b
def
unpack_right_tuple
(
tuple
t
):
"""
>>> unpack_right_tuple(())
Traceback (most recent call last):
ValueError: need more than 0 values to unpack
>>> unpack_right_tuple((1,))
(1, [])
>>> unpack_right_tuple((1,2))
(1, [2])
>>> unpack_right_tuple((1,2,3))
(1, [2, 3])
"""
a
,
*
b
=
t
return
a
,
b
def
unpack_left
(
l
):
"""
>>> unpack_left('')
Traceback (most recent call last):
ValueError: need more than 0 values to unpack
>>> unpack_left('1')
([], '1')
>>> unpack_left([1])
([], 1)
>>> unpack_left('12')
(['1'], '2')
>>> unpack_left([1,2])
([1], 2)
>>> unpack_left('123')
(['1', '2'], '3')
>>> unpack_left([1,2,3])
([1, 2], 3)
"""
*
a
,
b
=
l
return
a
,
b
def
unpack_left_list
(
list
l
):
"""
>>> unpack_left_list([])
Traceback (most recent call last):
ValueError: need more than 0 values to unpack
>>> unpack_left_list([1])
([], 1)
>>> unpack_left_list([1,2])
([1], 2)
>>> unpack_left_list([1,2,3])
([1, 2], 3)
"""
*
a
,
b
=
l
return
a
,
b
def
unpack_left_tuple
(
tuple
t
):
"""
>>> unpack_left_tuple(())
Traceback (most recent call last):
ValueError: need more than 0 values to unpack
>>> unpack_left_tuple((1,))
([], 1)
>>> unpack_left_tuple((1,2))
([1], 2)
>>> unpack_left_tuple((1,2,3))
([1, 2], 3)
"""
*
a
,
b
=
t
return
a
,
b
def
unpack_middle
(
l
):
"""
>>> unpack_middle('')
Traceback (most recent call last):
ValueError: need more than 0 values to unpack
>>> unpack_middle([])
Traceback (most recent call last):
ValueError: need more than 0 values to unpack
>>> unpack_middle(())
Traceback (most recent call last):
ValueError: need more than 0 values to unpack
>>> unpack_middle('1')
Traceback (most recent call last):
ValueError: need more than 1 value to unpack
>>> unpack_middle([1])
Traceback (most recent call last):
ValueError: need more than 1 value to unpack
>>> unpack_middle('12')
('1', [], '2')
>>> unpack_middle([1,2])
(1, [], 2)
>>> unpack_middle('123')
('1', ['2'], '3')
>>> unpack_middle([1,2,3])
(1, [2], 3)
"""
a
,
*
b
,
c
=
l
return
a
,
b
,
c
def
unpack_middle_list
(
list
l
):
"""
>>> unpack_middle_list([])
Traceback (most recent call last):
ValueError: need more than 0 values to unpack
>>> unpack_middle_list([1])
Traceback (most recent call last):
ValueError: need more than 1 value to unpack
>>> unpack_middle_list([1,2])
(1, [], 2)
>>> unpack_middle_list([1,2,3])
(1, [2], 3)
"""
a
,
*
b
,
c
=
l
return
a
,
b
,
c
def
unpack_middle_tuple
(
tuple
t
):
"""
>>> unpack_middle_tuple(())
Traceback (most recent call last):
ValueError: need more than 0 values to unpack
>>> unpack_middle_tuple((1,))
Traceback (most recent call last):
ValueError: need more than 1 value to unpack
>>> unpack_middle_tuple((1,2))
(1, [], 2)
>>> unpack_middle_tuple((1,2,3))
(1, [2], 3)
>>> a,b,c = unpack_middle(list(range(100)))
>>> a, len(b), c
(0, 98, 99)
>>> a,b,c = unpack_middle_list(list(range(100)))
>>> a, len(b), c
(0, 98, 99)
>>> a,b,c = unpack_middle_tuple(tuple(range(100)))
>>> a, len(b), c
(0, 98, 99)
"""
a
,
*
b
,
c
=
t
return
a
,
b
,
c
tests/run/extended_unpacking_T409.pyx
View file @
c8b85056
def
simple
():
"""
>>> simple()
...
...
tests/run/extinherit.pyx
View file @
c8b85056
__doc__
=
u"""
>>> p = create()
>>> rest(p)
0
"""
cdef
class
Parrot
:
cdef
object
name
cdef
int
alive
...
...
@@ -18,6 +12,11 @@ def create():
return
p
def
rest
(
Norwegian
polly
):
"""
>>> p = create()
>>> rest(p)
0
"""
cdef
Parrot
fred
cdef
object
spam
spam
=
None
...
...
tests/run/extkwonlyargs.pyx
View file @
c8b85056
...
...
@@ -2,27 +2,46 @@ __doc__ = u"""
>>> ext = Ext()
>>> b,c,d,e,f,g,h,k = ext.b,ext.c,ext.d,ext.e,ext.f,ext.g,ext.h,ext.k
>>> b(1,2,3)
>>> b(1,2,3,4)
Traceback (most recent call last):
TypeError: b() takes exactly 3 positional arguments (4 given)
"""
cdef
class
Ext
:
def
b
(
self
,
a
,
b
,
c
):
pass
def
c
(
self
,
a
,
b
,
c
=
1
):
pass
def
d
(
self
,
a
,
b
,
*
,
c
=
88
):
pass
def
e
(
self
,
a
,
b
,
c
=
88
,
**
kwds
):
pass
def
f
(
self
,
a
,
b
,
*
,
c
,
d
=
42
):
pass
def
g
(
self
,
a
,
b
,
*
,
c
,
d
=
42
,
e
=
17
,
f
,
**
kwds
):
pass
def
h
(
self
,
a
,
b
,
*
args
,
c
,
d
=
42
,
e
=
17
,
f
,
**
kwds
):
pass
def
k
(
self
,
a
,
b
,
c
=
1
,
*
args
,
d
=
42
,
e
=
17
,
f
,
**
kwds
):
pass
"""# c
>>> c(1,2)
>>> c(1,2,3)
>>> c(1,2,3,4)
Traceback (most recent call last):
TypeError: c() takes at most 3 positional arguments (4 given)
>>> d(1,2)
>>> d(1,2, c=1)
>>> d(1,2,3)
Traceback (most recent call last):
TypeError: d() takes exactly 2 positional arguments (3 given)
>>> d(1,2, d=1)
# b
>>> b(1,2,3)
>>> b(1,2,3,4)
Traceback (most recent call last):
TypeError:
d() got an unexpected keyword argument 'd'
TypeError:
b() takes exactly 3 positional arguments (4 given)
# e
>>> e(1,2)
>>> e(1,2, c=1)
>>> e(1,2, d=1)
...
...
@@ -32,19 +51,18 @@ __doc__ = u"""
Traceback (most recent call last):
TypeError: e() takes at most 3 positional arguments (4 given)
>>> f(1,2, c=1)
>>> f(1,2, c=1, d=2)
# d
>>> d(1,2)
>>> d(1,2, c=1)
>>> f(1,2,3)
Traceback (most recent call last):
TypeError: f() takes exactly 2 positional arguments (3 given)
>>> f(1,2)
>>> d(1,2,3)
Traceback (most recent call last):
TypeError:
f() needs keyword-only argument c
>>>
f(1,2, c=1, e=2
)
TypeError:
d() takes exactly 2 positional arguments (3 given)
>>>
d(1,2, d=1
)
Traceback (most recent call last):
TypeError:
f() got an unexpected keyword argument 'e
'
TypeError:
d() got an unexpected keyword argument 'd
'
# g
>>> g(1,2, c=1, f=2)
>>> g(1,2, c=1, e=0, f=2, d=11)
>>> g(1,2, c=1, f=2, e=0, x=25)
...
...
@@ -59,6 +77,21 @@ __doc__ = u"""
Traceback (most recent call last):
TypeError: g() needs keyword-only argument f
# f
>>> f(1,2, c=1)
>>> f(1,2, c=1, d=2)
>>> f(1,2,3)
Traceback (most recent call last):
TypeError: f() takes exactly 2 positional arguments (3 given)
>>> f(1,2)
Traceback (most recent call last):
TypeError: f() needs keyword-only argument c
>>> f(1,2, c=1, e=2)
Traceback (most recent call last):
TypeError: f() got an unexpected keyword argument 'e'
# h
>>> h(1,2, c=1, f=2)
>>> h(1,2, c=1, f=2, e=3)
>>> h(1,2,3,4,5,6, c=1, f=2)
...
...
@@ -71,6 +104,7 @@ __doc__ = u"""
Traceback (most recent call last):
TypeError: h() needs keyword-only argument c
# k
>>> k(1,2, c=1, f=2)
>>> k(1,2, c=1, f=2, e=3)
>>> k(1,2,3,4,5,6, d=1, f=2)
...
...
@@ -83,28 +117,3 @@ __doc__ = u"""
Traceback (most recent call last):
TypeError: k() needs keyword-only argument f
"""
cdef
class
Ext
:
def
b
(
self
,
a
,
b
,
c
):
pass
def
c
(
self
,
a
,
b
,
c
=
1
):
pass
def
d
(
self
,
a
,
b
,
*
,
c
=
88
):
pass
def
e
(
self
,
a
,
b
,
c
=
88
,
**
kwds
):
pass
def
f
(
self
,
a
,
b
,
*
,
c
,
d
=
42
):
pass
def
g
(
self
,
a
,
b
,
*
,
c
,
d
=
42
,
e
=
17
,
f
,
**
kwds
):
pass
def
h
(
self
,
a
,
b
,
*
args
,
c
,
d
=
42
,
e
=
17
,
f
,
**
kwds
):
pass
def
k
(
self
,
a
,
b
,
c
=
1
,
*
args
,
d
=
42
,
e
=
17
,
f
,
**
kwds
):
pass
tests/run/extlen.pyx
View file @
c8b85056
...
...
@@ -7,4 +7,3 @@ cdef class Spam:
def
__len__
(
self
):
return
0
tests/run/extpropertyref.pyx
View file @
c8b85056
__doc__
=
u"""
>>> tomato()
42
"""
cdef
class
Spam
:
property
eggs
:
...
...
@@ -11,6 +6,10 @@ cdef class Spam:
return
42
def
tomato
():
"""
>>> tomato()
42
"""
cdef
Spam
spam
cdef
object
lettuce
spam
=
Spam
()
...
...
tests/run/exttype.pyx
View file @
c8b85056
__doc__
=
u"""
>>> s = Spam(12)
>>> s.eat()
12 42
>>> f(s)
Traceback (most recent call last):
AttributeError: 'exttype.Spam' object has no attribute 'foo'
>>> s.eat()
12 42
>>> class Spam2(Spam):
... foo = 1
>>> s = Spam2(12)
>>> s.eat()
12 42
>>> f(s)
>>> s.eat()
12 42
"""
cdef
gobble
(
a
,
b
):
print
a
,
b
cdef
class
Spam
:
"""
>>> s = Spam(12)
>>> s.eat()
12 42
"""
cdef
eggs
cdef
int
ham
...
...
@@ -37,6 +22,22 @@ cdef class Spam:
gobble
(
self
.
eggs
,
self
.
ham
)
def
f
(
Spam
spam
):
"""
>>> s = Spam(12)
>>> f(s)
Traceback (most recent call last):
AttributeError: 'exttype.Spam' object has no attribute 'foo'
>>> s.eat()
12 42
>>> class Spam2(Spam):
... foo = 1
>>> s = Spam2(12)
>>> s.eat()
12 42
>>> f(s)
>>> s.eat()
12 42
"""
x
=
spam
.
eggs
y
=
spam
.
ham
z
=
spam
.
foo
...
...
tests/run/filenames.pyx
View file @
c8b85056
...
...
@@ -8,4 +8,3 @@ ftang
include
"filenames.pxi"
foo
=
42
tests/run/flatin.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test_in('ABC')
1
>>> test_in('abc')
2
>>> test_in('X')
3
>>> test_in('XYZ')
4
>>> test_in('ABCXYZ')
5
>>> test_in('')
5
>>> test_not_in('abc')
1
>>> test_not_in('CDE')
2
>>> test_not_in('CDEF')
3
>>> test_not_in('BCD')
4
"""
def
test_in
(
s
):
"""
>>> test_in('ABC')
1
>>> test_in('abc')
2
>>> test_in('X')
3
>>> test_in('XYZ')
4
>>> test_in('ABCXYZ')
5
>>> test_in('')
5
"""
if
s
in
(
u'ABC'
,
u'BCD'
):
return
1
elif
s
.
upper
()
in
(
u'ABC'
,
u'BCD'
):
...
...
@@ -35,6 +25,16 @@ def test_in(s):
return
5
def
test_not_in
(
s
):
"""
>>> test_not_in('abc')
1
>>> test_not_in('CDE')
2
>>> test_not_in('CDEF')
3
>>> test_not_in('BCD')
4
"""
if
s
not
in
(
u'ABC'
,
u'BCD'
,
u'CDE'
,
u'CDEF'
):
return
1
elif
s
.
upper
()
not
in
(
u'ABC'
,
u'BCD'
,
u'CDEF'
):
...
...
tests/run/float_floor_division_T260.pyx
View file @
c8b85056
__doc__
=
u"""
def
floor_div_float
(
double
a
,
double
b
):
"""
>>> floor_div_float(2, 1.5)
1.0
>>> floor_div_float(2, -1.5)
...
...
@@ -7,7 +8,5 @@ __doc__ = u"""
-2.0
>>> floor_div_float(1e10, 1e-10)
1e+20
"""
def
floor_div_float
(
double
a
,
double
b
):
"""
return
a
//
b
tests/run/fmod.pyx
View file @
c8b85056
__doc__
=
u"""
def
fmod
(
double
a
,
double
b
):
"""
>>> fmod(7, 1.25)
0.75
"""
def
fmod
(
double
a
,
double
b
):
"""
return
a
%
b
tests/run/for_from_float_T254.pyx
View file @
c8b85056
__doc__
=
u"""
def
double_target
(
a
,
b
):
"""
>>> double_target(0, 4)
at 0.0
at 1.0
at 2.0
at 3.0
4.0
>>> double_step(0, 2, .5)
at 0.0
at 0.5
at 1.0
at 1.5
2.0
>>> double_step_typed(0, 2, .5)
at 0.0
at 0.5
at 1.0
at 1.5
2.0
>>> double_step_py_target(0, 2, .5)
at 0.0
at 0.5
at 1.0
at 1.5
2.0
>>> int_step_py_target(0, 2, 1)
at 0
at 1
2
"""
def
double_target
(
a
,
b
):
"""
cdef
double
x
for
x
from
a
<=
x
<
b
:
print
u"at"
,
x
return
x
def
double_step
(
a
,
b
,
dx
):
"""
>>> double_step(0, 2, .5)
at 0.0
at 0.5
at 1.0
at 1.5
2.0
"""
cdef
double
x
for
x
from
a
<=
x
<
b
by
dx
:
print
u"at"
,
x
return
x
def
double_step_typed
(
a
,
b
,
double
dx
):
"""
>>> double_step_typed(0, 2, .5)
at 0.0
at 0.5
at 1.0
at 1.5
2.0
"""
cdef
double
x
for
x
from
a
<=
x
<
b
by
dx
:
print
u"at"
,
x
return
x
def
double_step_py_target
(
a
,
b
,
double
dx
):
"""
>>> double_step_py_target(0, 2, .5)
at 0.0
at 0.5
at 1.0
at 1.5
2.0
"""
cdef
object
x
for
x
from
a
<=
x
<
b
by
dx
:
print
u"at"
,
x
return
x
def
int_step_py_target
(
a
,
b
,
int
dx
):
"""
>>> int_step_py_target(0, 2, 1)
at 0
at 1
2
"""
cdef
object
x
for
x
from
a
<=
x
<
b
by
dx
:
print
u"at"
,
x
...
...
tests/run/for_in_range_T372.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test_modify()
0
1
2
3
4
<BLANKLINE>
(4, 0)
>>> test_fix()
0
1
2
3
4
<BLANKLINE>
4
>>> test_break()
0
1
2
<BLANKLINE>
(2, 0)
>>> test_return()
0
1
2
(2, 0)
"""
cimport
cython
@
cython
.
test_assert_path_exists
(
"//ForFromStatNode"
)
@
cython
.
test_fail_if_path_exists
(
"//ForInStatNode"
)
def
test_modify
():
"""
>>> test_modify()
0
1
2
3
4
<BLANKLINE>
(4, 0)
"""
cdef
int
i
,
n
=
5
for
i
in
range
(
n
):
print
i
...
...
@@ -43,6 +23,16 @@ def test_modify():
@
cython
.
test_assert_path_exists
(
"//ForFromStatNode"
)
@
cython
.
test_fail_if_path_exists
(
"//ForInStatNode"
)
def
test_fix
():
"""
>>> test_fix()
0
1
2
3
4
<BLANKLINE>
4
"""
cdef
int
i
for
i
in
range
(
5
):
print
i
...
...
@@ -52,6 +42,14 @@ def test_fix():
@
cython
.
test_assert_path_exists
(
"//ForFromStatNode"
)
@
cython
.
test_fail_if_path_exists
(
"//ForInStatNode"
)
def
test_break
():
"""
>>> test_break()
0
1
2
<BLANKLINE>
(2, 0)
"""
cdef
int
i
,
n
=
5
for
i
in
range
(
n
):
print
i
...
...
@@ -66,6 +64,13 @@ def test_break():
@
cython
.
test_assert_path_exists
(
"//ForFromStatNode"
)
@
cython
.
test_fail_if_path_exists
(
"//ForInStatNode"
)
def
test_return
():
"""
>>> test_return()
0
1
2
(2, 0)
"""
cdef
int
i
,
n
=
5
for
i
in
range
(
n
):
print
i
...
...
tests/run/forfrom.pyx
View file @
c8b85056
__doc__
=
u"""
>>> for_else()
30
>>> print( u'*'.join(int_comp()) )
00*01*02
"""
import
sys
if
sys
.
version_info
[
0
]
>=
3
:
__doc__
=
__doc__
.
replace
(
u" u'"
,
u" '"
).
replace
(
u' u"'
,
u' "'
)
def
for_else
():
"""
>>> for_else()
30
>>> print( int_comp() )
00*01*02
"""
cdef
int
i
,
j
=
0
,
k
=
2
for
i
from
0
<=
i
<
10
:
j
+=
k
...
...
@@ -19,5 +15,5 @@ def for_else():
def
int_comp
():
cdef
int
i
return
tuple
([
u"%02d"
%
i
for
i
from
0
<=
i
<
3
]
)
return
u'*'
.
join
(
tuple
([
u"%02d"
%
i
for
i
from
0
<=
i
<
3
])
)
tests/run/funcexceptreraise.pyx
View file @
c8b85056
import
sys
def
reraise
(
f
,
exc
):
...
...
tests/run/hash_T326.pyx
View file @
c8b85056
...
...
@@ -11,8 +11,6 @@ __doc__ = u"""
...
TypeError: That's kind of a round number...
>>> __hash__(-1)
-1
"""
cdef
class
A
:
...
...
@@ -26,4 +24,8 @@ cdef class A:
return
self
.
a
cpdef
long
__hash__
(
long
x
):
"""
>>> __hash__(-1)
-1
"""
return
x
tests/run/if.pyx
View file @
c8b85056
__doc__
=
u"""
def
f
(
a
,
b
):
"""
>>> f(0,0)
0
>>> f(1,2)
2
>>> f(1,-1)
1
>>> g(1,2)
1
>>> g(0,2)
2
>>> g(0,0)
0
>>> h(1,2)
1
>>> h(0,2)
2
>>> h(0,0)
3
>>> i(1,2)
1
>>> i(2,2)
2
>>> i(2,1)
0
"""
def
f
(
a
,
b
):
"""
x
=
0
if
a
:
x
=
1
...
...
@@ -37,6 +15,14 @@ def f(a, b):
return
x
def
g
(
a
,
b
):
"""
>>> g(1,2)
1
>>> g(0,2)
2
>>> g(0,0)
0
"""
x
=
0
if
a
:
x
=
1
...
...
@@ -45,6 +31,14 @@ def g(a, b):
return
x
def
h
(
a
,
b
):
"""
>>> h(1,2)
1
>>> h(0,2)
2
>>> h(0,0)
3
"""
x
=
0
if
a
:
x
=
1
...
...
@@ -60,6 +54,14 @@ except ImportError:
import
builtins
def
i
(
a
,
b
):
"""
>>> i(1,2)
1
>>> i(2,2)
2
>>> i(2,1)
0
"""
x
=
0
if
builtins
.
str
(
a
).
upper
()
==
u"1"
:
x
=
1
...
...
tests/run/importfrom.pyx
View file @
c8b85056
__doc__
=
u"""
>>> from distutils import cmd, core, version
>>> import1() == (cmd, core, version)
True
>>> import2() == (cmd, core, version)
True
>>> import3() == (cmd, core, version)
True
>>> import4() == (cmd, core, version)
True
>>> typed_imports()
True
True
an integer is required
Expected type, got int
"""
from
distutils
import
cmd
,
core
,
version
def
import1
():
"""
>>> import1() == (cmd, core, version)
True
"""
from
distutils
import
(
cmd
,
...
...
@@ -25,6 +14,10 @@ core, version)
def
import2
():
"""
>>> import2() == (cmd, core, version)
True
"""
from
distutils
import
(
cmd
,
core
,
...
...
@@ -36,16 +29,31 @@ core,
def
import3
():
"""
>>> import3() == (cmd, core, version)
True
"""
from
distutils
import
(
cmd
,
core
,
version
)
return
cmd
,
core
,
version
def
import4
():
"""
>>> import4() == (cmd, core, version)
True
"""
from
distutils
import
cmd
,
core
,
version
return
cmd
,
core
,
version
def
typed_imports
():
"""
>>> typed_imports()
True
True
an integer is required
Expected type, got int
"""
import
sys
import
types
...
...
@@ -66,4 +74,3 @@ def typed_imports():
from
sys
import
maxunicode
as
t
except
TypeError
,
e
:
print
e
tests/run/index.pyx
View file @
c8b85056
__doc__
=
u"""
>>> index_tuple((1,1,2,3,5), 0)
1
>>> index_tuple((1,1,2,3,5), 3)
3
>>> index_tuple((1,1,2,3,5), -1)
5
>>> index_tuple((1,1,2,3,5), 100)
Traceback (most recent call last):
...
IndexError: tuple index out of range
>>> index_list([2,3,5,7,11,13,17,19], 0)
2
>>> index_list([2,3,5,7,11,13,17,19], 5)
13
>>> index_list([2,3,5,7,11,13,17,19], -1)
19
>>> index_list([2,3,5,7,11,13,17,19], 100)
Traceback (most recent call last):
...
IndexError: list index out of range
>>> index_object([2,3,5,7,11,13,17,19], 1)
3
>>> index_object([2,3,5,7,11,13,17,19], -1)
19
>>> index_object((1,1,2,3,5), 2)
2
>>> index_object((1,1,2,3,5), -2)
3
>>> index_object("abcdef...z", 0)
'a'
>>> index_object("abcdef...z", -1)
'z'
>>> index_object("abcdef...z", 100)
Traceback (most recent call last):
...
IndexError: string index out of range
>>> index_object(100, 100)
Traceback (most recent call last):
...
TypeError: 'int' object is unsubscriptable
>>> test_unsigned_long()
>>> test_unsigned_short()
>>> test_long_long()
>>> index_object(100, 100)
Traceback (most recent call last):
...
TypeError: 'int' object is unsubscriptable
"""
import
sys
...
...
@@ -54,19 +11,65 @@ if sys.version_info[0] >= 3:
elif
sys
.
version_info
<
(
2
,
5
):
__doc__
=
__doc__
.
replace
(
u"'int' object is unsubscriptable"
,
u'unsubscriptable object'
)
def
index_tuple
(
tuple
t
,
int
i
):
"""
>>> index_tuple((1,1,2,3,5), 0)
1
>>> index_tuple((1,1,2,3,5), 3)
3
>>> index_tuple((1,1,2,3,5), -1)
5
>>> index_tuple((1,1,2,3,5), 100)
Traceback (most recent call last):
...
IndexError: tuple index out of range
"""
return
t
[
i
]
def
index_list
(
list
L
,
int
i
):
"""
>>> index_list([2,3,5,7,11,13,17,19], 0)
2
>>> index_list([2,3,5,7,11,13,17,19], 5)
13
>>> index_list([2,3,5,7,11,13,17,19], -1)
19
>>> index_list([2,3,5,7,11,13,17,19], 100)
Traceback (most recent call last):
...
IndexError: list index out of range
"""
return
L
[
i
]
def
index_object
(
object
o
,
int
i
):
"""
>>> index_object([2,3,5,7,11,13,17,19], 1)
3
>>> index_object([2,3,5,7,11,13,17,19], -1)
19
>>> index_object((1,1,2,3,5), 2)
2
>>> index_object((1,1,2,3,5), -2)
3
>>> index_object("abcdef...z", 0)
'a'
>>> index_object("abcdef...z", -1)
'z'
>>> index_object("abcdef...z", 100)
Traceback (most recent call last):
...
IndexError: string index out of range
"""
return
o
[
i
]
# These make sure that our fast indexing works with large and unsigned types.
def
test_unsigned_long
():
"""
>>> test_unsigned_long()
"""
cdef
int
i
cdef
unsigned
long
ix
cdef
D
=
{}
...
...
@@ -80,6 +83,9 @@ def test_unsigned_long():
assert
len
(
D
)
==
0
def
test_unsigned_short
():
"""
>>> test_unsigned_short()
"""
cdef
int
i
cdef
unsigned
short
ix
cdef
D
=
{}
...
...
@@ -93,6 +99,9 @@ def test_unsigned_short():
assert
len
(
D
)
==
0
def
test_long_long
():
"""
>>> test_long_long()
"""
cdef
int
i
cdef
long
long
ix
cdef
D
=
{}
...
...
tests/run/inline.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test(3)
3
"""
def
test
(
x
):
"""
>>> test(3)
3
"""
return
retinput
(
x
)
cdef
inline
int
retinput
(
int
x
):
o
=
x
return
o
tests/run/inop.pyx
View file @
c8b85056
__doc__
=
u"""
def
f
(
a
,
b
):
"""
>>> f(1,[1,2,3])
True
>>> f(5,[1,2,3])
False
>>> f(2,(1,2,3))
True
"""
result
=
a
in
b
return
result
def
g
(
a
,
b
):
"""
>>> g(1,[1,2,3])
1
>>> g(5,[1,2,3])
0
>>> g(2,(1,2,3))
1
"""
cdef
int
result
result
=
a
in
b
return
result
def
h
(
b
):
"""
>>> h([1,2,3,4])
True
>>> h([1,3,4])
False
"""
result
=
2
in
b
return
result
def
j
(
b
):
"""
>>> j([1,2,3,4])
1
>>> j([1,3,4])
0
"""
cdef
int
result
result
=
2
in
b
return
result
def
k
(
a
):
"""
>>> k(1)
1
>>> k(5)
0
"""
cdef
int
result
=
a
in
[
1
,
2
,
3
,
4
]
return
result
def
m
(
int
a
):
"""
>>> m(2)
1
>>> m(5)
0
"""
cdef
int
result
=
a
in
[
1
,
2
,
3
,
4
]
return
result
def
n
(
a
):
"""
>>> n('d *')
1
>>> n('xxx')
0
"""
cdef
int
result
=
a
.
lower
()
in
[
u'a *'
,
u'b *'
,
u'c *'
,
u'd *'
]
return
result
def
p
(
a
):
"""
>>> p(1)
0
>>> p('a')
1
"""
cdef
dict
d
=
{
u'a'
:
1
,
u'b'
:
2
}
cdef
int
result
=
a
in
d
return
result
def
q
(
a
):
"""
>>> q(1)
Traceback (most recent call last):
TypeError: 'NoneType' object is not iterable
>>> l = [1,2,3,4]
>>> l2 = [l[1:],l[:-1],l]
>>> 2 in l in l2
True
>>> r(2)
1
>>> s(2)
1
"""
def
f
(
a
,
b
):
result
=
a
in
b
return
result
def
g
(
a
,
b
):
cdef
int
result
result
=
a
in
b
return
result
def
h
(
b
):
result
=
2
in
b
return
result
def
j
(
b
):
cdef
int
result
result
=
2
in
b
return
result
def
k
(
a
):
cdef
int
result
=
a
in
[
1
,
2
,
3
,
4
]
return
result
def
m
(
int
a
):
cdef
int
result
=
a
in
[
1
,
2
,
3
,
4
]
return
result
def
n
(
a
):
cdef
int
result
=
a
.
lower
()
in
[
u'a *'
,
u'b *'
,
u'c *'
,
u'd *'
]
return
result
def
p
(
a
):
cdef
dict
d
=
{
u'a'
:
1
,
u'b'
:
2
}
cdef
int
result
=
a
in
d
return
result
def
q
(
a
):
"""
cdef
dict
d
=
None
cdef
int
result
=
a
in
d
# should fail with a TypeError
return
result
def
r
(
a
):
"""
>>> r(2)
1
"""
l
=
[
1
,
2
,
3
,
4
]
l2
=
[
l
[
1
:],
l
[:
-
1
],
l
]
cdef
int
result
=
a
in
l
in
l2
return
result
def
s
(
a
):
"""
>>> s(2)
1
"""
cdef
int
result
=
a
in
[
1
,
2
,
3
,
4
]
in
[[
1
,
2
,
3
],[
2
,
3
,
4
],[
1
,
2
,
3
,
4
]]
return
result
tests/run/inplace.pyx
View file @
c8b85056
...
...
@@ -2,27 +2,6 @@ __doc__ = u"""
>>> str(f(5, 7))
'29509034655744'
>>> g(13, 4)
32
>>> h(56, 7)
105.0
>>> arrays()
19
>>> attributes()
26 26 26
>>> smoketest()
10
>>> test_side_effects()
side effect 1
c side effect 2
side effect 3
c side effect 4
([0, 11, 102, 3, 4], [0, 1, 2, 13, 104])
"""
def
f
(
a
,
b
):
...
...
@@ -32,12 +11,20 @@ def f(a,b):
return
a
def
g
(
int
a
,
int
b
):
"""
>>> g(13, 4)
32
"""
a
-=
b
a
/=
b
a
<<=
b
return
a
def
h
(
double
a
,
double
b
):
"""
>>> h(56, 7)
105.0
"""
a
/=
b
a
+=
b
a
*=
b
...
...
@@ -46,6 +33,10 @@ def h(double a, double b):
cimport
stdlib
def
arrays
():
"""
>>> arrays()
19
"""
cdef
char
*
buf
=
<
char
*>
stdlib
.
malloc
(
10
)
cdef
int
i
=
2
cdef
object
j
=
2
...
...
@@ -68,6 +59,10 @@ class B:
attr
=
3
def
attributes
():
"""
>>> attributes()
26 26 26
"""
cdef
A
a
=
A
()
b
=
B
()
a
.
attr
+=
10
...
...
@@ -82,6 +77,10 @@ def get_2(): return 2
cdef
int
identity
(
int
value
):
return
value
def
smoketest
():
"""
>>> smoketest()
10
"""
cdef
char
*
buf
=
<
char
*>
stdlib
.
malloc
(
10
)
cdef
A
a
=
A
()
a
.
buf
=
buf
...
...
@@ -100,6 +99,14 @@ cdef int c_side_effect(int x):
return
x
def
test_side_effects
():
"""
>>> test_side_effects()
side effect 1
c side effect 2
side effect 3
c side effect 4
([0, 11, 102, 3, 4], [0, 1, 2, 13, 104])
"""
a
=
list
(
range
(
5
))
a
[
side_effect
(
1
)]
+=
10
a
[
c_side_effect
(
2
)]
+=
100
...
...
tests/run/int_float_builtins_as_casts_T400.pyx
0 → 100644
View file @
c8b85056
cimport
cython
@
cython
.
test_assert_path_exists
(
"//SingleAssignmentNode/CastNode"
)
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode"
)
def
double_to_short_int
(
double
x
):
"""
>>> double_to_short_int(4.1)
4
>>> double_to_short_int(4)
4
"""
cdef
short
r
=
int
(
x
)
return
r
@
cython
.
test_assert_path_exists
(
"//SingleAssignmentNode/CastNode"
)
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode"
)
def
double_to_pyssizet_int
(
double
x
):
"""
>>> double_to_pyssizet_int(4.1)
4
>>> double_to_pyssizet_int(4)
4
"""
cdef
Py_ssize_t
r
=
int
(
x
)
return
r
@
cython
.
test_assert_path_exists
(
"//SingleAssignmentNode/CastNode"
)
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode"
)
def
int_to_pyssizet_int
(
int
x
):
"""
>>> int_to_pyssizet_int(4.1)
4
>>> int_to_pyssizet_int(4)
4
"""
cdef
Py_ssize_t
r
=
int
(
x
)
return
r
@
cython
.
test_assert_path_exists
(
"//SingleAssignmentNode/CastNode"
)
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode"
)
def
double_to_pyssizet_float
(
double
x
):
"""
>>> double_to_pyssizet_float(4.1)
4
>>> double_to_pyssizet_float(4)
4
"""
cdef
Py_ssize_t
r
=
float
(
x
)
return
r
@
cython
.
test_assert_path_exists
(
"//SingleAssignmentNode/CastNode"
)
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode"
)
def
int_to_short_int
(
int
x
):
"""
>>> int_to_short_int(4)
4
"""
cdef
short
r
=
int
(
x
)
return
r
@
cython
.
test_assert_path_exists
(
"//SingleAssignmentNode/CastNode"
)
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode"
)
def
short_to_float_float
(
short
x
):
"""
>>> short_to_float_float(4)
4.0
"""
cdef
float
r
=
float
(
x
)
return
r
@
cython
.
test_assert_path_exists
(
"//SingleAssignmentNode/CastNode"
)
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode"
)
def
short_to_double_float
(
short
x
):
"""
>>> short_to_double_float(4)
4.0
"""
cdef
double
r
=
float
(
x
)
return
r
@
cython
.
test_assert_path_exists
(
"//SingleAssignmentNode/CastNode"
)
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode"
)
def
short_to_double_int
(
short
x
):
"""
>>> short_to_double_int(4)
4.0
"""
cdef
double
r
=
int
(
x
)
return
r
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode"
,
"//SingleAssignmentNode/CastNode"
)
def
float_to_float_float
(
float
x
):
"""
>>> 4.05 < float_to_float_float(4.1) < 4.15
True
>>> float_to_float_float(4)
4.0
"""
cdef
float
r
=
float
(
x
)
return
r
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode"
,
"//SingleAssignmentNode/CastNode"
)
def
double_to_double_float
(
double
x
):
"""
>>> 4.05 < double_to_double_float(4.1) < 4.15
True
>>> double_to_double_float(4)
4.0
"""
cdef
double
r
=
float
(
x
)
return
r
# tests that cannot be optimised
@
cython
.
test_fail_if_path_exists
(
"//SingleAssignmentNode/CastNode"
)
@
cython
.
test_assert_path_exists
(
"//SimpleCallNode"
)
def
double_to_py_int
(
double
x
):
"""
>>> double_to_py_int(4.1)
4
>>> double_to_py_int(4)
4
"""
return
int
(
x
)
@
cython
.
test_fail_if_path_exists
(
"//SingleAssignmentNode/CastNode"
)
@
cython
.
test_assert_path_exists
(
"//SimpleCallNode"
)
def
double_to_double_int
(
double
x
):
"""
>>> double_to_double_int(4.1)
4.0
>>> double_to_double_int(4)
4.0
"""
cdef
double
r
=
int
(
x
)
return
r
tests/run/int_literals.pyx
View file @
c8b85056
__doc__
=
u"""
>>> c_longs()
(1, 1L, -1L, 18446744073709551615L)
>>> py_longs()
(1, 1L, 100000000000000000000000000000000L, -100000000000000000000000000000000L)
>>> c_longs()
(1, 1L, -1L, 18446744073709551615L)
>>> py_longs()
(1, 1L, 100000000000000000000000000000000L, -100000000000000000000000000000000L)
"""
import
sys
if
sys
.
version_info
[
0
]
>=
3
:
__doc__
=
__doc__
.
replace
(
u'L'
,
u''
)
import
sys
if
sys
.
version_info
[
0
]
>=
3
:
__doc__
=
__doc__
.
replace
(
u'L'
,
u''
)
...
...
tests/run/ishimoto2.pyx
View file @
c8b85056
__doc__
=
u"""
class
C
:
"""
>>> C().xxx(5)
5
>>> C().xxx()
u
'a b'
'a b'
>>> C().xxx(42)
42
>>> C().xxx()
u'a b'
"""
import
sys
if
sys
.
version_info
[
0
]
>=
3
:
__doc__
=
__doc__
.
replace
(
u" u'"
,
u" '"
)
class
C
:
def
xxx
(
self
,
p
=
u"a b"
):
'a b'
"""
def
xxx
(
self
,
p
=
"a b"
):
return
p
tests/run/isinstance.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test_all()
True
"""
cdef
class
A
:
pass
...
...
@@ -9,6 +5,10 @@ import sys
IS_PY3
=
sys
.
version_info
[
0
]
>=
3
def
test_all
():
"""
>>> test_all()
True
"""
if
IS_PY3
:
new_type
=
type
(
u'a'
,(),{})
else
:
...
...
tests/run/isnonebool.pyx
View file @
c8b85056
__doc__
=
u"""
def
test_and
(
a
,
b
):
"""
>>> test_and(None, None)
True
>>> test_and(None, 1)
False
>>> test_and(1, None)
False
"""
return
a
is
None
and
b
is
None
def
test_more
(
a
,
b
):
"""
>>> test_more(None, None)
True
>>> test_more(None, 1)
...
...
@@ -14,7 +19,11 @@ __doc__ = u"""
False
>>> test_more(None, 0)
False
"""
return
a
is
None
and
(
b
is
None
or
b
==
1
)
def
test_more_c
(
a
,
b
):
"""
>>> test_more_c(None, None)
True
>>> test_more_c(None, 1)
...
...
@@ -23,13 +32,5 @@ __doc__ = u"""
False
>>> test_more_c(None, 0)
False
"""
def
test_and
(
a
,
b
):
return
a
is
None
and
b
is
None
def
test_more
(
a
,
b
):
return
a
is
None
and
(
b
is
None
or
b
==
1
)
def
test_more_c
(
a
,
b
):
"""
return
(
a
is
None
or
1
==
2
)
and
(
b
is
None
or
b
==
1
)
tests/run/iteratorexception.pyx
View file @
c8b85056
__doc__
=
u"""
>>> f()
"""
class
IteratorAndIterateable
:
def
next
(
self
):
raise
ValueError
...
...
@@ -11,6 +7,9 @@ class IteratorAndIterateable:
return
self
def
f
():
"""
>>> f()
"""
try
:
for
x
in
IteratorAndIterateable
():
pass
...
...
tests/run/iterdict.pyx
View file @
c8b85056
__doc__
=
u"""
>>> dict_size = 4
>>> d = dict(zip(range(10,dict_size+10), range(dict_size)))
>>> items(d)
[(10, 0), (11, 1), (12, 2), (13, 3)]
>>> iteritems(d)
[(10, 0), (11, 1), (12, 2), (13, 3)]
>>> iteritems_int(d)
[(10, 0), (11, 1), (12, 2), (13, 3)]
>>> iteritems_tuple(d)
[(10, 0), (11, 1), (12, 2), (13, 3)]
>>> iterkeys(d)
[10, 11, 12, 13]
>>> iterkeys_int(d)
[10, 11, 12, 13]
>>> iterdict(d)
[10, 11, 12, 13]
>>> iterdict_reassign(d)
[10, 11, 12, 13]
>>> iterdict_int(d)
[10, 11, 12, 13]
>>> itervalues(d)
[0, 1, 2, 3]
>>> itervalues_int(d)
[0, 1, 2, 3]
"""
dict_size
=
4
d
=
dict
(
zip
(
range
(
10
,
dict_size
+
10
),
range
(
dict_size
)))
def
items
(
dict
d
):
"""
>>> items(d)
[(10, 0), (11, 1), (12, 2), (13, 3)]
"""
l
=
[]
for
k
,
v
in
d
.
items
():
l
.
append
((
k
,
v
))
...
...
@@ -34,6 +13,10 @@ def items(dict d):
return
l
def
iteritems
(
dict
d
):
"""
>>> iteritems(d)
[(10, 0), (11, 1), (12, 2), (13, 3)]
"""
l
=
[]
for
k
,
v
in
d
.
iteritems
():
l
.
append
((
k
,
v
))
...
...
@@ -41,6 +24,10 @@ def iteritems(dict d):
return
l
def
iteritems_int
(
dict
d
):
"""
>>> iteritems_int(d)
[(10, 0), (11, 1), (12, 2), (13, 3)]
"""
cdef
int
k
,
v
l
=
[]
for
k
,
v
in
d
.
iteritems
():
...
...
@@ -49,6 +36,10 @@ def iteritems_int(dict d):
return
l
def
iteritems_tuple
(
dict
d
):
"""
>>> iteritems_tuple(d)
[(10, 0), (11, 1), (12, 2), (13, 3)]
"""
l
=
[]
for
t
in
d
.
iteritems
():
l
.
append
(
t
)
...
...
@@ -61,6 +52,10 @@ def iteritems_listcomp(dict d):
return
l
def
iterkeys
(
dict
d
):
"""
>>> iterkeys(d)
[10, 11, 12, 13]
"""
l
=
[]
for
k
in
d
.
iterkeys
():
l
.
append
(
k
)
...
...
@@ -68,6 +63,10 @@ def iterkeys(dict d):
return
l
def
iterkeys_int
(
dict
d
):
"""
>>> iterkeys_int(d)
[10, 11, 12, 13]
"""
cdef
int
k
l
=
[]
for
k
in
d
.
iterkeys
():
...
...
@@ -76,6 +75,10 @@ def iterkeys_int(dict d):
return
l
def
iterdict
(
dict
d
):
"""
>>> iterdict(d)
[10, 11, 12, 13]
"""
l
=
[]
for
k
in
d
:
l
.
append
(
k
)
...
...
@@ -83,6 +86,10 @@ def iterdict(dict d):
return
l
def
iterdict_int
(
dict
d
):
"""
>>> iterdict_int(d)
[10, 11, 12, 13]
"""
cdef
int
k
l
=
[]
for
k
in
d
:
...
...
@@ -91,6 +98,10 @@ def iterdict_int(dict d):
return
l
def
iterdict_reassign
(
dict
d
):
"""
>>> iterdict_reassign(d)
[10, 11, 12, 13]
"""
cdef
dict
d_new
=
{}
l
=
[]
for
k
in
d
:
...
...
@@ -105,6 +116,10 @@ def iterdict_listcomp(dict d):
return
l
def
itervalues
(
dict
d
):
"""
>>> itervalues(d)
[0, 1, 2, 3]
"""
l
=
[]
for
v
in
d
.
itervalues
():
l
.
append
(
v
)
...
...
@@ -112,6 +127,10 @@ def itervalues(dict d):
return
l
def
itervalues_int
(
dict
d
):
"""
>>> itervalues_int(d)
[0, 1, 2, 3]
"""
cdef
int
v
l
=
[]
for
v
in
d
.
itervalues
():
...
...
tests/run/king1.pyx
View file @
c8b85056
__doc__
=
u"""
>>> uf()
It works!
>>> bf()
It works!
"""
DEF
USTUFF
=
u"Spam"
def
uf
():
"""
>>> uf()
It works!
"""
IF
USTUFF
==
u"Spam"
:
print
"It works!"
ELSE
:
...
...
@@ -16,6 +13,10 @@ def uf():
DEF
BSTUFF
=
b"Spam"
def
bf
():
"""
>>> bf()
It works!
"""
IF
BSTUFF
==
b"Spam"
:
print
"It works!"
ELSE
:
...
...
tests/run/kwargproblems.pyx
View file @
c8b85056
__doc__
=
u"""
import
sys
def
test
(
**
kw
):
"""
>>> d = {1 : 2}
>>> test(**d)
Traceback (most recent call last):
TypeError: test() keywords must be strings
>>> d
{1: 2}
>>> d = {}
>>> test(**d)
{'arg': 3}
>>> d
{}
>>> d = {'arg' : 2} # this should be u'arg', but Py2 can't handle it...
>>> test(**d)
{'arg': 3}
>>> d
{'arg': 2}
"""
import
sys
def
test
(
**
kw
):
"""
if
sys
.
version_info
[
0
]
>=
3
:
kw
[
u'arg'
]
=
3
else
:
...
...
tests/run/kwonlyargs.pyx
View file @
c8b85056
__doc__
=
u"""
def
b
(
a
,
b
,
c
):
"""
>>> b(1,2,3)
>>> b(1,2,3,4)
Traceback (most recent call last):
TypeError: b() takes exactly 3 positional arguments (4 given)
"""
a
,
b
,
c
=
b
,
c
,
a
def
c
(
a
,
b
,
c
=
1
):
"""
>>> c(1,2)
>>> c(1,2,3)
>>> c(1,2,3,4)
Traceback (most recent call last):
TypeError: c() takes at most 3 positional arguments (4 given)
"""
a
,
b
,
c
=
b
,
c
,
a
def
d
(
a
,
b
,
*
,
c
=
88
):
"""
>>> d(1,2)
>>> d(1,2, c=1)
>>> d(1,2,3)
Traceback (most recent call last):
TypeError: d() takes exactly 2 positional arguments (3 given)
>>> d(1,2, d=1)
Traceback (most recent call last):
TypeError: d() got an unexpected keyword argument 'd'
"""
a
,
b
,
c
=
b
,
c
,
a
def
e
(
a
,
b
,
c
=
88
,
**
kwds
):
"""
>>> e(1,2)
>>> e(1,2, c=1)
>>> e(1,2, d=1)
...
...
@@ -28,10 +40,13 @@ __doc__ = u"""
>>> e(1,2,3,4)
Traceback (most recent call last):
TypeError: e() takes at most 3 positional arguments (4 given)
"""
a
,
b
,
c
=
b
,
c
,
a
def
f
(
a
,
b
,
*
,
c
,
d
=
42
):
"""
>>> f(1,2, c=1)
>>> f(1,2, c=1, d=2)
>>> f(1,2,3)
Traceback (most recent call last):
TypeError: f() takes exactly 2 positional arguments (3 given)
...
...
@@ -41,11 +56,14 @@ __doc__ = u"""
>>> f(1,2, c=1, e=2)
Traceback (most recent call last):
TypeError: f() got an unexpected keyword argument 'e'
"""
a
,
b
,
c
,
d
=
b
,
c
,
d
,
a
def
g
(
a
,
b
,
*
,
c
,
d
=
42
,
e
=
17
,
f
,
**
kwds
):
"""
>>> g(1,2, c=1, f=2)
>>> g(1,2, c=1, e=0, f=2, d=11)
>>> g(1,2, c=1, f=2, e=0, x=25)
>>> g(1,2,3)
Traceback (most recent call last):
TypeError: g() takes exactly 2 positional arguments (3 given)
...
...
@@ -55,81 +73,64 @@ __doc__ = u"""
>>> g(1,2, c=1)
Traceback (most recent call last):
TypeError: g() needs keyword-only argument f
"""
a
,
b
,
c
,
d
,
e
,
f
=
b
,
c
,
d
,
e
,
f
,
a
def
h
(
a
,
b
,
*
args
,
c
,
d
=
42
,
e
=
17
,
f
,
**
kwds
):
"""
>>> h(1,2, c=1, f=2)
>>> h(1,2, c=1, f=2, e=3)
>>> h(1,2,3,4,5,6, c=1, f=2)
>>> h(1,2,3,4,5,6, c=1, f=2, e=3, x=25, y=11)
>>> h(1,2,3)
Traceback (most recent call last):
TypeError: h() needs keyword-only argument c
>>> h(1,2, d=1)
Traceback (most recent call last):
TypeError: h() needs keyword-only argument c
"""
a
,
b
,
c
,
d
,
e
,
f
=
b
,
c
,
d
,
e
,
f
,
a
def
k
(
a
,
b
,
c
=
1
,
*
args
,
d
=
42
,
e
=
17
,
f
,
**
kwds
):
"""
>>> k(1,2, c=1, f=2)
>>> k(1,2, c=1, f=2, e=3)
>>> k(1,2,3,4,5,6, d=1, f=2)
>>> k(1,2,3,4,5,6, d=1, f=2, e=3, x=25, y=11)
>>> k(1,2,3)
Traceback (most recent call last):
TypeError: k() needs keyword-only argument f
>>> k(1,2, d=1)
Traceback (most recent call last):
TypeError: k() needs keyword-only argument f
"""
a
,
b
,
c
,
d
,
e
,
f
=
b
,
c
,
d
,
e
,
f
,
a
def
l
(
*
,
a
,
b
,
c
=
88
):
"""
>>> l(a=1, b=2)
>>> l(a=1, b=2, c=1)
>>> l(1,2,3)
Traceback (most recent call last):
TypeError: l() takes exactly 0 positional arguments (3 given)
>>> l(1,2, d=1)
Traceback (most recent call last):
TypeError: l() takes exactly 0 positional arguments (2 given)
>>> m(1, b=2)
>>> m(a=1, b=2)
>>> m(a=1, b=2, c=1)
>>> l(1,2,3)
Traceback (most recent call last):
TypeError: l() takes exactly 0 positional arguments (3 given)
>>> l(1,2, d=1)
Traceback (most recent call last):
TypeError: l() takes exactly 0 positional arguments (2 given)
"""
def
b
(
a
,
b
,
c
):
a
,
b
,
c
=
b
,
c
,
a
def
c
(
a
,
b
,
c
=
1
):
a
,
b
,
c
=
b
,
c
,
a
def
d
(
a
,
b
,
*
,
c
=
88
):
a
,
b
,
c
=
b
,
c
,
a
def
e
(
a
,
b
,
c
=
88
,
**
kwds
):
a
,
b
,
c
=
b
,
c
,
a
def
f
(
a
,
b
,
*
,
c
,
d
=
42
):
a
,
b
,
c
,
d
=
b
,
c
,
d
,
a
def
g
(
a
,
b
,
*
,
c
,
d
=
42
,
e
=
17
,
f
,
**
kwds
):
a
,
b
,
c
,
d
,
e
,
f
=
b
,
c
,
d
,
e
,
f
,
a
def
h
(
a
,
b
,
*
args
,
c
,
d
=
42
,
e
=
17
,
f
,
**
kwds
):
a
,
b
,
c
,
d
,
e
,
f
=
b
,
c
,
d
,
e
,
f
,
a
def
k
(
a
,
b
,
c
=
1
,
*
args
,
d
=
42
,
e
=
17
,
f
,
**
kwds
):
a
,
b
,
c
,
d
,
e
,
f
=
b
,
c
,
d
,
e
,
f
,
a
def
l
(
*
,
a
,
b
,
c
=
88
):
"""
a
,
b
,
c
=
b
,
c
,
a
def
m
(
a
,
*
,
b
,
c
=
88
):
"""
>>> m(1, b=2)
>>> m(a=1, b=2)
>>> m(a=1, b=2, c=1)
"""
a
,
b
,
c
=
b
,
c
,
a
def
n
(
a
,
*
,
b
,
c
=
88
):
...
...
tests/run/kwonlyargscall.pyx
View file @
c8b85056
__doc__
=
u"""
# the calls:
def
call0ab
(
f
):
"""
>>> call0ab(b)
Traceback (most recent call last):
TypeError: b() takes exactly 3 positional arguments (2 given)
>>> call0abc(b)
1 2 3
>>> call3(b)
1 2 3
>>> call4(b)
Traceback (most recent call last):
TypeError: b() takes exactly 3 positional arguments (4 given)
>>> call0ab(c)
1 2 1
>>> call0abc(c)
>>> call0ab(d)
1 2 88
"""
f
(
a
=
1
,
b
=
2
)
def
call0abc
(
f
):
"""
>>> call0abc(b)
1 2 3
>>> call2(c)
1 2 1
>>> call3(c)
>>> call0abc(c)
1 2 3
>>> call4(c)
Traceback (most recent call last):
TypeError: c() takes at most 3 positional arguments (4 given)
>>> call0abc(d)
1 2 3
>>> call0ab(d)
1 2 88
>>> call0abc(e)
1 2 3 []
>>> call0abc(f)
1 2 3 42
>>> call0abc(m)
1 2 3
"""
f
(
a
=
1
,
b
=
2
,
c
=
3
)
def
call2
(
f
):
"""
>>> call2(c)
1 2 1
>>> call2(d)
1 2 88
>>> call2c(d)
1 2 1
>>> call2(e)
1 2 88 []
>>> call2(f)
Traceback (most recent call last):
TypeError: f() needs keyword-only argument c
>>> call2(g)
Traceback (most recent call last):
TypeError: g() needs keyword-only argument c
>>> call2(m)
Traceback (most recent call last):
TypeError: m() needs keyword-only argument c
"""
f
(
1
,
2
)
def
call3
(
f
):
"""
>>> call3(b)
1 2 3
>>> call3(c)
1 2 3
>>> call3(d)
Traceback (most recent call last):
TypeError: d() takes exactly 2 positional arguments (3 given)
>>> call2d(d)
Traceback (most recent call last):
TypeError: d() got an unexpected keyword argument 'd'
>>> call0abc(e)
1 2 3 []
>>> call2(e)
1 2 88 []
>>> call2c(e)
1 2 1 []
>>> call2d(e)
1 2 88 [('d', 1)]
>>> call2cde(e)
1 2 1 [('d', 2), ('e', 3)]
>>> call3(e)
1 2 3 []
>>> call4(e)
Traceback (most recent call last):
TypeError: e() takes at most 3 positional arguments (4 given)
>>> call0abc(f)
1 2 3 42
>>> call2c(f)
1 2 1 42
>>> call2cd(f)
1 2 1 2
>>> call3(f)
Traceback (most recent call last):
TypeError: f() takes exactly 2 positional arguments (3 given)
>>> call2(f)
Traceback (most recent call last):
TypeError: f() needs keyword-only argument c
>>> call2ce(f)
Traceback (most recent call last):
TypeError: f() got an unexpected keyword argument 'e'
>>> call2cf(g)
1 2 1 42 17 2 []
>>> call2cefd(g)
1 2 1 11 0 2 []
>>> call2cfex(g)
1 2 1 42 0 2 [('x', 25)]
>>> call3(g)
Traceback (most recent call last):
TypeError: g() takes exactly 2 positional arguments (3 given)
>>> call2(g)
Traceback (most recent call last):
TypeError: g() needs keyword-only argument c
>>> call2c(g)
Traceback (most recent call last):
TypeError: g() needs keyword-only argument f
>>> call2cf(h)
1 2 1 42 17 2 () []
>>> call2cfe(h)
1 2 1 42 3 2 () []
>>> call6cf(h)
1 2 1 42 17 2 (3, 4, 5, 6) []
>>> call6cfexy(h)
1 2 1 42 3 2 (3, 4, 5, 6) [('x', 25), ('y', 11)]
>>> call3(h)
Traceback (most recent call last):
TypeError: h() needs keyword-only argument c
>>> call3d(h)
Traceback (most recent call last):
TypeError: h() needs keyword-only argument c
>>> call2cf(k)
1 2 1 42 17 2 () []
>>> call2cfe(k)
1 2 1 42 3 2 () []
>>> call6df(k)
1 2 3 1 17 2 (4, 5, 6) []
>>> call6dfexy(k)
1 2 3 1 3 2 (4, 5, 6) [('x', 25), ('y', 11)]
>>> call3(k)
Traceback (most recent call last):
TypeError: k() needs keyword-only argument f
>>> call2d(k)
Traceback (most recent call last):
TypeError: k() needs keyword-only argument f
>>> call0abc(m)
1 2 3
>>> call2c(m)
1 2 1
>>> call3(m)
Traceback (most recent call last):
TypeError: m() takes at most 2 positional arguments (3 given)
>>> call2(m)
Traceback (most recent call last):
TypeError: m() needs keyword-only argument c
>>> call2cd(m)
Traceback (most recent call last):
TypeError: m() got an unexpected keyword argument 'd'
"""
# the calls:
def
call0ab
(
f
):
f
(
a
=
1
,
b
=
2
)
def
call0abc
(
f
):
f
(
a
=
1
,
b
=
2
,
c
=
3
)
def
call2
(
f
):
f
(
1
,
2
)
def
call3
(
f
):
"""
f
(
1
,
2
,
3
)
def
call4
(
f
):
"""
>>> call4(b)
Traceback (most recent call last):
TypeError: b() takes exactly 3 positional arguments (4 given)
>>> call4(c)
Traceback (most recent call last):
TypeError: c() takes at most 3 positional arguments (4 given)
>>> call4(e)
Traceback (most recent call last):
TypeError: e() takes at most 3 positional arguments (4 given)
"""
f
(
1
,
2
,
3
,
4
)
def
call2c
(
f
):
"""
>>> call2c(d)
1 2 1
>>> call2c(e)
1 2 1 []
>>> call2c(f)
1 2 1 42
>>> call2c(g)
Traceback (most recent call last):
TypeError: g() needs keyword-only argument f
>>> call2c(m)
1 2 1
"""
f
(
1
,
2
,
c
=
1
)
def
call2d
(
f
):
"""
>>> call2d(d)
Traceback (most recent call last):
TypeError: d() got an unexpected keyword argument 'd'
>>> call2d(e)
1 2 88 [('d', 1)]
>>> call2d(k)
Traceback (most recent call last):
TypeError: k() needs keyword-only argument f
"""
f
(
1
,
2
,
d
=
1
)
def
call3d
(
f
):
"""
>>> call3d(h)
Traceback (most recent call last):
TypeError: h() needs keyword-only argument c
"""
f
(
1
,
2
,
3
,
d
=
1
)
def
call2cd
(
f
):
"""
>>> call2cd(f)
1 2 1 2
>>> call2cd(m)
Traceback (most recent call last):
TypeError: m() got an unexpected keyword argument 'd'
"""
f
(
1
,
2
,
c
=
1
,
d
=
2
)
def
call2ce
(
f
):
"""
>>> call2ce(f)
Traceback (most recent call last):
TypeError: f() got an unexpected keyword argument 'e'
"""
f
(
1
,
2
,
c
=
1
,
e
=
2
)
def
call2cde
(
f
):
"""
>>> call2cde(e)
1 2 1 [('d', 2), ('e', 3)]
"""
f
(
1
,
2
,
c
=
1
,
d
=
2
,
e
=
3
)
def
call2cf
(
f
):
"""
>>> call2cf(g)
1 2 1 42 17 2 []
>>> call2cf(h)
1 2 1 42 17 2 () []
>>> call2cf(k)
1 2 1 42 17 2 () []
"""
f
(
1
,
2
,
c
=
1
,
f
=
2
)
def
call6cf
(
f
):
"""
>>> call6cf(h)
1 2 1 42 17 2 (3, 4, 5, 6) []
"""
f
(
1
,
2
,
3
,
4
,
5
,
6
,
c
=
1
,
f
=
2
)
def
call6df
(
f
):
"""
>>> call6df(k)
1 2 3 1 17 2 (4, 5, 6) []
"""
f
(
1
,
2
,
3
,
4
,
5
,
6
,
d
=
1
,
f
=
2
)
def
call2cfe
(
f
):
"""
>>> call2cfe(h)
1 2 1 42 3 2 () []
>>> call2cfe(k)
1 2 1 42 3 2 () []
"""
f
(
1
,
2
,
c
=
1
,
f
=
2
,
e
=
3
)
def
call2cefd
(
f
):
"""
>>> call2cefd(g)
1 2 1 11 0 2 []
"""
f
(
1
,
2
,
c
=
1
,
e
=
0
,
f
=
2
,
d
=
11
)
def
call2cfex
(
f
):
"""
>>> call2cfex(g)
1 2 1 42 0 2 [('x', 25)]
"""
f
(
1
,
2
,
c
=
1
,
f
=
2
,
e
=
0
,
x
=
25
)
def
call6argscfexy
(
f
):
...
...
@@ -194,9 +207,17 @@ def call6argscfexy(f):
f
(
*
args
,
c
=
1
,
f
=
2
,
e
=
3
,
x
=
25
,
y
=
11
)
def
call6cfexy
(
f
):
"""
>>> call6cfexy(h)
1 2 1 42 3 2 (3, 4, 5, 6) [('x', 25), ('y', 11)]
"""
f
(
1
,
2
,
3
,
4
,
5
,
6
,
c
=
1
,
f
=
2
,
e
=
3
,
x
=
25
,
y
=
11
)
def
call6dfexy
(
f
):
"""
>>> call6dfexy(k)
1 2 3 1 3 2 (4, 5, 6) [('x', 25), ('y', 11)]
"""
f
(
1
,
2
,
3
,
4
,
5
,
6
,
d
=
1
,
f
=
2
,
e
=
3
,
x
=
25
,
y
=
11
)
# the called functions:
...
...
tests/run/large_consts_T237.pyx
View file @
c8b85056
__doc__
=
u"""
>>> add_large_pow() == 2**31 + 2**31
True
>>> add_large_pow() == 2**32
True
>>> add_large() == 2147483647 + 2147483647
True
#>>> add_large_c() == 2147483647 + 2147483647
#True
"""
#def add_large_c():
# cdef unsigned long long val = 2**30 + 2**30
# return val
def
add_large
():
"""
>>> add_large() == 2147483647 + 2147483647
True
#>>> add_large_c() == 2147483647 + 2147483647
#True
"""
return
2147483647
+
2147483647
def
add_large_pow
():
"""
>>> add_large_pow() == 2**31 + 2**31
True
>>> add_large_pow() == 2**32
True
"""
return
2
**
31
+
2
**
31
tests/run/list.pyx
View file @
c8b85056
__doc__
=
u"""
def
f
(
obj1
,
obj2
,
obj3
,
obj4
,
obj5
):
"""
>>> f(1, 2, 3, 4, 5)
[]
>>> g(1, 2, 3, 4, 5)
[2]
>>> h(1, 2, 3, 4, 5)
[2, 3]
>>> j(1, 2, 3, 4, 5)
[2, 3, 4]
>>> k(1, 2, 3, 4, 5)
[17, 42, 88]
>>> test_list_sort()
[1, 2, 3, 4]
>>> test_list_reverse()
[1, 2, 3, 4]
>>> test_list_pop()
(2, [1])
>>> test_list_pop0()
(1, [2])
>>> test_list_pop_all()
True
"""
def
f
(
obj1
,
obj2
,
obj3
,
obj4
,
obj5
):
"""
obj1
=
[]
return
obj1
def
g
(
obj1
,
obj2
,
obj3
,
obj4
,
obj5
):
"""
>>> g(1, 2, 3, 4, 5)
[2]
"""
obj1
=
[
obj2
]
return
obj1
def
h
(
obj1
,
obj2
,
obj3
,
obj4
,
obj5
):
"""
>>> h(1, 2, 3, 4, 5)
[2, 3]
"""
obj1
=
[
obj2
,
obj3
]
return
obj1
def
j
(
obj1
,
obj2
,
obj3
,
obj4
,
obj5
):
"""
>>> j(1, 2, 3, 4, 5)
[2, 3, 4]
"""
obj1
=
[
obj2
,
obj3
,
obj4
]
return
obj1
def
k
(
obj1
,
obj2
,
obj3
,
obj4
,
obj5
):
"""
>>> k(1, 2, 3, 4, 5)
[17, 42, 88]
"""
obj1
=
[
17
,
42
,
88
]
return
obj1
def
test_list_sort
():
"""
>>> test_list_sort()
[1, 2, 3, 4]
"""
cdef
list
l1
l1
=
[
2
,
3
,
1
,
4
]
l1
.
sort
()
...
...
@@ -54,24 +55,40 @@ def test_list_sort_reversed():
return
l1
def
test_list_reverse
():
"""
>>> test_list_reverse()
[1, 2, 3, 4]
"""
cdef
list
l1
l1
=
[
4
,
3
,
2
,
1
]
l1
.
reverse
()
return
l1
def
test_list_pop
():
"""
>>> test_list_pop()
(2, [1])
"""
cdef
list
l1
l1
=
[
1
,
2
]
two
=
l1
.
pop
()
return
two
,
l1
def
test_list_pop0
():
"""
>>> test_list_pop0()
(1, [2])
"""
cdef
list
l1
l1
=
[
1
,
2
]
one
=
l1
.
pop
(
0
)
return
one
,
l1
def
test_list_pop_all
():
"""
>>> test_list_pop_all()
True
"""
cdef
list
l1
l1
=
[
1
,
2
]
try
:
...
...
tests/run/listcomp.pyx
View file @
c8b85056
__doc__
=
u"""
>>> smoketest()
[0, 4, 8]
>>> int_runvar()
[0, 4, 8]
>>> typed()
[A, A, A]
>>> iterdict()
[1, 2, 3]
"""
def
smoketest
():
"""
>>> smoketest()
[0, 4, 8]
"""
print
[
x
*
2
for
x
in
range
(
5
)
if
x
%
2
==
0
]
def
int_runvar
():
"""
>>> int_runvar()
[0, 4, 8]
"""
cdef
int
x
print
[
x
*
2
for
x
in
range
(
5
)
if
x
%
2
==
0
]
...
...
@@ -20,10 +17,18 @@ cdef class A:
def
__repr__
(
self
):
return
u"A"
def
typed
():
"""
>>> typed()
[A, A, A]
"""
cdef
A
obj
print
[
obj
for
obj
in
[
A
(),
A
(),
A
()]]
def
iterdict
():
"""
>>> iterdict()
[1, 2, 3]
"""
cdef
dict
d
=
dict
(
a
=
1
,
b
=
2
,
c
=
3
)
l
=
[
d
[
key
]
for
key
in
d
]
l
.
sort
()
...
...
tests/run/literal_lists.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test_ints(100)
(100, 100, 100)
__doc__
=
"""
>>> test_chars(b'yo')
(b'a', b'bc', b'yo')
>>> test_chars(None) # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: expected ...
>>> test_struct(-5, -10)
-5 -10 True
1 2 False
"""
import
sys
...
...
@@ -17,6 +12,10 @@ if sys.version_info[0] < 3:
__doc__
=
__doc__
.
replace
(
u"b'"
,
u"'"
)
def
test_ints
(
int
x
):
"""
>>> test_ints(100)
(100, 100, 100)
"""
cdef
list
L
=
[
1
,
2
,
3
,
x
]
cdef
int
*
Li
=
[
1
,
2
,
3
,
x
]
cdef
int
**
Lii
=
[
Li
,
&
x
]
...
...
@@ -35,6 +34,11 @@ cdef print_struct(MyStruct a):
print
a
.
x
,
a
.
y
,
a
.
data
==
NULL
def
test_struct
(
int
x
,
y
):
"""
>>> test_struct(-5, -10)
-5 -10 True
1 2 False
"""
cdef
MyStruct
*
aa
=
[[
x
,
y
,
NULL
],
[
x
+
1
,
y
+
1
,
NULL
]]
print_struct
(
aa
[
0
])
print_struct
([
1
,
2
,
<
double
**>
1
])
...
...
tests/run/literals.pyx
View file @
c8b85056
__doc__
=
u"""
>>> foo()
>>> test_float(1./3)
True
>>> test_complex(1j/3)
True
"""
def
foo
():
"""
>>> foo()
"""
a
=
42
a1
=
0123
a2
=
0xabc
...
...
@@ -55,7 +50,15 @@ with ' and " quotes"""
def test_float(x):
"""
>>>
test_float
(
1.
/
3
)
True
"""
return x == 1./3
def test_complex(x):
"""
>>>
test_complex
(
1j
/
3
)
True
"""
return x == 0.3333333333333333j
tests/run/locals.pyx
View file @
c8b85056
...
...
@@ -2,12 +2,6 @@ __doc__ = u"""
>>> sorted( get_locals(1,2,3, k=5) .items())
[('args', (2, 3)), ('kwds', {'k': 5}), ('x', 1), ('y', 'hi'), ('z', 5)]
>>> in_locals('z')
True
>>> in_locals('args')
True
>>> in_locals('X')
False
"""
def
get_locals
(
x
,
*
args
,
**
kwds
):
...
...
@@ -16,6 +10,14 @@ def get_locals(x, *args, **kwds):
return
locals
()
def
in_locals
(
x
,
*
args
,
**
kwds
):
"""
>>> in_locals('z')
True
>>> in_locals('args')
True
>>> in_locals('X')
False
"""
cdef
int
z
=
5
y
=
"hi"
return
x
in
locals
()
...
...
tests/run/locals_rebind_T429.pyx
View file @
c8b85056
...
...
@@ -2,8 +2,6 @@ __doc__ = u"""
>>> sorted( get_locals(1,2,3, k=5) .items())
[('args', (2, 3)), ('kwds', {'k': 5}), ('x', 1), ('y', 'hi'), ('z', 5)]
>>> get_locals_rebound(1,2,3)
'REBOUND'
"""
def
get_locals
(
x
,
*
args
,
**
kwds
):
...
...
@@ -12,6 +10,10 @@ def get_locals(x, *args, **kwds):
return
locals
()
def
get_locals_rebound
(
x
,
*
args
,
**
kwds
):
"""
>>> get_locals_rebound(1,2,3)
'REBOUND'
"""
cdef
int
z
=
5
locals
=
_locals
y
=
"hi"
...
...
tests/run/menten1.pyx
View file @
c8b85056
__doc__
=
u"""
>>> loops()
5
"""
def
loops
():
"""
>>> loops()
5
"""
cdef
int
k
for
i
from
0
<=
i
<
5
:
for
j
from
0
<=
j
<
2
:
...
...
tests/run/modbody.pyx
View file @
c8b85056
__doc__
=
u"""
def
f
():
"""
>>> f()
>>> g
42
>>> x
u'spam'
>>> y
u'eggs'
>>> z
u'spameggs'
"""
import
sys
if
sys
.
version_info
[
0
]
>=
3
:
__doc__
=
__doc__
.
replace
(
u" u'"
,
u" '"
)
def
f
():
>>> x == 'spam'
True
>>> y == 'eggs'
True
>>> z == 'spameggs'
True
"""
pass
g
=
42
...
...
tests/run/modop.pyx
View file @
c8b85056
__doc__
=
u"""
>>> modobj(9,2)
1
>>> modobj('%d', 5)
'5'
>>> modint(9,2)
1
"""
import
sys
if
sys
.
version_info
[
0
]
<
3
:
__doc__
=
__doc__
+
u"""
__doc__
=
u"""
>>> modptr()
'spameggs'
"""
"""
def
modobj
(
obj2
,
obj3
):
"""
>>> modobj(9,2)
1
>>> modobj('%d', 5)
'5'
"""
obj1
=
obj2
%
obj3
return
obj1
def
modint
(
int
int2
,
int
int3
):
"""
>>> modint(9,2)
1
"""
cdef
int
int1
int1
=
int2
%
int3
return
int1
...
...
@@ -29,6 +28,5 @@ def modptr():
cdef
char
*
str2
,
*
str3
str2
=
"spam%s"
str3
=
"eggs"
obj1
=
str2
%
str3
# '%' operator doesn't work on byte strings in Py3
return
obj1
tests/run/multass.pyx
View file @
c8b85056
__doc__
=
u"""
>>> f()
(1, 2, 1, 2)
>>> g()
(1, 1, 2, 2, 3, 3)
__doc__
=
"""
>>> h()
(1, b'test', 3, 1, b'test', 3)
>>> j()
(2, 1, 4, 2, 6, 3)
"""
import
sys
...
...
@@ -14,12 +8,20 @@ if sys.version_info[0] < 3:
__doc__
=
__doc__
.
replace
(
u" b'"
,
u" '"
)
def
f
():
"""
>>> f()
(1, 2, 1, 2)
"""
cdef
object
obj1a
,
obj2a
,
obj3a
,
obj1b
,
obj2b
,
obj3b
obj1b
,
obj2b
,
obj3b
=
1
,
2
,
3
obj1a
,
obj2a
=
obj1b
,
obj2b
return
obj1a
,
obj2a
,
obj1b
,
obj2b
def
g
():
"""
>>> g()
(1, 1, 2, 2, 3, 3)
"""
cdef
object
obj1a
,
obj2a
,
obj3a
,
obj1b
,
obj2b
,
obj3b
obj1b
,
obj2b
,
obj3b
=
1
,
2
,
3
obj1a
,
[
obj2a
,
obj3a
]
=
[
obj1b
,
(
obj2b
,
obj3b
)]
...
...
@@ -34,6 +36,10 @@ def h():
return
int1
,
ptr1
,
obj1a
,
int2
,
ptr2
,
obj1b
def
j
():
"""
>>> j()
(2, 1, 4, 2, 6, 3)
"""
cdef
object
obj1a
,
obj2a
,
obj3a
,
obj1b
,
obj2b
,
obj3b
obj1b
,
obj2b
,
obj3b
=
1
,
2
,
3
obj1a
,
obj2a
,
obj3a
=
obj1b
+
1
,
obj2b
+
2
,
obj3b
+
3
...
...
tests/run/new_style_exceptions.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test(Exception(u'hi'))
Raising: Exception(u'hi',)
Caught: Exception(u'hi',)
"""
import
sys
if
sys
.
version_info
[
0
]
>=
3
:
__doc__
=
__doc__
.
replace
(
u"u'"
,
u"'"
)
import
sys
,
types
def
test
(
obj
):
"""
>>> test(Exception('hi'))
Raising: Exception('hi',)
Caught: Exception('hi',)
"""
print
u"Raising: %s%r"
%
(
obj
.
__class__
.
__name__
,
obj
.
args
)
try
:
raise
obj
...
...
tests/run/nogil.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test(5)
47
>>> test(11)
53
"""
def
test
(
int
x
):
"""
>>> test(5)
47
>>> test(11)
53
"""
with
nogil
:
f
(
x
)
x
=
g
(
x
)
...
...
@@ -20,5 +19,3 @@ cdef int g(int x) nogil:
cdef
int
y
y
=
x
+
42
return
y
tests/run/nonecheck.pyx
View file @
c8b85056
__doc__
=
u"""
Tests accessing attributes of extension type variables
set to None
>>> obj = MyClass(2, 3)
>>> getattr_(obj)
2
>>> getattr_(None)
Traceback (most recent call last):
...
AttributeError: 'NoneType' object has no attribute 'a'
>>> setattr_(obj)
>>> getattr_(obj)
10
>>> setattr_(None)
Traceback (most recent call last):
...
AttributeError: 'NoneType' object has no attribute 'a'
>>> obj = MyClass(2, 3)
>>> checking(obj)
2
2
>>> checking(None)
var is None
>>> check_and_assign(obj)
Traceback (most recent call last):
...
AttributeError: 'NoneType' object has no attribute 'a'
>>> check_buffer_get(None)
Traceback (most recent call last):
...
TypeError: 'NoneType' object is unsubscriptable
>>> check_buffer_set(None)
Traceback (most recent call last):
...
TypeError: 'NoneType' object is unsubscriptable
"""
cimport
cython
...
...
@@ -54,10 +13,30 @@ cdef class MyClass:
@
cython
.
nonecheck
(
True
)
def
getattr_
(
MyClass
var
):
"""
>>> obj = MyClass(2, 3)
>>> getattr_(obj)
2
>>> getattr_(None)
Traceback (most recent call last):
...
AttributeError: 'NoneType' object has no attribute 'a'
>>> setattr_(obj)
>>> getattr_(obj)
10
"""
print
var
.
a
@
cython
.
nonecheck
(
True
)
def
setattr_
(
MyClass
var
):
"""
>>> obj = MyClass(2, 3)
>>> setattr_(obj)
>>> setattr_(None)
Traceback (most recent call last):
...
AttributeError: 'NoneType' object has no attribute 'a'
"""
var
.
a
=
10
def
some
():
...
...
@@ -65,6 +44,14 @@ def some():
@
cython
.
nonecheck
(
True
)
def
checking
(
MyClass
var
):
"""
>>> obj = MyClass(2, 3)
>>> checking(obj)
2
2
>>> checking(None)
var is None
"""
state
=
(
var
is
None
)
if
not
state
:
print
var
.
a
...
...
@@ -75,6 +62,13 @@ def checking(MyClass var):
@
cython
.
nonecheck
(
True
)
def
check_and_assign
(
MyClass
var
):
"""
>>> obj = MyClass(2, 3)
>>> check_and_assign(obj)
Traceback (most recent call last):
...
AttributeError: 'NoneType' object has no attribute 'a'
"""
if
var
is
not
None
:
print
var
.
a
var
=
None
...
...
@@ -82,9 +76,20 @@ def check_and_assign(MyClass var):
@
cython
.
nonecheck
(
True
)
def
check_buffer_get
(
object
[
int
]
buf
):
"""
>>> check_buffer_get(None)
Traceback (most recent call last):
...
TypeError: 'NoneType' object is unsubscriptable
"""
return
buf
[
0
]
@
cython
.
nonecheck
(
True
)
def
check_buffer_set
(
object
[
int
]
buf
):
"""
>>> check_buffer_set(None)
Traceback (most recent call last):
...
TypeError: 'NoneType' object is unsubscriptable
"""
buf
[
0
]
=
1
tests/run/nononetypecheck.pyx
View file @
c8b85056
__doc__
=
u"""
>>> g()
"""
cdef
class
Spam
:
pass
...
...
@@ -9,4 +5,7 @@ cdef f(Spam s):
pass
def
g
():
"""
>>> g()
"""
f
(
None
)
tests/run/notinop.pyx
View file @
c8b85056
__doc__
=
u"""
def
f
(
a
,
b
):
"""
>>> f(1,[1,2,3])
False
>>> f(5,[1,2,3])
True
>>> f(2,(1,2,3))
False
"""
result
=
a
not
in
b
return
result
def
g
(
a
,
b
):
"""
>>> g(1,[1,2,3])
0
>>> g(5,[1,2,3])
1
>>> g(2,(1,2,3))
0
"""
cdef
int
result
result
=
a
not
in
b
return
result
def
h
(
b
):
"""
>>> h([1,2,3,4])
False
>>> h([1,3,4])
True
"""
result
=
2
not
in
b
return
result
def
j
(
b
):
"""
>>> j([1,2,3,4])
0
>>> j([1,3,4])
1
"""
cdef
int
result
result
=
2
not
in
b
return
result
def
k
(
a
):
"""
>>> k(1)
0
>>> k(5)
1
"""
cdef
int
result
=
a
not
in
[
1
,
2
,
3
,
4
]
return
result
def
m
(
int
a
):
"""
>>> m(2)
0
>>> m(5)
1
"""
cdef
int
result
=
a
not
in
[
1
,
2
,
3
,
4
]
return
result
def
n
(
a
):
"""
>>> n('d *')
0
>>> n('xxx')
1
"""
cdef
int
result
=
a
.
lower
()
not
in
[
u'a *'
,
u'b *'
,
u'c *'
,
u'd *'
]
return
result
def
p
(
a
):
"""
>>> p('a')
0
>>> p(1)
1
>>> q(1)
Traceback (most recent call last):
TypeError: 'NoneType' object is not iterable
"""
def
f
(
a
,
b
):
result
=
a
not
in
b
return
result
def
g
(
a
,
b
):
cdef
int
result
result
=
a
not
in
b
return
result
def
h
(
b
):
result
=
2
not
in
b
return
result
def
j
(
b
):
cdef
int
result
result
=
2
not
in
b
return
result
def
k
(
a
):
cdef
int
result
=
a
not
in
[
1
,
2
,
3
,
4
]
return
result
def
m
(
int
a
):
cdef
int
result
=
a
not
in
[
1
,
2
,
3
,
4
]
return
result
def
n
(
a
):
cdef
int
result
=
a
.
lower
()
not
in
[
u'a *'
,
u'b *'
,
u'c *'
,
u'd *'
]
return
result
def
p
(
a
):
"""
cdef
dict
d
=
{
u'a'
:
1
,
u'b'
:
2
}
cdef
int
result
=
a
not
in
d
return
result
def
q
(
a
):
"""
>>> q(1)
Traceback (most recent call last):
TypeError: 'NoneType' object is not iterable
"""
cdef
dict
d
=
None
cdef
int
result
=
a
not
in
d
# should fail with a TypeError
return
result
tests/run/or.pyx
View file @
c8b85056
__doc__
=
u"""
>>> a,b = 'a *','b *' # use non-interned strings
>>> or2_assign(2,3) == (2 or 3)
True
>>> or2_assign('a', 'b') == ('a' or 'b')
True
>>> or2_assign(a, b) == (a or b)
True
>>> or2(2,3) == (2 or 3)
True
>>> or2(0,2) == (0 or 2)
True
>>> or2('a', 'b') == ('a' or 'b')
True
>>> or2(a, b) == (a or b)
True
>>> or2('', 'b') == ('' or 'b')
True
>>> or2([], [1]) == ([] or [1])
True
>>> or2([], [a]) == ([] or [a])
True
>>> or3(0,1,2) == (0 or 1 or 2)
True
>>> or3([],(),[1]) == ([] or () or [1])
True
>>> or2_no_result(2,3)
>>> or2_no_result(0,2)
>>> or2_no_result('a','b')
>>> or2_no_result(a,b)
>>> a or b
'a *'
"""
a
,
b
=
'a *'
,
'b *'
# use non-interned strings
def
or2_assign
(
a
,
b
):
"""
>>> or2_assign(2,3) == (2 or 3)
True
>>> or2_assign('a', 'b') == ('a' or 'b')
True
>>> or2_assign(a, b) == (a or b)
True
"""
c
=
a
or
b
return
c
def
or2
(
a
,
b
):
"""
>>> or2(2,3) == (2 or 3)
True
>>> or2(0,2) == (0 or 2)
True
>>> or2('a', 'b') == ('a' or 'b')
True
>>> or2(a, b) == (a or b)
True
>>> or2('', 'b') == ('' or 'b')
True
>>> or2([], [1]) == ([] or [1])
True
>>> or2([], [a]) == ([] or [a])
True
"""
return
a
or
b
def
or3
(
a
,
b
,
c
):
"""
>>> or3(0,1,2) == (0 or 1 or 2)
True
>>> or3([],(),[1]) == ([] or () or [1])
True
"""
d
=
a
or
b
or
c
return
d
def
or2_no_result
(
a
,
b
):
"""
>>> or2_no_result(2,3)
>>> or2_no_result(0,2)
>>> or2_no_result('a','b')
>>> or2_no_result(a,b)
>>> a or b
'a *'
"""
a
or
b
tests/run/packedstruct_T290.pyx
View file @
c8b85056
...
...
@@ -13,4 +13,3 @@ ctypedef packed struct MyCTypeDefStruct:
def
f
():
return
(
sizeof
(
MyCdefStruct
),
sizeof
(
MyCTypeDefStruct
))
tests/run/parallel_swap_assign_T425.pyx
View file @
c8b85056
cimport
cython
@
cython
.
test_assert_path_exists
(
...
...
tests/run/pass.pyx
View file @
c8b85056
__doc__
=
u"""
>>> f()
"""
def
f
():
"""
>>> f()
"""
pass
tests/run/pinard5.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test()
1
"""
cdef
class
Tri
:
def
test
(
self
):
return
1
...
...
@@ -16,6 +11,10 @@ cdef produire_fiches(Tri tri):
return
tri
.
test
()
def
test
():
"""
>>> test()
1
"""
cdef
Curseur
c
c
=
Curseur
()
c
.
tri
=
Tri
()
...
...
tests/run/powop.pyx
View file @
c8b85056
__doc__
=
u"""
def
f
(
obj2
,
obj3
):
"""
>>> f(1.0, 2.95)[0] == f(1.0, 2.95)[1]
True
>>> g(4)
1024
>>> h(4)
625
>>> constant_py() == 2 ** 10
True
>>> constant_long() == 2 ** 36
True
>>> small_int_pow(3)
(1, 3, 9, 27, 81)
>>> small_int_pow(-5)
(1, -5, 25, -125, 625)
>>> int_pow(7, 2)
49
>>> int_pow(5, 3)
125
>>> int_pow(2, 10)
1024
"""
def
f
(
obj2
,
obj3
):
"""
cdef
float
flt1
,
flt2
,
flt3
flt2
,
flt3
=
obj2
,
obj3
...
...
@@ -36,21 +11,51 @@ def f(obj2, obj3):
return
flt1
,
obj1
def
g
(
i
):
"""
>>> g(4)
1024
"""
return
i
**
5
def
h
(
i
):
"""
>>> h(4)
625
"""
return
5
**
i
def
constant_py
():
"""
>>> constant_py() == 2 ** 10
True
"""
result
=
(
<
object
>
2
)
**
10
return
result
def
constant_long
():
"""
>>> constant_long() == 2 ** 36
True
"""
result
=
(
<
object
>
2L
)
**
36
return
result
def
small_int_pow
(
long
s
):
"""
>>> small_int_pow(3)
(1, 3, 9, 27, 81)
>>> small_int_pow(-5)
(1, -5, 25, -125, 625)
"""
return
s
**
0
,
s
**
1
,
s
**
2
,
s
**
3
,
s
**
4
def
int_pow
(
short
a
,
short
b
):
"""
>>> int_pow(7, 2)
49
>>> int_pow(5, 3)
125
>>> int_pow(2, 10)
1024
"""
return
a
**
b
tests/run/print.pyx
View file @
c8b85056
__doc__
=
u"""
def
f
(
a
,
b
):
"""
>>> f(1, 'test')
<BLANKLINE>
1
1 test
1 test
1 test 42 spam
"""
def
f
(
a
,
b
):
"""
print
print
a
print
a
,
...
...
tests/run/pure.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test_sizeof()
True
True
True
True
True
>>> test_declare(100)
(100, 100)
>>> test_declare(100.5)
(100, 100)
>>> test_declare(None)
Traceback (most recent call last):
...
TypeError: an integer is required
>>> test_cast(1.5)
1
>>> test_cast(None)
Traceback (most recent call last):
...
TypeError: a float is required
>>> test_address(39)
39
>>> test_locals(5)
True
>>> test_struct(389, 1.64493)
(389, 1.64493)
>>> test_imports()
True
"""
import
cython
def
test_sizeof
():
"""
>>> test_sizeof()
True
True
True
True
True
"""
x
=
cython
.
declare
(
cython
.
bint
)
print
sizeof
(
x
)
==
sizeof
(
cython
.
bint
)
print
sizeof
(
cython
.
char
)
<=
sizeof
(
cython
.
short
)
<=
sizeof
(
cython
.
int
)
<=
sizeof
(
cython
.
long
)
<=
sizeof
(
cython
.
longlong
)
...
...
@@ -49,6 +20,16 @@ def test_sizeof():
print
sizeof
(
cython
.
char
)
==
1
def
test_declare
(
n
):
"""
>>> test_declare(100)
(100, 100)
>>> test_declare(100.5)
(100, 100)
>>> test_declare(None)
Traceback (most recent call last):
...
TypeError: an integer is required
"""
x
=
cython
.
declare
(
cython
.
int
)
y
=
cython
.
declare
(
cython
.
int
,
n
)
if
cython
.
compiled
:
...
...
@@ -59,17 +40,33 @@ def test_declare(n):
@
cython
.
locals
(
x
=
cython
.
double
,
n
=
cython
.
int
)
def
test_cast
(
x
):
"""
>>> test_cast(1.5)
1
>>> test_cast(None)
Traceback (most recent call last):
...
TypeError: a float is required
"""
n
=
cython
.
cast
(
cython
.
int
,
x
)
return
n
@
cython
.
locals
(
x
=
cython
.
int
,
y
=
cython
.
p_int
)
def
test_address
(
x
):
"""
>>> test_address(39)
39
"""
y
=
cython
.
address
(
x
)
return
y
[
0
]
@
cython
.
locals
(
x
=
cython
.
int
)
@
cython
.
locals
(
y
=
cython
.
bint
)
def
test_locals
(
x
):
"""
>>> test_locals(5)
True
"""
y
=
x
return
y
...
...
@@ -79,6 +76,10 @@ MyStruct = cython.struct(is_integral=cython.bint, data=MyUnion)
MyStruct2
=
cython
.
typedef
(
MyStruct
[
2
])
def
test_struct
(
n
,
x
):
"""
>>> test_struct(389, 1.64493)
(389, 1.64493)
"""
a
=
cython
.
declare
(
MyStruct2
)
a
[
0
]
=
MyStruct
(
True
,
data
=
MyUnion
(
n
=
n
))
a
[
1
]
=
MyStruct
(
is_integral
=
False
,
data
=
{
'x'
:
x
})
...
...
@@ -90,6 +91,10 @@ from cython import declare as my_declare, locals as my_locals, p_void as my_void
@
my_locals
(
a
=
cython
.
p_void
)
def
test_imports
():
"""
>>> test_imports()
True
"""
a
=
cython
.
NULL
b
=
declare
(
p_void
,
cython
.
NULL
)
c
=
my_declare
(
my_void_star
,
cython
.
NULL
)
...
...
tests/run/pycmp.pyx
View file @
c8b85056
__doc__
=
u"""
>>> f()
>>> g()
"""
def
f
():
"""
>>> f()
"""
cdef
int
bool
,
int1
,
int2
cdef
object
obj1
,
obj2
int1
=
0
...
...
@@ -22,6 +20,9 @@ def f():
assert
bool
def
g
():
"""
>>> g()
"""
cdef
int
bool
obj1
=
1
obj2
=
[]
...
...
@@ -29,4 +30,3 @@ def g():
assert
not
bool
bool
=
obj1
not
in
obj2
assert
bool
tests/run/pyintop.pyx
View file @
c8b85056
__doc__
=
u"""
def
f
(
obj1
,
obj2
,
obj3
):
"""
>>> f(1,2,3)
3
>>> g(1,2,3)
1
>>> h(1,2,3)
2
>>> j(1,2,3)
16
>>> k(1,2,3)
0
>>> l(1,2,3)
16
"""
def
f
(
obj1
,
obj2
,
obj3
):
"""
obj1
=
obj2
|
obj3
return
obj1
def
g
(
obj1
,
obj2
,
obj3
):
"""
>>> g(1,2,3)
1
"""
obj1
=
obj2
^
obj3
return
obj1
def
h
(
obj1
,
obj2
,
obj3
):
"""
>>> h(1,2,3)
2
"""
obj1
=
obj2
&
obj3
return
obj1
def
j
(
obj1
,
obj2
,
obj3
):
"""
>>> j(1,2,3)
16
"""
obj1
=
obj2
<<
obj3
return
obj1
def
k
(
obj1
,
obj2
,
obj3
):
"""
>>> k(1,2,3)
0
"""
obj1
=
obj2
>>
obj3
return
obj1
def
l
(
obj1
,
obj2
,
obj3
):
"""
>>> l(1,2,3)
16
"""
obj1
=
obj2
<<
obj3
|
obj2
>>
obj3
return
obj1
tests/run/pynumop.pyx
View file @
c8b85056
__doc__
=
u"""
def
f
():
"""
>>> f()
6
>>> g()
2
"""
def
f
():
"""
obj1
=
1
obj2
=
2
obj3
=
3
...
...
@@ -13,6 +10,10 @@ def f():
return
obj1
def
g
():
"""
>>> g()
2
"""
obj1
=
12
obj2
=
6
obj3
=
3
...
...
tests/run/pyobjcast_T313.pyx
View file @
c8b85056
...
...
@@ -18,4 +18,3 @@ def f():
p1
=
<
void
*>
a
p2
=
<
PyObject
*>
a
return
(
<
object
>
p1
,
<
object
>
p2
)
tests/run/r_argdefault.pyx
View file @
c8b85056
__doc__
=
u"""
def
swallow
(
name
=
None
,
airspeed
=
None
,
coconuts
=
None
):
"""
>>> swallow(name = "Brian")
This swallow is called Brian
>>> swallow(airspeed = 42)
This swallow is flying at 42 furlongs per fortnight
>>> swallow(coconuts = 3)
This swallow is carrying 3 coconuts
"""
def
swallow
(
name
=
None
,
airspeed
=
None
,
coconuts
=
None
):
"""
if
name
is
not
None
:
print
u"This swallow is called"
,
name
if
airspeed
is
not
None
:
print
u"This swallow is flying at"
,
airspeed
,
u"furlongs per fortnight"
if
coconuts
is
not
None
:
print
u"This swallow is carrying"
,
coconuts
,
u"coconuts"
tests/run/r_delgado_1.pyx
View file @
c8b85056
...
...
@@ -15,4 +15,3 @@ cdef class eggs:
def
eat
(
self
):
raise
RuntimeError
(
u"I don't like that"
)
tests/run/r_forloop.pyx
View file @
c8b85056
__doc__
=
u"""
def
go_py
():
"""
>>> go_py()
Spam!
Spam!
Spam!
Spam!
>>> go_py_ret()
2
>>> go_c()
Spam!
Spam!
Spam!
Spam!
>>> go_c_int(1,5)
Spam!
Spam!
>>> go_c_enumerate()
True
True
True
True
>>> go_c_all()
Spam!
Spam!
Spam!
>>> go_c_all_exprs(1)
Spam!
>>> go_c_all_exprs(3)
Spam!
Spam!
>>> go_c_const_exprs()
Spam!
Spam!
>>> go_c_calc(2)
Spam!
Spam!
>>> go_c_ret()
2
>>> go_c_calc_ret(2)
6
>>> go_list()
Spam!
Spam!
Spam!
Spam!
>>> go_list_ret()
2
>>> go_tuple()
Spam!
Spam!
Spam!
Spam!
>>> go_tuple_ret()
2
>>> go_dict()
Spam!
Spam!
Spam!
Spam!
>>> go_dict_ret()
2
>>> global_result
6
"""
def
go_py
():
"""
for
i
in
range
(
4
):
print
u"Spam!"
def
go_py_ret
():
"""
>>> go_py_ret()
2
"""
for
i
in
range
(
4
):
if
i
>
1
:
return
i
def
go_c
():
"""
>>> go_c()
Spam!
Spam!
Spam!
Spam!
"""
cdef
int
i
for
i
in
range
(
4
):
print
u"Spam!"
def
go_c_enumerate
():
"""
>>> go_c_enumerate()
True
True
True
True
"""
cdef
int
i
,
k
for
i
,
k
in
enumerate
(
range
(
4
)):
print
i
==
k
def
go_c_int
(
int
a
,
int
b
):
"""
>>> go_c_int(1,5)
Spam!
Spam!
"""
cdef
int
i
for
i
in
range
(
a
,
b
,
2
):
print
u"Spam!"
def
go_c_all
():
"""
>>> go_c_all()
Spam!
Spam!
Spam!
"""
cdef
int
i
for
i
in
range
(
8
,
2
,
-
2
):
print
u"Spam!"
def
go_c_all_exprs
(
x
):
"""
>>> go_c_all_exprs(1)
Spam!
>>> go_c_all_exprs(3)
Spam!
Spam!
"""
cdef
int
i
for
i
in
range
(
4
*
x
,
2
*
x
,
-
3
):
print
u"Spam!"
def
go_c_const_exprs
():
"""
>>> go_c_const_exprs()
Spam!
Spam!
"""
cdef
int
i
for
i
in
range
(
4
*
2
+
1
,
2
*
2
,
-
2
-
1
):
print
u"Spam!"
...
...
@@ -111,50 +89,98 @@ def f(x):
return
2
*
x
def
go_c_calc
(
x
):
"""
>>> go_c_calc(2)
Spam!
Spam!
"""
cdef
int
i
for
i
in
range
(
2
*
f
(
x
),
f
(
x
),
-
2
):
print
u"Spam!"
def
go_c_calc_ret
(
x
):
"""
>>> go_c_calc_ret(2)
6
"""
cdef
int
i
for
i
in
range
(
2
*
f
(
x
),
f
(
x
),
-
2
):
if
i
<
2
*
f
(
x
):
return
i
def
go_c_ret
():
"""
>>> go_c_ret()
2
"""
cdef
int
i
for
i
in
range
(
4
):
if
i
>
1
:
return
i
def
go_list
():
"""
>>> go_list()
Spam!
Spam!
Spam!
Spam!
"""
cdef
list
l
=
list
(
range
(
4
))
for
i
in
l
:
print
u"Spam!"
def
go_list_ret
():
"""
>>> go_list_ret()
2
"""
cdef
list
l
=
list
(
range
(
4
))
for
i
in
l
:
if
i
>
1
:
return
i
def
go_tuple
():
"""
>>> go_tuple()
Spam!
Spam!
Spam!
Spam!
"""
cdef
tuple
t
=
tuple
(
range
(
4
))
for
i
in
t
:
print
u"Spam!"
def
go_tuple_ret
():
"""
>>> go_tuple_ret()
2
"""
cdef
tuple
t
=
tuple
(
range
(
4
))
for
i
in
t
:
if
i
>
1
:
return
i
def
go_dict
():
"""
>>> go_dict()
Spam!
Spam!
Spam!
Spam!
"""
cdef
dict
d
=
dict
(
zip
(
range
(
4
),
range
(
4
)))
for
i
in
d
:
print
u"Spam!"
def
go_dict_ret
():
"""
>>> go_dict_ret()
2
>>> global_result
6
"""
cdef
dict
d
=
dict
(
zip
(
range
(
4
),
range
(
4
)))
for
i
in
d
:
if
i
>
1
and
i
<
3
:
...
...
tests/run/r_jeff_epler_1.pyx
View file @
c8b85056
__doc__
=
u"""
def
blowup
(
p
):
"""
>>> blowup([2, 3, 5])
1
"""
def
blowup
(
p
):
"""
cdef
int
n
,
i
n
=
10
i
=
1
...
...
tests/run/r_mitch_chapman_2.pyx
View file @
c8b85056
__doc__
=
u"""
def
boolExpressionsFail
():
"""
>>> boolExpressionsFail()
'Not 2b'
"""
def
boolExpressionsFail
():
"""
dict
=
{
1
:
1
}
if
not
"2b"
in
dict
:
return
"Not 2b"
...
...
tests/run/r_primes.pyx
View file @
c8b85056
__doc__
=
u"""
def
primes
(
int
kmax
):
"""
>>> primes(20)
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]
"""
def
primes
(
int
kmax
):
"""
cdef
int
n
,
k
,
i
cdef
int
p
[
1000
]
result
=
[]
...
...
tests/run/r_print.pyx
View file @
c8b85056
__doc__
=
u"""
def
frighten
():
"""
>>> frighten()
NOBODY expects the Spanish Inquisition!
"""
def
frighten
():
"""
print
u"NOBODY"
,
u"expects"
,
u"the Spanish Inquisition!"
tests/run/r_pyclass.pyx
View file @
c8b85056
__doc__
=
u"""
>>> order()
42 tons of spam!
"""
class
Spam
:
def
__init__
(
self
,
w
):
...
...
@@ -12,5 +7,9 @@ class Spam:
print
self
.
weight
,
u"tons of spam!"
def
order
():
"""
>>> order()
42 tons of spam!
"""
s
=
Spam
(
42
)
s
.
serve
()
tests/run/r_starargcall.pyx
View file @
c8b85056
__doc__
=
u"""
>>> eggs()
Args: 1 2 3
Args: buckle my shoe
"""
def
spam
(
a
,
b
,
c
):
print
u"Args:"
,
a
,
b
,
c
def
eggs
():
"""
>>> eggs()
Args: 1 2 3
Args: buckle my shoe
"""
spam
(
*
(
1
,
2
,
3
))
spam
(
*
[
u"buckle"
,
u"my"
,
u"shoe"
])
tests/run/r_starargs.pyx
View file @
c8b85056
__doc__
=
u"""
def
swallow
(
name
,
airspeed
,
*
args
,
**
kwds
):
"""
>>> swallow("Brian", 42)
Name: Brian
Airspeed: 42
Extra args: ()
Extra keywords: {}
>>> swallow("Brian", 42, "African")
Name: Brian
Airspeed: 42
Extra args: ('African',)
Extra keywords: {}
>>> swallow("Brian", airspeed = 42)
Name: Brian
Airspeed: 42
Extra args: ()
Extra keywords: {}
>>> swallow("Brian", airspeed = 42, species = "African", coconuts = 3)
Name: Brian
Airspeed: 42
Extra args: ()
Extra keywords: {'coconuts': 3, 'species': 'African'}
>>> swallow("Brian", 42, "African", coconuts = 3)
Name: Brian
Airspeed: 42
Extra args: ('African',)
Extra keywords: {'coconuts': 3}
"""
def
swallow
(
name
,
airspeed
,
*
args
,
**
kwds
):
"""
print
u"Name:"
,
name
print
u"Airspeed:"
,
airspeed
print
u"Extra args:"
,
args
print
u"Extra keywords:"
,
kwds
tests/run/r_starargsonly.pyx
View file @
c8b85056
__doc__
=
u"""
def
spam
(
*
args
):
"""
>>> spam()
Args: ()
>>> spam(42)
Args: (42,)
>>> spam("one", 2, "buckle my shoe")
Args: ('one', 2, 'buckle my shoe')
"""
def
spam
(
*
args
):
"""
print
u"Args:"
,
args
tests/run/r_typecast.pyx
View file @
c8b85056
__doc__
=
u"""
>>> call_method( ExtType() ).method()
1
"""
cdef
class
ExtType
:
cdef
c_method
(
self
):
return
self
...
...
@@ -11,4 +6,8 @@ cdef class ExtType:
return
1
def
call_method
(
ExtType
et
):
"""
>>> call_method( ExtType() ).method()
1
"""
return
<
ExtType
>
et
.
c_method
()
tests/run/r_vree_1.pyx
View file @
c8b85056
import
sys
if
sys
.
version_info
[
0
]
<
3
:
__doc__
=
u"""
...
...
tests/run/range_optimisation_T203.pyx
View file @
c8b85056
__doc__
=
u"""
>>> for_from_range(5, 10)
range(5)
at 0
at 1
at 2
at 3
at 4
range(5, 10)
at 5
at 6
at 7
at 8
at 9
range(5, 10, 2)
at 5
at 7
at 9
9
>>> for_from_range(-5, -10)
range(-5)
range(-5, -10)
range(-5, -10, 2)
100
>>> for_from_bound_reassignment(5, 1)
at 0
at 1
at 2
at 3
at 4
5
>>> for_from_step_reassignment(15, 5, 2)
at 0
at 5
at 10
15
>>> for_from_target_reassignment(10, 2)
at 0
at 1
at 3
at 7
15
>>> for_from_py_target_reassignment(10, 2)
at 0
at 1
at 3
at 7
15
>>> for_from_py_global_target_reassignment(10, 2)
at 0
at 1
at 3
at 7
15
>>> for_in_target_reassignment(10, 2)
at 0
at 1
at 2
at 3
at 4
at 5
at 6
at 7
at 8
at 9
18
>>> test_func(5)
get_bound(5)
at 0
at 1
at 2
at 3
at 4
5
"""
cdef
int
get_bound
(
int
m
):
print
u"get_bound(%s)"
%
m
return
m
def
for_from_range
(
a
,
b
):
"""
>>> for_from_range(5, 10)
range(5)
at 0
at 1
at 2
at 3
at 4
range(5, 10)
at 5
at 6
at 7
at 8
at 9
range(5, 10, 2)
at 5
at 7
at 9
9
>>> for_from_range(-5, -10)
range(-5)
range(-5, -10)
range(-5, -10, 2)
100
"""
cdef
int
i
=
100
print
u"range(%s)"
%
a
for
i
in
range
(
a
):
...
...
@@ -91,6 +41,15 @@ def for_from_range(a, b):
return
i
def
for_from_bound_reassignment
(
int
bound
,
int
fake_bound
):
"""
>>> for_from_bound_reassignment(5, 1)
at 0
at 1
at 2
at 3
at 4
5
"""
cdef
int
i
=
100
for
i
from
0
<=
i
<
bound
:
print
u"at"
,
i
...
...
@@ -98,6 +57,13 @@ def for_from_bound_reassignment(int bound, int fake_bound):
return
i
def
for_from_step_reassignment
(
int
bound
,
int
step
,
int
fake_step
):
"""
>>> for_from_step_reassignment(15, 5, 2)
at 0
at 5
at 10
15
"""
cdef
int
i
=
100
for
i
from
0
<=
i
<
bound
by
step
:
print
u"at"
,
i
...
...
@@ -105,6 +71,14 @@ def for_from_step_reassignment(int bound, int step, int fake_step):
return
i
def
for_from_target_reassignment
(
int
bound
,
int
factor
):
"""
>>> for_from_target_reassignment(10, 2)
at 0
at 1
at 3
at 7
15
"""
cdef
int
i
=
100
for
i
from
0
<=
i
<
bound
:
print
u"at"
,
i
...
...
@@ -112,6 +86,14 @@ def for_from_target_reassignment(int bound, int factor):
return
i
def
for_from_py_target_reassignment
(
int
bound
,
int
factor
):
"""
>>> for_from_py_target_reassignment(10, 2)
at 0
at 1
at 3
at 7
15
"""
cdef
object
i
for
i
from
0
<=
i
<
bound
:
print
u"at"
,
i
...
...
@@ -119,6 +101,14 @@ def for_from_py_target_reassignment(int bound, int factor):
return
i
def
for_from_py_global_target_reassignment
(
int
bound
,
int
factor
):
"""
>>> for_from_py_global_target_reassignment(10, 2)
at 0
at 1
at 3
at 7
15
"""
global
g_var
for
g_var
from
0
<=
g_var
<
bound
:
print
u"at"
,
g_var
...
...
@@ -126,6 +116,20 @@ def for_from_py_global_target_reassignment(int bound, int factor):
return
g_var
def
for_in_target_reassignment
(
int
bound
,
int
factor
):
"""
>>> for_in_target_reassignment(10, 2)
at 0
at 1
at 2
at 3
at 4
at 5
at 6
at 7
at 8
at 9
18
"""
cdef
int
i
=
100
for
i
in
range
(
bound
):
print
u"at"
,
i
...
...
@@ -133,6 +137,16 @@ def for_in_target_reassignment(int bound, int factor):
return
i
def
test_func
(
int
n
):
"""
>>> test_func(5)
get_bound(5)
at 0
at 1
at 2
at 3
at 4
5
"""
cdef
int
i
=
100
for
i
from
0
<=
i
<
get_bound
(
n
):
print
u"at"
,
i
...
...
tests/run/ref2local.pyx
View file @
c8b85056
__doc__
=
u"""
def
f
():
"""
>>> f()
42
"""
def
f
():
"""
a
=
42
b
=
a
return
b
tests/run/return.pyx
View file @
c8b85056
__doc__
=
u"""
>>> f('test')
>>> test_g()
>>> test_h(5)
5
"""
def
f
(
a
):
"""
>>> f('test')
"""
return
return
a
return
42
...
...
@@ -19,7 +15,14 @@ cdef int h(a):
return
i
def
test_g
():
"""
>>> test_g()
"""
g
()
def
test_h
(
i
):
"""
>>> test_h(5)
5
"""
return
h
(
i
)
tests/run/returnparassign.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test()
5
"""
def
test
():
"""
>>> test()
5
"""
a
=
b
=
c
=
5
return
a
tests/run/simpcall.pyx
View file @
c8b85056
__doc__
=
u
"""
__doc__
=
"""
>>> z(1,9.2, b'test')
>>> failtype()
Traceback (most recent call last):
TypeError: an integer is required
>>> fail0(1,2)
Traceback (most recent call last):
TypeError: f() takes exactly 2 positional arguments (0 given)
>>> fail1(1,2)
Traceback (most recent call last):
TypeError: f() takes exactly 2 positional arguments (1 given)
"""
import
sys
...
...
@@ -33,10 +22,25 @@ def z(a, b, c):
g
(
a
,
b
,
c
)
def
fail0
(
a
,
b
):
"""
>>> fail0(1,2)
Traceback (most recent call last):
TypeError: f() takes exactly 2 positional arguments (0 given)
"""
f
()
def
fail1
(
a
,
b
):
"""
>>> fail1(1,2)
Traceback (most recent call last):
TypeError: f() takes exactly 2 positional arguments (1 given)
"""
f
(
a
)
def
failtype
():
"""
>>> failtype()
Traceback (most recent call last):
TypeError: an integer is required
"""
h
(
42
,
"eggs"
)
tests/run/sizeof.pyx
View file @
c8b85056
__doc__
=
u"""
>>> f()
"""
cdef
struct
Spam
:
char
*
grail
def
f
():
"""
>>> f()
"""
cdef
int
i
,
j
,
k
cdef
char
*
p
i
=
sizeof
(
p
)
...
...
tests/run/slice2.pyx
View file @
c8b85056
__doc__
=
u"""
def
f
(
obj1
,
obj2
,
obj3
,
obj4
):
"""
>>> l = [1,2,3,4]
>>> f(1, l, 2, 3)
[1, 2, 3, 4]
>>> l == f(1, l, 2, 3)
True
>>> l is f(1, l, 2, 3)
False
>>> g(1, [1,2,3,4], 2, 3)
[3, 4]
>>> h(1, [1,2,3,4], 2, 3)
[1, 2, 3]
>>> j(1, [1,2,3,4], 2, 3)
[3]
>>> slice_of_temporary_smoketest()
[3, 2]
"""
def
f
(
obj1
,
obj2
,
obj3
,
obj4
):
"""
obj1
=
obj2
[:]
return
obj1
def
g
(
obj1
,
obj2
,
obj3
,
obj4
):
"""
>>> g(1, [1,2,3,4], 2, 3)
[3, 4]
"""
obj1
=
obj2
[
obj3
:]
return
obj1
def
h
(
obj1
,
obj2
,
obj3
,
obj4
):
"""
>>> h(1, [1,2,3,4], 2, 3)
[1, 2, 3]
"""
obj1
=
obj2
[:
obj4
]
return
obj1
def
j
(
obj1
,
obj2
,
obj3
,
obj4
):
"""
>>> j(1, [1,2,3,4], 2, 3)
[3]
"""
obj1
=
obj2
[
obj3
:
obj4
]
return
obj1
...
...
@@ -41,6 +39,10 @@ class A(object):
pass
def
slice_of_temporary_smoketest
():
"""
>>> slice_of_temporary_smoketest()
[3, 2]
"""
x
=
A
()
x
.
a
=
[
1
,
2
]
x
.
a
[:]
=
[
3
,
2
]
...
...
tests/run/specialfloat.pyx
View file @
c8b85056
__doc__
=
u"""
>>> f()
12.5
>>> nan1()
nan
>>> nan2()
nan
>>> nan3()
nan
>>> float_nan
nan
>>> infp1()
inf
>>> infp1() == float('inf')
True
>>> infp2()
inf
>>> infp2() == float('inf')
True
>>> infp3()
inf
>>> infp3() == float('inf')
True
>>> float_infp
inf
>>> float_infp == float('inf')
True
>>> infn1()
-inf
>>> infn1() == float('-inf')
True
>>> infn2()
-inf
>>> infn2() == float('-inf')
True
>>> infn3()
-inf
>>> infn3() == float('-inf')
True
>>> float_infn
-inf
>>> float_infn == float('-inf')
True
>>> global_floats()[1:] == (float('+inf'), float('-inf'))
True
>>> global_floats()[0]
nan
"""
DEF
FLOAT
=
12.5
DEF
FLOAT_NAN
=
float
(
'nan'
)
DEF
FLOAT_INFP
=
float
(
'+inf'
)
...
...
@@ -65,54 +12,122 @@ float_infp = FLOAT_INFP
float_infn
=
FLOAT_INFN
def
f
():
"""
>>> f()
12.5
"""
cdef
float
f
f
=
FLOAT
return
f
def
nan1
():
"""
>>> nan1()
nan
"""
cdef
double
f
f
=
FLOAT_NAN
return
f
def
nan2
():
"""
>>> nan2()
nan
"""
cdef
double
f
f
=
float
(
'nan'
)
return
f
def
nan3
():
"""
>>> nan3()
nan
>>> float_nan
nan
"""
cdef
float
f
f
=
FLOAT_NAN
return
f
def
infp1
():
"""
>>> infp1()
inf
>>> infp1() == float('inf')
True
"""
cdef
double
f
f
=
FLOAT_INFP
return
f
def
infp2
():
"""
>>> infp2()
inf
>>> infp2() == float('inf')
True
"""
cdef
double
f
f
=
float
(
'+inf'
)
return
f
def
infp3
():
"""
>>> infp3()
inf
>>> infp3() == float('inf')
True
>>> float_infp
inf
>>> float_infp == float('inf')
True
"""
cdef
float
f
f
=
FLOAT_INFP
return
f
def
infn1
():
"""
>>> infn1()
-inf
>>> infn1() == float('-inf')
True
"""
cdef
double
f
f
=
FLOAT_INFN
return
f
def
infn2
():
"""
>>> infn2()
-inf
>>> infn2() == float('-inf')
True
"""
cdef
double
f
f
=
float
(
'-inf'
)
return
f
def
infn3
():
"""
>>> infn3()
-inf
>>> infn3() == float('-inf')
True
>>> float_infn
-inf
>>> float_infn == float('-inf')
True
"""
cdef
float
f
f
=
FLOAT_INFN
return
f
def
global_floats
():
"""
>>> global_floats()[1:] == (float('+inf'), float('-inf'))
True
>>> global_floats()[0]
nan
"""
return
(
cdef
_float_nan
,
cdef
_float_infp
,
cdef
_float_infn
)
tests/run/starargs.pyx
View file @
c8b85056
__doc__
=
u"""
cdef
sorteditems
(
d
):
l
=
list
(
d
.
items
())
l
.
sort
()
return
tuple
(
l
)
def
spam
(
x
,
y
,
z
):
"""
>>> spam(1,2,3)
(1, 2, 3)
>>> spam(1,2)
...
...
@@ -10,7 +16,11 @@ __doc__ = u"""
>>> spam(1,2,3, a=1)
Traceback (most recent call last):
TypeError: spam() got an unexpected keyword argument 'a'
"""
return
(
x
,
y
,
z
)
def
grail
(
x
,
y
,
z
,
*
a
):
"""
>>> grail(1,2,3)
(1, 2, 3, ())
>>> grail(1,2,3,4)
...
...
@@ -23,7 +33,11 @@ __doc__ = u"""
>>> grail(1,2,3, a=1)
Traceback (most recent call last):
TypeError: grail() got an unexpected keyword argument 'a'
"""
return
(
x
,
y
,
z
,
a
)
def
swallow
(
x
,
y
,
z
,
**
k
):
"""
>>> swallow(1,2,3)
(1, 2, 3, ())
>>> swallow(1,2,3,4)
...
...
@@ -34,7 +48,11 @@ __doc__ = u"""
>>> swallow(1,2,3, x=1)
Traceback (most recent call last):
TypeError: swallow() got multiple values for keyword argument 'x'
"""
return
(
x
,
y
,
z
,
sorteditems
(
k
))
def
creosote
(
x
,
y
,
z
,
*
a
,
**
k
):
"""
>>> creosote(1,2,3)
(1, 2, 3, (), ())
>>> creosote(1,2,3,4)
...
...
@@ -46,7 +64,11 @@ __doc__ = u"""
>>> creosote(1,2,3,4, x=1)
Traceback (most recent call last):
TypeError: creosote() got multiple values for keyword argument 'x'
"""
return
(
x
,
y
,
z
,
a
,
sorteditems
(
k
))
def
onlyt
(
*
a
):
"""
>>> onlyt(1)
(1,)
>>> onlyt(1,2)
...
...
@@ -57,7 +79,11 @@ __doc__ = u"""
>>> onlyt(1, a=2)
Traceback (most recent call last):
TypeError: onlyt() got an unexpected keyword argument 'a'
"""
return
a
def
onlyk
(
**
k
):
"""
>>> onlyk(a=1)
(('a', 1),)
>>> onlyk(a=1, b=2)
...
...
@@ -71,7 +97,11 @@ __doc__ = u"""
>>> onlyk(1, a=1, b=2)
Traceback (most recent call last):
TypeError: onlyk() takes exactly 0 positional arguments (1 given)
"""
return
sorteditems
(
k
)
def
tk
(
*
a
,
**
k
):
"""
>>> tk(a=1)
(('a', 1),)
>>> tk(a=1, b=2)
...
...
@@ -82,30 +112,5 @@ __doc__ = u"""
(1, 2)
>>> tk(1, a=1, b=2)
(1, ('a', 1), ('b', 2))
"""
cdef
sorteditems
(
d
):
l
=
list
(
d
.
items
())
l
.
sort
()
return
tuple
(
l
)
def
spam
(
x
,
y
,
z
):
return
(
x
,
y
,
z
)
def
grail
(
x
,
y
,
z
,
*
a
):
return
(
x
,
y
,
z
,
a
)
def
swallow
(
x
,
y
,
z
,
**
k
):
return
(
x
,
y
,
z
,
sorteditems
(
k
))
def
creosote
(
x
,
y
,
z
,
*
a
,
**
k
):
return
(
x
,
y
,
z
,
a
,
sorteditems
(
k
))
def
onlyt
(
*
a
):
return
a
def
onlyk
(
**
k
):
return
sorteditems
(
k
)
def
tk
(
*
a
,
**
k
):
"""
return
a
+
sorteditems
(
k
)
tests/run/str_char_coercion_T412.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test_eq()
True
True
True
True
>>> test_cascaded_eq()
True
True
True
True
True
True
True
True
>>> test_cascaded_ineq()
True
True
True
True
True
True
True
True
>>> test_long_ineq()
True
>>> test_long_ineq_py()
True
True
"""
cdef
int
i
=
'x'
cdef
char
c
=
'x'
cdef
char
*
s
=
'x'
def
test_eq
():
"""
>>> test_eq()
True
True
True
True
"""
print
i
==
'x'
print
i
==
c
'x'
print
c
==
'x'
...
...
@@ -46,6 +18,17 @@ def test_eq():
# print s == c'x' # error
def
test_cascaded_eq
():
"""
>>> test_cascaded_eq()
True
True
True
True
True
True
True
True
"""
print
'x'
==
i
==
'x'
print
'x'
==
i
==
c
'x'
print
c
'x'
==
i
==
'x'
...
...
@@ -57,6 +40,17 @@ def test_cascaded_eq():
print
c
'x'
==
c
==
c
'x'
def
test_cascaded_ineq
():
"""
>>> test_cascaded_ineq()
True
True
True
True
True
True
True
True
"""
print
'a'
<=
i
<=
'z'
print
'a'
<=
i
<=
c
'z'
print
c
'a'
<=
i
<=
'z'
...
...
@@ -68,8 +62,17 @@ def test_cascaded_ineq():
print
c
'a'
<=
c
<=
c
'z'
def
test_long_ineq
():
"""
>>> test_long_ineq()
True
"""
print
'a'
<
'b'
<
'c'
<
'd'
<
c
<
'y'
<
'z'
def
test_long_ineq_py
():
"""
>>> test_long_ineq_py()
True
True
"""
print
'abcdef'
<
'b'
<
'c'
<
'd'
<
'y'
<
'z'
print
'a'
<
'b'
<
'cde'
<
'd'
<
'y'
<
'z'
tests/run/strconstinclass.pyx
View file @
c8b85056
...
...
@@ -6,4 +6,3 @@ __doc__ = u"""
class
C
:
x
=
"foo"
tests/run/strfunction.pyx
View file @
c8b85056
...
...
@@ -3,29 +3,35 @@ __doc__ = u"""
'test'
>>> z
'test'
>>> c('testing')
'testing'
>>> sub('testing a subtype')
'testing a subtype'
>>> subs('testing a subtype')
'testing a subtype'
# >>> csub('testing a subtype')
# 'testing a subtype'
# >>> csubs('testing a subtype')
# 'testing a subtype'
"""
s
=
str
z
=
str
(
'test'
)
def
c
(
string
):
"""
>>> c('testing')
'testing'
"""
return
str
(
string
)
class
subs
(
str
):
"""
>>> subs('testing a subtype')
'testing a subtype'
# >>> csub('testing a subtype')
# 'testing a subtype'
# >>> csubs('testing a subtype')
# 'testing a subtype'
"""
pass
def
sub
(
string
):
"""
>>> sub('testing a subtype')
'testing a subtype'
"""
return
subs
(
string
)
#cdef class subs(str):
...
...
tests/run/struct_conversion.pyx
View file @
c8b85056
__doc__
=
u"""
cdef
struct
Point
:
double
x
double
y
int
color
def
test_constructor
(
x
,
y
,
color
):
"""
>>> test_constructor(1,2,255)
{'y': 2.0, 'x': 1.0, 'color': 255}
>>> test_constructor(1,None,255)
Traceback (most recent call last):
...
TypeError: a float is required
"""
cdef
Point
p
=
Point
(
x
,
y
,
color
)
return
p
def
test_constructor_kwds
(
x
,
y
,
color
):
"""
>>> test_constructor_kwds(1.25, 2.5, 128)
{'y': 2.5, 'x': 1.25, 'color': 128}
>>> test_constructor_kwds(1.25, 2.5, None)
Traceback (most recent call last):
...
TypeError: an integer is required
"""
cdef
Point
p
=
Point
(
x
=
x
,
y
=
y
,
color
=
color
)
return
p
def
test_dict_construction
(
x
,
y
,
color
):
"""
>>> test_dict_construction(4, 5, 64)
{'y': 5.0, 'x': 4.0, 'color': 64}
>>> test_dict_construction("foo", 5, 64)
Traceback (most recent call last):
...
TypeError: a float is required
>>> test_pointers(100, 2.71828)
100
2.71828
True
"""
cdef
struct
Point
:
double
x
double
y
int
color
def
test_constructor
(
x
,
y
,
color
):
cdef
Point
p
=
Point
(
x
,
y
,
color
)
return
p
def
test_constructor_kwds
(
x
,
y
,
color
):
cdef
Point
p
=
Point
(
x
=
x
,
y
=
y
,
color
=
color
)
return
p
def
test_dict_construction
(
x
,
y
,
color
):
"""
cdef
Point
p
=
{
'color'
:
color
,
'x'
:
x
,
'y'
:
y
}
return
p
...
...
@@ -53,6 +49,12 @@ cdef struct with_pointers:
void
*
ptr
def
test_pointers
(
int
n
,
double
x
):
"""
>>> test_pointers(100, 2.71828)
100
2.71828
True
"""
cdef
with_pointers
a
=
[
True
,
{
'n'
:
n
},
NULL
]
cdef
with_pointers
b
=
with_pointers
(
False
,
{
'x'
:
x
},
NULL
)
print
a
.
data
.
n
...
...
tests/run/subclasses.pyx
View file @
c8b85056
__doc__
=
u"""
>>> zoo = Zoo()
>>> for cl in (Zoo, Bam, Bar, Foo, Base, Base0): assert isinstance(zoo, cl)
>>> fooit(zoo)
42
>>> bam = Bam()
>>> for cl in (Bam, Bar, Foo, Base, Base0): assert isinstance(bam, cl)
>>> fooit(bam)
42
>>> bar = Bar()
>>> for cl in (Bar, Foo, Base, Base0): assert isinstance(bar, cl)
>>> fooit(bar)
42
>>> foo = Foo()
>>> for cl in (Foo, Base, Base0): assert isinstance(foo, cl)
>>> fooit(foo)
42
>>> base = Base()
>>> for cl in (Base, Base0): assert isinstance(base, cl)
>>> fooit(base)
Traceback (most recent call last):
TypeError: Argument 'foo' has incorrect type (expected subclasses.Foo, got subclasses.Base)
>>> base0 = Base0()
>>> for cl in (Base0,): assert isinstance(base0, cl)
>>> fooit(base0)
Traceback (most recent call last):
TypeError: Argument 'foo' has incorrect type (expected subclasses.Foo, got subclasses.Base0)
"""
cdef
class
Base0
:
pass
...
...
@@ -53,4 +19,32 @@ cdef class Zoo(Bam):
def
fooit
(
Foo
foo
):
"""
>>> zoo = Zoo()
>>> for cl in (Zoo, Bam, Bar, Foo, Base, Base0): assert isinstance(zoo, cl)
>>> fooit(zoo)
42
>>> bam = Bam()
>>> for cl in (Bam, Bar, Foo, Base, Base0): assert isinstance(bam, cl)
>>> fooit(bam)
42
>>> bar = Bar()
>>> for cl in (Bar, Foo, Base, Base0): assert isinstance(bar, cl)
>>> fooit(bar)
42
>>> foo = Foo()
>>> for cl in (Foo, Base, Base0): assert isinstance(foo, cl)
>>> fooit(foo)
42
>>> base = Base()
>>> for cl in (Base, Base0): assert isinstance(base, cl)
>>> fooit(base)
Traceback (most recent call last):
TypeError: Argument 'foo' has incorrect type (expected subclasses.Foo, got subclasses.Base)
>>> base0 = Base0()
>>> for cl in (Base0,): assert isinstance(base0, cl)
>>> fooit(base0)
Traceback (most recent call last):
TypeError: Argument 'foo' has incorrect type (expected subclasses.Foo, got subclasses.Base0)
"""
return
foo
.
fooit
()
tests/run/subop.pyx
View file @
c8b85056
__doc__
=
u"""
def
f
():
"""
>>> f()
(-1, -1)
>>> p()
0
"""
def
f
():
"""
cdef
int
int1
,
int2
,
int3
obj1
=
1
obj2
=
2
...
...
@@ -18,6 +15,10 @@ def f():
return
int1
,
obj1
def
p
():
"""
>>> p()
0
"""
cdef
int
int1
,
int2
,
int3
cdef
char
*
ptr1
,
*
ptr2
,
*
ptr3
int2
=
2
...
...
tests/run/switch.pyx
View file @
c8b85056
__doc__
=
u"""
>>> switch_simple_py(1)
1
>>> switch_simple_py(2)
2
>>> switch_simple_py(3)
3
>>> switch_simple_py(4)
8
>>> switch_simple_py(5)
0
>>> switch_py(1)
1
>>> switch_py(2)
2
>>> switch_py(3)
3
>>> switch_py(4)
4
>>> switch_py(5)
4
>>> switch_py(6)
0
>>> switch_py(8)
4
>>> switch_py(10)
10
>>> switch_py(12)
12
>>> switch_py(13)
0
>>> switch_simple_c(1)
1
>>> switch_simple_c(2)
2
>>> switch_simple_c(3)
3
>>> switch_simple_c(4)
8
>>> switch_simple_c(5)
0
>>> switch_c(1)
1
>>> switch_c(2)
2
>>> switch_c(3)
3
>>> switch_c(4)
4
>>> switch_c(5)
4
>>> switch_c(6)
0
>>> switch_c(8)
4
>>> switch_c(10)
10
>>> switch_c(12)
12
>>> switch_c(13)
0
>>> switch_or(0)
0
>>> switch_or(1)
1
>>> switch_or(2)
1
>>> switch_or(3)
1
>>> switch_or(4)
0
>>> switch_in(0)
0
>>> switch_in(1)
1
>>> switch_in(2)
0
>>> switch_in(7)
1
>>> switch_in(8)
0
>>> switch_short(0)
0
>>> switch_short(1)
1
>>> switch_short(2)
2
>>> switch_short(3)
0
>>> switch_off(0)
0
>>> switch_off(1)
1
>>> switch_off(2)
0
>>> switch_pass(1)
1
"""
def
switch_simple_py
(
x
):
"""
>>> switch_simple_py(1)
1
>>> switch_simple_py(2)
2
>>> switch_simple_py(3)
3
>>> switch_simple_py(4)
8
>>> switch_simple_py(5)
0
"""
if
x
==
1
:
return
1
elif
2
==
x
:
...
...
@@ -119,6 +24,28 @@ def switch_simple_py(x):
return
-
1
def
switch_py
(
x
):
"""
>>> switch_py(1)
1
>>> switch_py(2)
2
>>> switch_py(3)
3
>>> switch_py(4)
4
>>> switch_py(5)
4
>>> switch_py(6)
0
>>> switch_py(8)
4
>>> switch_py(10)
10
>>> switch_py(12)
12
>>> switch_py(13)
0
"""
if
x
==
1
:
return
1
elif
2
==
x
:
...
...
@@ -136,6 +63,18 @@ def switch_py(x):
return
-
1
def
switch_simple_c
(
int
x
):
"""
>>> switch_simple_c(1)
1
>>> switch_simple_c(2)
2
>>> switch_simple_c(3)
3
>>> switch_simple_c(4)
8
>>> switch_simple_c(5)
0
"""
if
x
==
1
:
return
1
elif
2
==
x
:
...
...
@@ -149,6 +88,28 @@ def switch_simple_c(int x):
return
-
1
def
switch_c
(
int
x
):
"""
>>> switch_c(1)
1
>>> switch_c(2)
2
>>> switch_c(3)
3
>>> switch_c(4)
4
>>> switch_c(5)
4
>>> switch_c(6)
0
>>> switch_c(8)
4
>>> switch_c(10)
10
>>> switch_c(12)
12
>>> switch_c(13)
0
"""
if
x
==
1
:
return
1
elif
2
==
x
:
...
...
@@ -166,6 +127,18 @@ def switch_c(int x):
return
-
1
def
switch_or
(
int
x
):
"""
>>> switch_or(0)
0
>>> switch_or(1)
1
>>> switch_or(2)
1
>>> switch_or(3)
1
>>> switch_or(4)
0
"""
if
x
==
1
or
x
==
2
or
x
==
3
:
return
1
else
:
...
...
@@ -173,11 +146,33 @@ def switch_or(int x):
return
-
1
def
switch_in
(
int
X
):
"""
>>> switch_in(0)
0
>>> switch_in(1)
1
>>> switch_in(2)
0
>>> switch_in(7)
1
>>> switch_in(8)
0
"""
if
X
in
(
1
,
3
,
5
,
7
):
return
1
return
0
def
switch_short
(
int
x
):
"""
>>> switch_short(0)
0
>>> switch_short(1)
1
>>> switch_short(2)
2
>>> switch_short(3)
0
"""
if
x
==
1
:
return
1
elif
2
==
x
:
...
...
@@ -187,6 +182,14 @@ def switch_short(int x):
return
-
1
def
switch_off
(
int
x
):
"""
>>> switch_off(0)
0
>>> switch_off(1)
1
>>> switch_off(2)
0
"""
if
x
==
1
:
return
1
else
:
...
...
@@ -194,6 +197,10 @@ def switch_off(int x):
return
-
1
def
switch_pass
(
int
x
):
"""
>>> switch_pass(1)
1
"""
if
x
==
1
:
pass
elif
x
==
2
:
...
...
tests/run/tandemstats.pyx
View file @
c8b85056
__doc__
=
u"""
>>> result() == (99, 17*42, 17*42)
True
"""
cdef
int
i
,
j
,
k
i
=
17
;
j
=
42
;
k
=
i
*
j
if
j
>
k
:
i
=
88
else
:
i
=
99
;
j
=
k
def
result
():
"""
>>> result() == (99, 17*42, 17*42)
True
"""
return
(
i
,
j
,
k
)
tests/run/temp_alloc_T409.pyx
View file @
c8b85056
__doc__
=
"""
>>> foo()
([0, 0], [0, 0])
"""
# Extracted from sage/plot/plot3d/index_face_set.pyx:502
# Turns out to be a bug in implementation of PEP 3132 (Extended Iterable Unpacking)
def
foo
():
"""
>>> foo()
([0, 0], [0, 0])
"""
a
=
b
=
[
0
,
0
]
return
a
,
b
tests/run/temps_corner1.pyx
View file @
c8b85056
__doc__
=
u"""
>>> B().coeffs_bitsize()
[2]
"""
cdef
class
A
:
def
numerator
(
self
):
return
self
...
...
@@ -13,6 +8,10 @@ cdef int bitsize(A a):
coeffs
=
[
A
()]
class
B
:
"""
>>> B().coeffs_bitsize()
[2]
"""
def
coeffs_bitsize
(
self
):
r
=
[
bitsize
(
c
.
numerator
())
+
1
for
c
in
coeffs
]
return
r
tests/run/ticket_124.pyx
View file @
c8b85056
__doc__
=
u"""
>>> spam(dict(test=2))
False
"""
def
spam
(
dict
d
):
"""
>>> spam(dict(test=2))
False
"""
for
elm
in
d
:
return
False
return
True
tests/run/tp_new.pyx
0 → 100644
View file @
c8b85056
cimport
cython
cdef
class
MyType
:
def
__cinit__
(
self
):
print
"CINIT"
def
__init__
(
self
):
print
"INIT"
cdef
class
MySubType
(
MyType
):
def
__cinit__
(
self
):
print
"CINIT(SUB)"
def
__init__
(
self
):
print
"INIT"
class
MyClass
(
object
):
def
__cinit__
(
self
):
print
"CINIT"
def
__init__
(
self
):
print
"INIT"
class
MyTypeSubClass
(
MyType
):
def
__cinit__
(
self
):
# not called: Python class!
print
"CINIT(PYSUB)"
def
__init__
(
self
):
print
"INIT"
# only this can be safely optimised:
@
cython
.
test_assert_path_exists
(
'//PythonCapiCallNode'
)
@
cython
.
test_fail_if_path_exists
(
'//SimpleCallNode/AttributeNode'
)
def
make_new
():
"""
>>> isinstance(make_new(), MyType)
CINIT
True
"""
m
=
MyType
.
__new__
(
MyType
)
return
m
@
cython
.
test_assert_path_exists
(
'//PythonCapiCallNode'
)
@
cython
.
test_fail_if_path_exists
(
'//SimpleCallNode/AttributeNode'
)
def
make_new_typed_target
():
"""
>>> isinstance(make_new_typed_target(), MyType)
CINIT
True
"""
cdef
MyType
m
m
=
MyType
.
__new__
(
MyType
)
return
m
@
cython
.
test_assert_path_exists
(
'//PythonCapiCallNode'
)
@
cython
.
test_fail_if_path_exists
(
'//SimpleCallNode/AttributeNode'
)
def
make_new_builtin
():
"""
>>> isinstance(make_new_builtin(), tuple)
True
"""
m
=
dict
.
__new__
(
dict
)
m
=
list
.
__new__
(
list
)
m
=
tuple
.
__new__
(
tuple
)
return
m
@
cython
.
test_assert_path_exists
(
'//PythonCapiCallNode'
)
@
cython
.
test_fail_if_path_exists
(
'//SimpleCallNode/AttributeNode'
)
def
make_new_none
(
type
t
=
None
):
"""
>>> isinstance(make_new_none(), MyType)
Traceback (most recent call last):
TypeError: object.__new__(X): X is not a type object (NoneType)
"""
m
=
t
.
__new__
(
t
)
return
m
# these cannot:
@
cython
.
test_assert_path_exists
(
'//SimpleCallNode/AttributeNode'
)
@
cython
.
test_fail_if_path_exists
(
'//PythonCapiCallNode'
)
def
make_new_pyclass
():
"""
>>> isinstance(make_new_pyclass(), MyTypeSubClass)
CINIT
True
"""
m
=
MyClass
.
__new__
(
MyClass
)
m
=
MyTypeSubClass
.
__new__
(
MyTypeSubClass
)
return
m
@
cython
.
test_assert_path_exists
(
'//SimpleCallNode/AttributeNode'
)
@
cython
.
test_fail_if_path_exists
(
'//PythonCapiCallNode'
)
def
make_new_args
(
type
t1
=
None
,
type
t2
=
None
):
"""
>>> isinstance(make_new_args(), MyType)
CINIT
True
>>> isinstance(make_new_args(MyType), MyType)
CINIT
True
>>> isinstance(make_new_args(MyType, MyType), MyType)
CINIT
True
>>> isinstance(make_new_args(MyType, MySubType), MySubType)
Traceback (most recent call last):
TypeError: tp_new.MyType.__new__(tp_new.MySubType) is not safe, use tp_new.MySubType.__new__()
>>> isinstance(make_new_args(MySubType, MyType), MyType)
Traceback (most recent call last):
TypeError: tp_new.MySubType.__new__(tp_new.MyType): tp_new.MyType is not a subtype of tp_new.MySubType
"""
if
t1
is
None
:
t1
=
MyType
if
t2
is
None
:
t2
=
MyType
m
=
t1
.
__new__
(
t2
)
return
m
@
cython
.
test_assert_path_exists
(
'//SimpleCallNode/AttributeNode'
)
@
cython
.
test_fail_if_path_exists
(
'//PythonCapiCallNode'
)
def
make_new_none_typed
(
tuple
t
=
None
):
"""
>>> isinstance(make_new_none(), MyType)
Traceback (most recent call last):
TypeError: object.__new__(X): X is not a type object (NoneType)
"""
m
=
t
.
__new__
(
t
)
return
m
@
cython
.
test_assert_path_exists
(
'//SimpleCallNode/AttributeNode'
)
@
cython
.
test_fail_if_path_exists
(
'//PythonCapiCallNode'
)
def
make_new_untyped
(
t
):
"""
>>> make_new_untyped(None)
Traceback (most recent call last):
TypeError: object.__new__(X): X is not a type object (NoneType)
"""
m
=
t
.
__new__
(
t
)
return
m
tests/run/tuple.pyx
View file @
c8b85056
__doc__
=
u"""
>>> f(1,2,3,4,5)
()
>>> g(1,2,3,4,5)
(2,)
>>> h(1,2,3,4,5)
(2, 3)
>>> j(1,2,3,4,5)
(2, 3, 4)
>>> k(1,2,3,4,5)
(2, 3, 4)
>>> l(1,2,3,4,5)
(17, 42, 88)
>>> tuple_none()
Traceback (most recent call last):
TypeError: 'NoneType' object is not iterable
>>> tuple_none_list()
Traceback (most recent call last):
TypeError: 'NoneType' object is not iterable
"""
import
sys
if
sys
.
version_info
<
(
2
,
5
):
__doc__
=
__doc__
.
replace
(
...
...
@@ -26,21 +5,37 @@ if sys.version_info < (2,5):
u'iteration over non-sequence
\
n
>>> tuple_none_list()'
)
def
f
(
obj1
,
obj2
,
obj3
,
obj4
,
obj5
):
"""
>>> f(1,2,3,4,5)
()
"""
obj1
=
()
return
obj1
def
g
(
obj1
,
obj2
,
obj3
,
obj4
,
obj5
):
"""
>>> g(1,2,3,4,5)
(2,)
"""
obj1
=
()
obj1
=
(
obj2
,)
return
obj1
def
h
(
obj1
,
obj2
,
obj3
,
obj4
,
obj5
):
"""
>>> h(1,2,3,4,5)
(2, 3)
"""
obj1
=
()
obj1
=
(
obj2
,)
obj1
=
obj2
,
obj3
return
obj1
def
j
(
obj1
,
obj2
,
obj3
,
obj4
,
obj5
):
"""
>>> j(1,2,3,4,5)
(2, 3, 4)
"""
obj1
=
()
obj1
=
(
obj2
,)
obj1
=
obj2
,
obj3
...
...
@@ -48,6 +43,10 @@ def j(obj1, obj2, obj3, obj4, obj5):
return
obj1
def
k
(
obj1
,
obj2
,
obj3
,
obj4
,
obj5
):
"""
>>> k(1,2,3,4,5)
(2, 3, 4)
"""
obj1
=
()
obj1
=
(
obj2
,)
obj1
=
obj2
,
obj3
...
...
@@ -56,6 +55,10 @@ def k(obj1, obj2, obj3, obj4, obj5):
return
obj1
def
l
(
obj1
,
obj2
,
obj3
,
obj4
,
obj5
):
"""
>>> l(1,2,3,4,5)
(17, 42, 88)
"""
obj1
=
()
obj1
=
(
obj2
,)
obj1
=
obj2
,
obj3
...
...
@@ -65,8 +68,18 @@ def l(obj1, obj2, obj3, obj4, obj5):
return
obj1
def
tuple_none
():
"""
>>> tuple_none()
Traceback (most recent call last):
TypeError: 'NoneType' object is not iterable
"""
return
tuple
(
None
)
def
tuple_none_list
():
"""
>>> tuple_none_list()
Traceback (most recent call last):
TypeError: 'NoneType' object is not iterable
"""
cdef
list
none
=
None
return
tuple
(
none
)
tests/run/tupleassign.pyx
View file @
c8b85056
__doc__
=
u"""
>>> assign3(l)
(1, 2, 3)
>>> assign3(t)
(1, 2, 3)
>>> assign3_typed(t)
(1, 2, 3)
>>> assign3_int(l)
(1, 2, 3)
>>> assign3_mixed1(l)
(1, 2, 3)
>>> assign3_mixed2(l)
(1, 2, 3)
>>> assign3_mixed3(l)
(1, 2, 3)
>>> assign3_typed(l)
Traceback (most recent call last):
TypeError: Argument 't' has incorrect type (expected tuple, got list)
>>> a,b,c = (1,) # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: ...
>>> assign3((1,))
Traceback (most recent call last):
ValueError: need more than 1 value to unpack
>>> assign3_typed((1,))
Traceback (most recent call last):
ValueError: need more than 1 value to unpack
>>> a,b,c = (1,2) # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: ...
>>> assign3((1,2))
Traceback (most recent call last):
ValueError: need more than 2 values to unpack
>>> assign3_typed((1,2))
Traceback (most recent call last):
ValueError: need more than 2 values to unpack
>>> a,b,c = (1,2,3,4)
Traceback (most recent call last):
ValueError: too many values to unpack
>>> assign3((1,2,3,4))
Traceback (most recent call last):
ValueError: too many values to unpack
>>> assign3_typed((1,2,3,4))
Traceback (most recent call last):
ValueError: too many values to unpack
>>> a,b = 99,98
>>> a,b = t
Traceback (most recent call last):
ValueError: too many values to unpack
>>> a,b
(99, 98)
>>> test_overwrite(l)
(99, 98)
>>> test_overwrite(t)
(99, 98)
>>> test_overwrite_int(l)
(99, 98)
>>> test_overwrite_int(t)
(99, 98)
>>> test_overwrite_mixed(l)
(99, 98)
>>> test_overwrite_mixed(t)
(99, 98)
>>> test_overwrite_mixed2(l)
(99, 98)
>>> test_overwrite_mixed2(t)
(99, 98)
"""
t
=
(
1
,
2
,
3
)
l
=
[
1
,
2
,
3
]
def
assign3
(
t
):
"""
>>> assign3(l)
(1, 2, 3)
>>> assign3(t)
(1, 2, 3)
>>> assign3((1,))
Traceback (most recent call last):
ValueError: need more than 1 value to unpack
>>> assign3((1,2))
Traceback (most recent call last):
ValueError: need more than 2 values to unpack
>>> assign3((1,2,3,4))
Traceback (most recent call last):
ValueError: too many values to unpack
"""
a
,
b
,
c
=
t
return
(
a
,
b
,
c
)
def
assign3_typed
(
tuple
t
):
"""
>>> assign3_typed(t)
(1, 2, 3)
>>> assign3_typed(l)
Traceback (most recent call last):
TypeError: Argument 't' has incorrect type (expected tuple, got list)
>>> a,b,c = (1,) # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: ...
>>> assign3_typed((1,))
Traceback (most recent call last):
ValueError: need more than 1 value to unpack
>>> a,b,c = (1,2) # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: ...
>>> assign3_typed((1,2))
Traceback (most recent call last):
ValueError: need more than 2 values to unpack
>>> a,b,c = (1,2,3,4)
Traceback (most recent call last):
ValueError: too many values to unpack
>>> assign3_typed((1,2,3,4))
Traceback (most recent call last):
ValueError: too many values to unpack
>>> a,b = 99,98
>>> a,b = t
Traceback (most recent call last):
ValueError: too many values to unpack
>>> a,b
(99, 98)
"""
a
,
b
,
c
=
t
return
(
a
,
b
,
c
)
def
assign3_int
(
t
):
"""
>>> assign3_int(l)
(1, 2, 3)
"""
cdef
int
a
,
b
,
c
a
,
b
,
c
=
t
return
(
a
,
b
,
c
)
def
assign3_mixed1
(
t
):
"""
>>> assign3_mixed1(l)
(1, 2, 3)
"""
cdef
int
a
a
,
b
,
c
=
t
return
(
a
,
b
,
c
)
def
assign3_mixed2
(
t
):
"""
>>> assign3_mixed2(l)
(1, 2, 3)
"""
cdef
int
b
a
,
b
,
c
=
t
return
(
a
,
b
,
c
)
def
assign3_mixed3
(
t
):
"""
>>> assign3_mixed3(l)
(1, 2, 3)
"""
cdef
int
c
a
,
b
,
c
=
t
return
(
a
,
b
,
c
)
...
...
@@ -113,6 +97,12 @@ def assign3_mixed4(t):
return
(
a
,
b
,
c
)
def
test_overwrite
(
t
):
"""
>>> test_overwrite(l)
(99, 98)
>>> test_overwrite(t)
(99, 98)
"""
a
,
b
=
99
,
98
try
:
a
,
b
=
t
...
...
@@ -121,6 +111,12 @@ def test_overwrite(t):
return
(
a
,
b
)
def
test_overwrite_int
(
t
):
"""
>>> test_overwrite_int(l)
(99, 98)
>>> test_overwrite_int(t)
(99, 98)
"""
cdef
int
a
,
b
a
,
b
=
99
,
98
try
:
...
...
@@ -130,6 +126,12 @@ def test_overwrite_int(t):
return
(
a
,
b
)
def
test_overwrite_mixed
(
t
):
"""
>>> test_overwrite_mixed(l)
(99, 98)
>>> test_overwrite_mixed(t)
(99, 98)
"""
cdef
int
b
a
,
b
=
99
,
98
try
:
...
...
@@ -139,6 +141,12 @@ def test_overwrite_mixed(t):
return
(
a
,
b
)
def
test_overwrite_mixed2
(
t
):
"""
>>> test_overwrite_mixed2(l)
(99, 98)
>>> test_overwrite_mixed2(t)
(99, 98)
"""
cdef
int
a
a
,
b
=
99
,
98
try
:
...
...
tests/run/tuplereassign.pyx
View file @
c8b85056
__doc__
=
u"""
def
test1
(
t
):
"""
>>> test1( (1,2,3) )
1
>>> test3( (1,2,3) )
3
>>> test( (1,2,3) )
3
>>> testnonsense() # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...
"""
def
test1
(
t
):
"""
t
,
a
,
b
=
t
return
t
def
test3
(
t
):
"""
>>> test3( (1,2,3) )
3
"""
a
,
b
,
t
=
t
return
t
def
test
(
t
):
"""
>>> test( (1,2,3) )
3
"""
t
,
t
,
t
=
t
return
t
def
testnonsense
():
"""
>>> testnonsense() # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ...
"""
t
,
t
,
t
=
1
*
2
return
t
tests/run/type_inference.pyx
View file @
c8b85056
# cython: infer_types = True
__doc__
=
u"""
>>> simple()
>>> multiple_assignments()
>>> arithmatic()
>>> cascade()
>>> increment()
>>> loop()
"""
from
cython
cimport
typeof
def
simple
():
"""
>>> simple()
"""
i
=
3
assert
typeof
(
i
)
==
"long"
,
typeof
(
i
)
x
=
1.41
...
...
@@ -32,6 +27,9 @@ def simple():
assert
typeof
(
t
)
==
"tuple object"
,
typeof
(
t
)
def
multiple_assignments
():
"""
>>> multiple_assignments()
"""
a
=
3
a
=
4
a
=
5
...
...
@@ -46,6 +44,9 @@ def multiple_assignments():
assert
typeof
(
c
)
==
"Python object"
def
arithmatic
():
"""
>>> arithmatic()
"""
a
=
1
+
2
assert
typeof
(
a
)
==
"long"
b
=
1
+
1.5
...
...
@@ -56,6 +57,9 @@ def arithmatic():
assert
typeof
(
d
)
==
"Python object"
def
cascade
():
"""
>>> cascade()
"""
a
=
1.0
b
=
a
+
2
c
=
b
+
3
...
...
@@ -74,11 +78,17 @@ def cascaded_assignment():
assert
typeof
(
e
)
==
"double"
def
increment
():
"""
>>> increment()
"""
a
=
5
a
+=
1
assert
typeof
(
a
)
==
"long"
def
loop
():
"""
>>> loop()
"""
for
a
in
range
(
10
):
pass
assert
typeof
(
a
)
==
"long"
...
...
tests/run/type_slots_int_long_T287.pyx
View file @
c8b85056
...
...
@@ -10,34 +10,37 @@ __doc__ = u"""
>>> print( "%d" % IntLongC() )
3
>>> getint( Int() )
2
>>> getint( Long() )
3
>>> getint( IntLongA() )
2
>>> getint( IntLongB() )
2
>>> getint( IntLongC() )
3
>>> getlong( Int() )
2
>>> getlong( Long() )
3
>>> getlong( IntLongA() )
2
>>> getlong( IntLongB() )
2
>>> getlong( IntLongC() )
3
"""
def
getint
(
int
i
):
"""
>>> getint( Int() )
2
>>> getint( Long() )
3
>>> getint( IntLongA() )
2
>>> getint( IntLongB() )
2
>>> getint( IntLongC() )
3
"""
return
i
def
getlong
(
long
long
i
):
"""
>>> getlong( Int() )
2
>>> getlong( Long() )
3
>>> getlong( IntLongA() )
2
>>> getlong( IntLongB() )
2
>>> getlong( IntLongC() )
3
"""
return
<
int
>
i
...
...
tests/run/typed_slice.pyx
View file @
c8b85056
__doc__
=
u"""
>>> l = [1,2,3,4]
>>> slice_list(l)
[2, 3]
>>> slice_tuple(tuple(l))
(2, 3)
>>> l2 = l[:]
>>> slice_list_assign_list(l2)
[1, 1, 2, 3, 4, 4]
>>> l2 = l[:]
>>> slice_list_assign_tuple(l2)
[1, 1, 2, 3, 4, 4]
>>> l2 = l[:]
>>> slice_list_assign(l2, (1,2,3,4))
[1, 1, 2, 3, 4, 4]
>>> l2 = l[:]
>>> slice_list_assign(l2, dict(zip(l,l)))
[1, 1, 2, 3, 4, 4]
>>> print("%s" % slice_charp('abcdefg'))
bc
>>> print("%s" % slice_charp_repeat('abcdefg'))
cd
"""
def
slice_list
(
list
l
):
"""
>>> slice_list([1,2,3,4])
[2, 3]
"""
return
l
[
1
:
3
]
def
slice_list_copy
(
list
l
):
...
...
@@ -36,27 +10,63 @@ def slice_list_copy(list l):
return
retlist
def
slice_tuple
(
tuple
t
):
"""
>>> l = [1,2,3,4]
>>> slice_tuple(tuple(l))
(2, 3)
"""
return
t
[
1
:
3
]
def
slice_list_assign_list
(
list
l
):
"""
>>> l = [1,2,3,4]
>>> l2 = l[:]
>>> slice_list_assign_list(l2)
[1, 1, 2, 3, 4, 4]
"""
l
[
1
:
3
]
=
[
1
,
2
,
3
,
4
]
return
l
def
slice_list_assign_tuple
(
list
l
):
"""
>>> l = [1,2,3,4]
>>> l2 = l[:]
>>> slice_list_assign_tuple(l2)
[1, 1, 2, 3, 4, 4]
"""
l
[
1
:
3
]
=
(
1
,
2
,
3
,
4
)
return
l
def
slice_list_assign
(
list
l
,
value
):
"""
>>> l = [1,2,3,4]
>>> l2 = l[:]
>>> slice_list_assign(l2, (1,2,3,4))
[1, 1, 2, 3, 4, 4]
>>> l2 = l[:]
>>> slice_list_assign(l2, dict(zip(l,l)))
[1, 1, 2, 3, 4, 4]
"""
l
[
1
:
3
]
=
value
return
l
def
slice_charp
(
py_string_arg
):
"""
>>> l = [1,2,3,4]
>>> print("%s" % slice_charp('abcdefg'))
bc
"""
cdef
bytes
py_string
=
py_string_arg
.
encode
(
u'ASCII'
)
cdef
char
*
s
=
py_string
return
s
[
1
:
3
].
decode
(
u'ASCII'
)
def
slice_charp_repeat
(
py_string_arg
):
"""
>>> l = [1,2,3,4]
>>> print("%s" % slice_charp_repeat('abcdefg'))
cd
"""
cdef
bytes
py_string
=
py_string_arg
.
encode
(
u'ASCII'
)
cdef
char
*
s
=
py_string
cdef
bytes
slice_val
=
s
[
1
:
6
]
...
...
tests/run/typedfieldbug_T303.pyx
View file @
c8b85056
__doc__
=
u"""
>>> f()
42.0
42.0
>>> global_vars(12.0)
12.0 12.0
__doc__
=
"""
>>> readonly()
Traceback (most recent call last):
...
...
TypeError: readonly attribute
>>> longdouble_access()
Traceback (most recent call last):
...
SystemError: bad memberdescr type
"""
import
sys
...
...
@@ -38,17 +29,32 @@ cdef class MyClass:
self
.
float_isreally_longdouble
=
42.0
def
global_vars
(
x
):
"""
>>> global_vars(12.0)
12.0 12.0
"""
global
global_tdef
,
global_double
global_tdef
=
x
global_double
=
x
print
global_tdef
,
global_double
def
f
():
"""
>>> f()
42.0
42.0
"""
c
=
MyClass
()
print
c
.
actual_double
print
c
.
float_isreally_double
def
longdouble_access
():
"""
>>> longdouble_access()
Traceback (most recent call last):
...
SystemError: bad memberdescr type
"""
c
=
MyClass
()
print
c
.
float_isreally_longdouble
...
...
@@ -56,4 +62,3 @@ def longdouble_access():
def
readonly
():
c
=
MyClass
()
c
.
actual_double
=
3
tests/run/typeof.pyx
View file @
c8b85056
__doc__
=
u"""
>>> simple()
int
long
long long
int *
int **
A
B
X
Python object
>>> expression()
double
double complex
int
unsigned int
"""
from
cython
cimport
typeof
cdef
class
A
:
...
...
@@ -30,6 +11,18 @@ cdef struct X:
double
complex
b
def
simple
():
"""
>>> simple()
int
long
long long
int *
int **
A
B
X
Python object
"""
cdef
int
i
=
0
cdef
long
l
=
0
cdef
long
long
ll
=
0
...
...
@@ -50,6 +43,13 @@ def simple():
used
=
i
,
l
,
ll
,
<
long
>
iptr
,
<
long
>
iptrptr
,
a
,
b
,
x
def
expression
():
"""
>>> expression()
double
double complex
int
unsigned int
"""
cdef
X
x
=
X
(
a
=
1
,
b
=
2
)
cdef
X
*
xptr
=
&
x
cdef
short
s
=
0
...
...
tests/run/unop.pyx
View file @
c8b85056
__doc__
=
u"""
def
f
(
obj1
,
obj2
,
obj3
):
"""
>>> f(1, 2, 3)
(-3, -4, 1)
"""
def
f
(
obj1
,
obj2
,
obj3
):
"""
cdef
int
bool1
,
bool2
cdef
int
int1
,
int2
cdef
char
*
str1
...
...
tests/run/unpack.pyx
View file @
c8b85056
__doc__
=
u"""
def
f
(
obj1
,
obj2
,
obj3
,
obj4
,
obj5
):
"""
>>> f(1, (2,), (3,4,5), (6,(7,(8,9))), 0)
(8, 9, (8, 9), (6, (7, (8, 9))), 0)
"""
def
f
(
obj1
,
obj2
,
obj3
,
obj4
,
obj5
):
"""
obj1
,
=
obj2
obj1
,
obj2
=
obj2
+
obj2
obj1
,
obj2
,
obj3
=
obj3
...
...
tests/run/unpacklistcomp.pyx
View file @
c8b85056
__doc__
=
u"""
def
unpack_normal
(
l
):
"""
>>> unpack_normal([1,2])
(1, 2)
>>> unpack_normal([1,2,3]) # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: ...
"""
a
,
b
=
l
return
a
,
b
def
unpack_comp
(
l
):
"""
>>> unpack_comp([1,2])
(1, 2)
>>> unpack_comp([1,2,3]) # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: ...
"""
a
,
b
=
[
n
for
n
in
l
]
return
a
,
b
def
unpack_expr
(
l
):
"""
>>> unpack_expr([1,2])
(1, 4)
>>> unpack_expr([1,2,3]) # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: ...
"""
def
unpack_normal
(
l
):
a
,
b
=
l
return
a
,
b
def
unpack_comp
(
l
):
a
,
b
=
[
n
for
n
in
l
]
return
a
,
b
def
unpack_expr
(
l
):
"""
a
,
b
=
[
n
*
n
for
n
in
l
]
return
a
,
b
tests/run/varargcall.pyx
View file @
c8b85056
__doc__
=
u"""
>>> swallow()
"""
cdef
grail
(
char
*
blarg
,
...):
pass
def
swallow
():
"""
>>> swallow()
"""
grail
(
"spam"
)
grail
(
"spam"
,
42
)
tests/run/varargdecl.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test()
"""
cdef
grail
(
char
*
blarg
,
...):
pass
def
test
():
"""
>>> test()
"""
grail
(
b"test"
)
grail
(
b"test"
,
b"toast"
)
tests/run/watts1.pyx
View file @
c8b85056
__doc__
=
u"""
>>> test() == 55 + 66
True
"""
def
test
():
"""
>>> test() == 55 + 66
True
"""
cdef
int
a
,
b
foo
=
(
55
,
66
)
a
,
b
=
foo
...
...
tests/run/withnogil.pyx
View file @
c8b85056
__doc__
=
u"""
def
f
(
x
):
"""
>>> f(1)
(1, 17)
>>> g()
1
"""
def
f
(
x
):
"""
cdef
int
y
z
=
42
with
nogil
:
...
...
@@ -14,6 +11,10 @@ def f(x):
return
z
,
y
def
g
():
"""
>>> g()
1
"""
with
nogil
:
h
()
return
1
...
...
tests/run/withstat.pyx
View file @
c8b85056
from
__future__
import
with_statement
__doc__
=
u"""
>>> no_as()
enter
hello
exit <type 'NoneType'> <type 'NoneType'> <type 'NoneType'>
>>> basic()
enter
value
exit <type 'NoneType'> <type 'NoneType'> <type 'NoneType'>
>>> with_return()
enter
exit <type 'NoneType'> <type 'NoneType'> <type 'NoneType'>
>>> with_pass()
enter
exit <type 'NoneType'> <type 'NoneType'> <type 'NoneType'>
>>> with_exception(None)
enter
value
exit <type 'type'> <type 'MyException'> <type 'traceback'>
outer except
>>> with_exception(True)
enter
value
exit <type 'type'> <type 'MyException'> <type 'traceback'>
>>> multitarget()
enter
1 2 3 4 5
exit <type 'NoneType'> <type 'NoneType'> <type 'NoneType'>
>>> tupletarget()
enter
(1, 2, (3, (4, 5)))
exit <type 'NoneType'> <type 'NoneType'> <type 'NoneType'>
>>> typed()
enter
10
exit <type 'NoneType'> <type 'NoneType'> <type 'NoneType'>
"""
import
sys
if
sys
.
version_info
<
(
2
,
5
):
...
...
@@ -63,24 +26,57 @@ class ContextManager(object):
return
self
.
value
def
no_as
():
"""
>>> no_as()
enter
hello
exit <type 'NoneType'> <type 'NoneType'> <type 'NoneType'>
"""
with
ContextManager
(
u"value"
):
print
u"hello"
def
basic
():
"""
>>> basic()
enter
value
exit <type 'NoneType'> <type 'NoneType'> <type 'NoneType'>
"""
with
ContextManager
(
u"value"
)
as
x
:
print
x
def
with_pass
():
"""
>>> with_pass()
enter
exit <type 'NoneType'> <type 'NoneType'> <type 'NoneType'>
"""
with
ContextManager
(
u"value"
)
as
x
:
pass
def
with_return
():
"""
>>> with_return()
enter
exit <type 'NoneType'> <type 'NoneType'> <type 'NoneType'>
"""
with
ContextManager
(
u"value"
)
as
x
:
# FIXME: DISABLED - currently crashes!!
# return x
pass
def
with_exception
(
exit_ret
):
"""
>>> with_exception(None)
enter
value
exit <type 'type'> <type 'MyException'> <type 'traceback'>
outer except
>>> with_exception(True)
enter
value
exit <type 'type'> <type 'MyException'> <type 'traceback'>
"""
try
:
with
ContextManager
(
u"value"
,
exit_ret
=
exit_ret
)
as
value
:
print
value
...
...
@@ -89,14 +85,32 @@ def with_exception(exit_ret):
print
u"outer except"
def
multitarget
():
"""
>>> multitarget()
enter
1 2 3 4 5
exit <type 'NoneType'> <type 'NoneType'> <type 'NoneType'>
"""
with
ContextManager
((
1
,
2
,
(
3
,
(
4
,
5
))))
as
(
a
,
b
,
(
c
,
(
d
,
e
))):
print
a
,
b
,
c
,
d
,
e
def
tupletarget
():
"""
>>> tupletarget()
enter
(1, 2, (3, (4, 5)))
exit <type 'NoneType'> <type 'NoneType'> <type 'NoneType'>
"""
with
ContextManager
((
1
,
2
,
(
3
,
(
4
,
5
))))
as
t
:
print
t
def
typed
():
"""
>>> typed()
enter
10
exit <type 'NoneType'> <type 'NoneType'> <type 'NoneType'>
"""
cdef
unsigned
char
i
c
=
ContextManager
(
255
)
with
c
as
i
:
...
...
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