Commit 429c0b96 authored by Robert Bradshaw's avatar Robert Bradshaw

Merge branch 'master' of github.com:cython/cython

parents 56304494 d0c1a7a2
...@@ -47,6 +47,8 @@ Other changes ...@@ -47,6 +47,8 @@ Other changes
To try parsing your files against this grammar, use the --formal_grammar directive. To try parsing your files against this grammar, use the --formal_grammar directive.
Experimental. Experimental.
* ``_`` is no longer considered a cacheable builtin as it could interfere with gettext.
0.21.2 (2014-12-27) 0.21.2 (2014-12-27)
=================== ===================
......
...@@ -50,14 +50,15 @@ non_portable_builtins_map = { ...@@ -50,14 +50,15 @@ non_portable_builtins_map = {
basicsize_builtins_map = { basicsize_builtins_map = {
# builtins whose type has a different tp_basicsize than sizeof(...) # builtins whose type has a different tp_basicsize than sizeof(...)
'PyTypeObject' : 'PyHeapTypeObject', 'PyTypeObject': 'PyHeapTypeObject',
} }
uncachable_builtins = [ uncachable_builtins = [
# builtin names that cannot be cached because they may or may not # builtin names that cannot be cached because they may or may not
# be available at import time # be available at import time
'WindowsError', 'WindowsError',
] '_', # e.g. gettext
]
modifier_output_mapper = { modifier_output_mapper = {
'inline': 'CYTHON_INLINE' 'inline': 'CYTHON_INLINE'
......
...@@ -5069,6 +5069,8 @@ class InlinedDefNodeCallNode(CallNode): ...@@ -5069,6 +5069,8 @@ class InlinedDefNodeCallNode(CallNode):
return False return False
if len(func_type.args) != len(self.args): if len(func_type.args) != len(self.args):
return False return False
if func_type.num_kwonly_args:
return False # actually wrong number of arguments
return True return True
def analyse_types(self, env): def analyse_types(self, env):
...@@ -7810,6 +7812,14 @@ class PyCFunctionNode(ExprNode, ModuleNameMixin): ...@@ -7810,6 +7812,14 @@ class PyCFunctionNode(ExprNode, ModuleNameMixin):
if not arg.annotation.type.is_pyobject: if not arg.annotation.type.is_pyobject:
arg.annotation = arg.annotation.coerce_to_pyobject(env) arg.annotation = arg.annotation.coerce_to_pyobject(env)
annotations.append((arg.pos, arg.name, arg.annotation)) annotations.append((arg.pos, arg.name, arg.annotation))
for arg in (self.def_node.star_arg, self.def_node.starstar_arg):
if arg and arg.annotation:
arg.annotation = arg.annotation.analyse_types(env)
if not arg.annotation.type.is_pyobject:
arg.annotation = arg.annotation.coerce_to_pyobject(env)
annotations.append((arg.pos, arg.name, arg.annotation))
if self.def_node.return_type_annotation: if self.def_node.return_type_annotation:
annotations.append((self.def_node.return_type_annotation.pos, annotations.append((self.def_node.return_type_annotation.pos,
StringEncoding.EncodedString("return"), StringEncoding.EncodedString("return"),
......
...@@ -212,6 +212,9 @@ class _XMLTestResult(_TextTestResult): ...@@ -212,6 +212,9 @@ class _XMLTestResult(_TextTestResult):
for tests in (self.successes, self.failures, self.errors): for tests in (self.successes, self.failures, self.errors):
for test_info in tests: for test_info in tests:
if not isinstance(test_info, _TestInfo):
print("Unexpected test result type: %s" % test_info)
continue
testcase = type(test_info.test_method) testcase = type(test_info.test_method)
# Ignore module name if it is '__main__' # Ignore module name if it is '__main__'
......
...@@ -62,7 +62,7 @@ With additional type declarations, this might look like:: ...@@ -62,7 +62,7 @@ With additional type declarations, this might look like::
Since the iterator variable ``i`` is typed with C semantics, the for-loop will be compiled Since the iterator variable ``i`` is typed with C semantics, the for-loop will be compiled
to pure C code. Typing ``a``, ``s`` and ``dx`` is important as they are involved to pure C code. Typing ``a``, ``s`` and ``dx`` is important as they are involved
in arithmetic withing the for-loop; typing ``b`` and ``N`` makes less of a in arithmetic within the for-loop; typing ``b`` and ``N`` makes less of a
difference, but in this case it is not much extra work to be difference, but in this case it is not much extra work to be
consistent and type the entire function. consistent and type the entire function.
......
...@@ -37,6 +37,9 @@ def test_func_signature(a): ...@@ -37,6 +37,9 @@ def test_func_signature(a):
""" """
>>> test_func_signature(Foo()) >>> test_func_signature(Foo())
<Foo> <Foo>
>>> test_func_signature(123)
Traceback (most recent call last):
TypeError: Cannot convert int to closure_inlining.Foo
""" """
def inner(Foo a): def inner(Foo a):
...@@ -49,6 +52,9 @@ def test_func_signature2(a, b): ...@@ -49,6 +52,9 @@ def test_func_signature2(a, b):
""" """
>>> test_func_signature2(Foo(), 123) >>> test_func_signature2(Foo(), 123)
(<Foo>, 123) (<Foo>, 123)
>>> test_func_signature2(321, 123)
Traceback (most recent call last):
TypeError: Cannot convert int to closure_inlining.Foo
""" """
def inner(Foo a, b): def inner(Foo a, b):
...@@ -66,6 +72,27 @@ def test_defaults(a, b): ...@@ -66,6 +72,27 @@ def test_defaults(a, b):
return a, b, c return a, b, c
return inner(a) return inner(a)
@cython.test_assert_path_exists('//SimpleCallNode')
def test_kwonly_args(a, b):
"""
>>> test_kwonly_args(1, 2)
(1, 2, 123)
"""
def inner(a, b=b, *, c=123):
return a, b, c
return inner(a)
@cython.test_assert_path_exists('//SimpleCallNode')
def test_kwonly_args_missing(a, b):
"""
>>> test_kwonly_args_missing(1, 2)
Traceback (most recent call last):
TypeError: inner() needs keyword-only argument c
"""
def inner(a, b=b, *, c):
return a, b, c
return inner(a)
@cython.test_assert_path_exists('//SimpleCallNode') @cython.test_assert_path_exists('//SimpleCallNode')
def test_starred(a): def test_starred(a):
""" """
......
# cython: language_level=3 # cython: language_level=3, binding=True
# mode: run # mode: run
# tag: generators, python3, exceptions # tag: generators, python3, exceptions
...@@ -437,11 +437,24 @@ def int_literals(): ...@@ -437,11 +437,24 @@ def int_literals():
print(cython.typeof(1UL)) print(cython.typeof(1UL))
print(cython.typeof(10000000000000UL)) print(cython.typeof(10000000000000UL))
def annotation_syntax(a : "test new test", b : "other" = 2) -> "ret": def annotation_syntax(a: "test new test", b : "other" = 2, *args: "ARGS", **kwargs: "KWARGS") -> "ret":
""" """
>>> annotation_syntax(1) >>> annotation_syntax(1)
3 3
>>> annotation_syntax(1,3) >>> annotation_syntax(1,3)
4 4
>>> len(annotation_syntax.__annotations__)
5
>>> print(annotation_syntax.__annotations__['a'])
test new test
>>> print(annotation_syntax.__annotations__['b'])
other
>>> print(annotation_syntax.__annotations__['args'])
ARGS
>>> print(annotation_syntax.__annotations__['kwargs'])
KWARGS
>>> print(annotation_syntax.__annotations__['return'])
ret
""" """
return a+b return a+b
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment