summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2017-10-29 20:01:43 +0100
committerStefan Behnel <stefan_ml@behnel.de>2017-10-29 20:01:43 +0100
commit949b413351dc7b638420abcc3e35c68cea3d8b7b (patch)
tree6b3236b9039fec0fe1db10977453ce88989466a5
parent5e6ca03861d559e7542633b781babd39735d043e (diff)
parenteb270f7e763f6f2313da447addfb4a29425d8672 (diff)
downloadcython-949b413351dc7b638420abcc3e35c68cea3d8b7b.tar.gz
Merge branch '0.27.x'
-rw-r--r--CHANGES.rst3
-rw-r--r--Cython/Compiler/ExprNodes.py5
-rw-r--r--tests/run/pure.pyx20
3 files changed, 28 insertions, 0 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 71a778ae4..6706ab165 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -50,6 +50,9 @@ Other changes
Bugs fixed
----------
+* String forward references to extension types like ``@cython.locals(x="ExtType")``
+ failed to find the named type. (Github issue #1962)
+
* NumPy slicing generated incorrect results when compiled with Pythran.
(Github issue #1946)
diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py
index da058b4f0..422639668 100644
--- a/Cython/Compiler/ExprNodes.py
+++ b/Cython/Compiler/ExprNodes.py
@@ -1362,6 +1362,11 @@ def _analyse_name_as_type(name, pos, env):
type = PyrexTypes.parse_basic_type(name)
if type is not None:
return type
+
+ global_entry = env.global_scope().lookup_here(name)
+ if global_entry and global_entry.type and global_entry.type.is_extension_type:
+ return global_entry.type
+
from .TreeFragment import TreeFragment
with local_errors(ignore=True):
pos = (pos[0], pos[1], pos[2]-7)
diff --git a/tests/run/pure.pyx b/tests/run/pure.pyx
index 0ad7772db..57a575a33 100644
--- a/tests/run/pure.pyx
+++ b/tests/run/pure.pyx
@@ -160,3 +160,23 @@ def test_declare_c_types(n):
#z01 = cython.declare(cython.floatcomplex, n+1j)
#z02 = cython.declare(cython.doublecomplex, n+1j)
#z03 = cython.declare(cython.longdoublecomplex, n+1j)
+
+
+cdef class ExtType:
+ """
+ >>> x = ExtType()
+ >>> x.forward_ref(x)
+ 'ExtType'
+ """
+ @cython.locals(x="ExtType")
+ def forward_ref(self, x):
+ return cython.typeof(x)
+
+
+def ext_type_string_ref(x: "ExtType"):
+ """
+ >>> x = ExtType()
+ >>> ext_type_string_ref(x)
+ 'ExtType'
+ """
+ return cython.typeof(x)