summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorda-woods <dw-git@d-woods.co.uk>2020-03-24 18:45:05 +0000
committerGitHub <noreply@github.com>2020-03-24 19:45:05 +0100
commit606b4f447d098d3f8f169f68696a96418d089e80 (patch)
treee86492affcdd031ddb5730913cfcf734f90cb533
parent05f7a479f6417716b3de2a9559f2724013af6eba (diff)
downloadcython-606b4f447d098d3f8f169f68696a96418d089e80.tar.gz
Mark view.* extension types as non-imported so that they can be inherited from. (GH-3413)
-rw-r--r--Cython/Compiler/CythonScope.py9
-rw-r--r--Cython/Compiler/ModuleNode.py3
-rw-r--r--Cython/Compiler/PyrexTypes.py1
-rw-r--r--tests/memoryview/cythonarray.pyx8
4 files changed, 20 insertions, 1 deletions
diff --git a/Cython/Compiler/CythonScope.py b/Cython/Compiler/CythonScope.py
index 1c25d1a6b..8085d1890 100644
--- a/Cython/Compiler/CythonScope.py
+++ b/Cython/Compiler/CythonScope.py
@@ -127,6 +127,15 @@ class CythonScope(ModuleScope):
self.viewscope, cython_scope=self,
whitelist=MemoryView.view_utility_whitelist)
+ # Marks the types as being cython_builtin_type so that they can be
+ # extended from without Cython attempting to import cython.view
+ ext_types = [ entry.type
+ for entry in view_utility_scope.entries.values()
+ if entry.type.is_extension_type ]
+ for ext_type in ext_types:
+ ext_type.is_cython_builtin_type = 1
+
+
# self.entries["array"] = view_utility_scope.entries.pop("array")
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py
index f398cb443..f86c76a89 100644
--- a/Cython/Compiler/ModuleNode.py
+++ b/Cython/Compiler/ModuleNode.py
@@ -3379,7 +3379,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
def generate_base_type_import_code(self, env, entry, code, import_generator):
base_type = entry.type.base_type
if (base_type and base_type.module_name != env.qualified_name and not
- base_type.is_builtin_type and not entry.utility_code_definition):
+ (base_type.is_builtin_type or base_type.is_cython_builtin_type)
+ and not entry.utility_code_definition):
self.generate_type_import_code(env, base_type, self.pos, code, import_generator)
def generate_type_import_code(self, env, type, pos, code, import_generator):
diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py
index a52debf55..7abb4e569 100644
--- a/Cython/Compiler/PyrexTypes.py
+++ b/Cython/Compiler/PyrexTypes.py
@@ -229,6 +229,7 @@ class PyrexType(BaseType):
is_extension_type = 0
is_final_type = 0
is_builtin_type = 0
+ is_cython_builtin_type = 0
is_numeric = 0
is_int = 0
is_float = 0
diff --git a/tests/memoryview/cythonarray.pyx b/tests/memoryview/cythonarray.pyx
index 1f87a4e18..098b18aac 100644
--- a/tests/memoryview/cythonarray.pyx
+++ b/tests/memoryview/cythonarray.pyx
@@ -209,3 +209,11 @@ def test_cyarray_from_carray():
mslice = a
print mslice[0, 0], mslice[1, 0], mslice[2, 5]
+
+class InheritFrom(v.array):
+ """
+ Test is just to confirm it works, not to do anything meaningful with it
+ (Be aware that itemsize isn't necessarily right)
+ >>> inst = InheritFrom(shape=(3, 3, 3), itemsize=4, format="i")
+ """
+ pass