Commit 6c5accdd authored by Stefan Behnel's avatar Stefan Behnel

support 'from __future__ import absolute_import'

parent 36d8cab3
......@@ -34,7 +34,7 @@ import Symtab
import Options
from Cython import Utils
from Annotate import AnnotationItem
from Cython.Compiler import Future
from Cython.Debugging import print_call_chain
from DebugFlags import debug_disposal_code, debug_temp_alloc, \
debug_coercion
......@@ -1933,7 +1933,8 @@ class ImportNode(ExprNode):
def analyse_types(self, env):
if self.level is None:
if env.directives['language_level'] < 3 or env.directives['py2_import']:
if (env.directives['py2_import'] or
Future.absolute_import not in env.global_scope().context.future_directives):
self.level = -1
else:
self.level = 0
......
......@@ -10,6 +10,7 @@ unicode_literals = _get_feature("unicode_literals")
with_statement = _get_feature("with_statement")
division = _get_feature("division")
print_function = _get_feature("print_function")
absolute_import = _get_feature("absolute_import")
nested_scopes = _get_feature("nested_scopes") # dummy
generators = _get_feature("generators") # dummy
......
......@@ -81,9 +81,8 @@ class Context(object):
def set_language_level(self, level):
self.language_level = level
if level >= 3:
from Future import print_function, unicode_literals
self.future_directives.add(print_function)
self.future_directives.add(unicode_literals)
from Future import print_function, unicode_literals, absolute_import
self.future_directives.update([print_function, unicode_literals, absolute_import])
self.modules['builtins'] = self.modules['__builtin__']
# pipeline creation functions can now be found in Pipeline.py
......
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