Commit 4326a3b9 authored by Stefan Behnel's avatar Stefan Behnel

Allow arbitrary annotations again with "annotation_typing=False", not only valid types.

parent acd03a26
......@@ -35,6 +35,9 @@ Bugs fixed
* Cython annotation types in Python files could lead to import failures
with a "cython undefined" error. Recognised types are now turned into strings.
* Annotations could be parsed (and rejected) as types even with
``annotation_typing=False``.
0.27 (2017-09-23)
=================
......
......@@ -1657,7 +1657,7 @@ class FuncDefNode(StatNode, BlockNode):
# Annotations can not only contain valid Python expressions but arbitrary type references.
if annotation is None:
return None
if annotation.analyse_as_type(env) is None:
if not env.directives['annotation_typing'] or annotation.analyse_as_type(env) is None:
annotation = annotation.analyse_types(env)
return annotation
......
#cython: embedsignature=True
#cython: embedsignature=True, annotation_typing=False
import sys
......@@ -81,7 +81,7 @@ __doc__ = ur"""
Ext.m(self, a=u'spam')
>>> print (Ext.n.__doc__)
Ext.n(self, a: int, double b: float = 1.0, *args: tuple, **kwargs: dict) -> (None, True)
Ext.n(self, a: int, b: float = 1.0, *args: tuple, **kwargs: dict) -> (None, True)
>>> print (Ext.get_int.__doc__)
Ext.get_int(self) -> int
......@@ -403,8 +403,7 @@ cdef class Foo:
def m03(self, a: 42, b: +42, c: -42) -> int : pass # XXX +42 -> 42
def m04(self, a: 3.14, b: +3.14, c: -3.14) -> float : pass
def m05(self, a: 1 + 2j, b: +2j, c: -2j) -> complex : pass
# this is not a valid PEP 484 declaration, and Cython interprets it as a C-tuple
#def m06(self, a: "abc", b: b"abc", c: u"abc") -> (str, bytes, unicode) : pass
def m06(self, a: "abc", b: b"abc", c: u"abc") -> (str, bytes, unicode) : pass
def m07(self, a: [1, 2, 3], b: []) -> list: pass
def m08(self, a: (1, 2, 3), b: ()) -> tuple: pass
def m09(self, a: {1, 2, 3}, b: {i for i in ()}) -> set: pass
......@@ -449,8 +448,8 @@ Foo.m04(self, a: 3.14, b: 3.14, c: -3.14) -> float
>>> print(Foo.m05.__doc__)
Foo.m05(self, a: 1 + 2j, b: +2j, c: -2j) -> complex
#>>> print(Foo.m06.__doc__)
#Foo.m06(self, a: 'abc', b: b'abc', c: u'abc') -> (str, bytes, unicode)
>>> print(Foo.m06.__doc__)
Foo.m06(self, a: 'abc', b: b'abc', c: u'abc') -> (str, bytes, unicode)
>>> print(Foo.m07.__doc__)
Foo.m07(self, a: [1, 2, 3], b: []) -> list
......
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