Commit 4d115ea6 authored by Stefan Behnel's avatar Stefan Behnel

create intermediate parent module chain when cimporting from a sub-package

parent 22f67f24
...@@ -1161,16 +1161,28 @@ class ModuleScope(Scope): ...@@ -1161,16 +1161,28 @@ class ModuleScope(Scope):
def find_submodule(self, name): def find_submodule(self, name):
# Find and return scope for a submodule of this module, # Find and return scope for a submodule of this module,
# creating a new empty one if necessary. Doesn't parse .pxd. # creating a new empty one if necessary. Doesn't parse .pxd.
if '.' in name:
name, submodule = name.split('.', 1)
else:
submodule = None
scope = self.lookup_submodule(name) scope = self.lookup_submodule(name)
if not scope: if not scope:
scope = ModuleScope(name, scope = ModuleScope(name, parent_module=self, context=self.context)
parent_module = self, context = self.context)
self.module_entries[name] = scope self.module_entries[name] = scope
if submodule:
scope = scope.find_submodule(submodule)
return scope return scope
def lookup_submodule(self, name): def lookup_submodule(self, name):
# Return scope for submodule of this module, or None. # Return scope for submodule of this module, or None.
return self.module_entries.get(name, None) if '.' in name:
name, submodule = name.split('.', 1)
else:
submodule = None
module = self.module_entries.get(name, None)
if submodule and module is not None:
module = module.lookup_submodule(submodule)
return module
def add_include_file(self, filename): def add_include_file(self, filename):
if filename not in self.python_include_files \ if filename not in self.python_include_files \
......
...@@ -22,6 +22,11 @@ setup( ...@@ -22,6 +22,11 @@ setup(
######## pkg/a.pyx ######## ######## pkg/a.pyx ########
from .sub.reimport cimport myint
cdef myint i = 5
assert i == 5
cdef class test_pxd: cdef class test_pxd:
pass pass
...@@ -59,3 +64,13 @@ def test(): ...@@ -59,3 +64,13 @@ def test():
obj.x = 1 obj.x = 1
obj.y = 2 obj.y = 2
return (obj.x, obj.y) return (obj.x, obj.y)
######## pkg/sub/tdef.pxd ########
ctypedef int myint
######## pkg/sub/reimport.pxd ########
from .tdef cimport myint
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