# 0: absolute import;
# >0: the number of parent directories to search
# relative to the current module.
+ # None: decide the level according to language level and
+ # directives
type = py_object_type
subexprs = ['module_name', 'name_list']
def analyse_types(self, env):
+ if self.level is None:
+ if env.directives['language_level'] < 3 or env.directives['py2_import']:
+ self.level = -1
+ else:
+ self.level = 0
self.module_name.analyse_types(env)
self.module_name = self.module_name.coerce_to_pyobject(env)
if self.name_list:
'autotestdict.all': False,
'language_level': 2,
'fast_getattr': False, # Undocumented until we come up with a better way to handle this everywhere.
+ 'py2_import': False, # For backward compatibility of Cython's source code
'warn': None,
'warn.undeclared': False,
return Nodes.ReraiseStatNode(pos)
def p_import_statement(s):
- # will do absolute import in Py3 and try both relative and absolute in Py2.
- if s.context.language_level >= 3:
- level = 0
- else:
- level = -1
# s.sy in ('import', 'cimport')
pos = s.position()
kind = s.sy
rhs = ExprNodes.ImportNode(pos,
module_name = ExprNodes.IdentifierStringNode(
pos, value = dotted_name),
- level = level,
+ level = None,
name_list = name_list))
stats.append(stat)
return Nodes.StatListNode(pos, stats = stats)
while s.sy == '.':
level += 1
s.next()
+ if s.sy == 'cimport':
+ s.error("Relative cimport is not supported yet")
else:
- # will do absolute import in Py3 and try both relative and absolute in Py2.
- if s.context.language_level >= 3:
- level = 0
- else:
- level = -1
-
- if level > 0 and s.sy == 'cimport':
- s.error("Relative cimport is not supported yet")
- if level > 0 and s.sy == 'import':
+ level = None
+ if level is not None and s.sy == 'import':
# we are dealing with "from .. import foo, bar"
dotted_name_pos, dotted_name = s.position(), ''
+ elif level is not None and s.sy == 'cimport':
+ # "from .. cimport"
+ s.error("Relative cimport is not supported yet")
else:
(dotted_name_pos, _, dotted_name, _) = \
p_dotted_name(s, as_allowed = 0)
# cython: language_level=3
-__name__='distutils.baregg' # fool Python we are in distutils
+import sys
+# fool Python we are in distutils
+if sys.version_info >= (3,):
+ __package__='distutils'
+else:
+ __package__=b'distutils'
from distutils import cmd, core, version
from .core import *