Commit d019d9f3 authored by Jeroen Demeyer's avatar Jeroen Demeyer Committed by Stefan Behnel

Correctly remove future_directives with # cython: language_level=2

parent c7b13f37
...@@ -97,18 +97,17 @@ class Context(object): ...@@ -97,18 +97,17 @@ class Context(object):
def set_language_level(self, level): def set_language_level(self, level):
from .Future import print_function, unicode_literals, absolute_import, division from .Future import print_function, unicode_literals, absolute_import, division
future_directives = [] future_directives = set()
if level == '3str': if level == '3str':
future_directives = [print_function, absolute_import, division]
self.future_directives.discard(unicode_literals)
level = 3 level = 3
else: else:
level = int(level) level = int(level)
if level >= 3: if level >= 3:
future_directives = [print_function, unicode_literals, absolute_import, division] future_directives.add(unicode_literals)
if level >= 3:
future_directives.update([print_function, absolute_import, division])
self.language_level = level self.language_level = level
if future_directives: self.future_directives = future_directives
self.future_directives.update(future_directives)
if level >= 3: if level >= 3:
self.modules['builtins'] = self.modules['__builtin__'] self.modules['builtins'] = self.modules['__builtin__']
......
...@@ -7,12 +7,19 @@ PYTHON -c "import infile2; import infile3" ...@@ -7,12 +7,19 @@ PYTHON -c "import infile2; import infile3"
from Cython.Build.Dependencies import cythonize from Cython.Build.Dependencies import cythonize
from distutils.core import setup from distutils.core import setup
setup( ext_modules = []
ext_modules = (cythonize("infile*.py") +
cythonize("directive2.py", compiler_directives={'language_level': 2}) + # Test language_level specified in the cythonize() call
cythonize("directive3.py", compiler_directives={'language_level': 3}) ext_modules += cythonize("directive2.py", compiler_directives={'language_level': 2})
) ext_modules += cythonize("directive3.py", compiler_directives={'language_level': 3})
)
# Test language_level specified in the source file. We give a
# conflicting directive to cythonize() to check that the language_level
# is correctly overridden when compiling
ext_modules += cythonize("infile2.py", compiler_directives={'language_level': 3})
ext_modules += cythonize("infile3.py", compiler_directives={'language_level': 2})
setup(ext_modules=ext_modules)
######## directive3.py ######## ######## directive3.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