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