Commit 9a8dcfde authored by Stefan Behnel's avatar Stefan Behnel

fix Py2.x style implicit relative cimports (try relative first, then absolute)

parent 14746524
......@@ -1128,15 +1128,18 @@ class ModuleScope(Scope):
# Finds and parses the module's .pxd file if the module
# has not been referenced before.
relative_to = None
if relative_level is not None and relative_level > 0:
absolute_fallback = False
if relative_level is not None and relative_level > 0:
# explicit relative cimport
# error of going beyond top-level is handled in cimport node
relative_to = self
while relative_level > 0 and relative_to:
relative_to = relative_to.parent_module
relative_level -= 1
else:
absolute_fallback = relative_level != 0 # might be None!
elif relative_level != 0:
# -1 or None: try relative cimport first, then absolute
relative_to = self.parent_module
absolute_fallback = True
module_scope = self.global_scope()
return module_scope.context.find_module(
......
......@@ -37,8 +37,10 @@ cdef class test_pxd:
from . cimport a
from .a cimport test_pxd
cimport a as implicitly_relative_a
assert a.test_pxd is test_pxd
assert implicitly_relative_a.test_pxd is test_pxd
def test():
cdef test_pxd obj = test_pxd()
......
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