Commit bd8dab84 authored by Stefan Behnel's avatar Stefan Behnel

Document "language_level=3str" and also support it in the cythonize command as "--3str".

parent a1ec72b2
...@@ -89,8 +89,8 @@ Features added ...@@ -89,8 +89,8 @@ Features added
* An additional ``check_size`` clause was added to the ``ctypedef class`` name * An additional ``check_size`` clause was added to the ``ctypedef class`` name
specification to allow suppressing warnings when importing modules with specification to allow suppressing warnings when importing modules with
backward-compatible `PyTypeObject`` size changes. backwards-compatible ``PyTypeObject`` size changes.
(Github issue #2627) Patch by Matti Picus. (Github issue #2627)
Bugs fixed Bugs fixed
---------- ----------
...@@ -162,16 +162,16 @@ Bugs fixed ...@@ -162,16 +162,16 @@ Bugs fixed
Other changes Other changes
------------- -------------
* Cython now emits a warning when no ``language_level`` (2 or 3) is set explicitly, * Cython now emits a warning when no ``language_level`` (2, 3 or '3str') is set
neither as a ``cythonize()`` option nor as a compiler directive. This is meant explicitly, neither as a ``cythonize()`` option nor as a compiler directive.
to prepare the transition of the default language level from currently Py2 This is meant to prepare the transition of the default language level from
to Py3, since that is what most new users will expect these days. The future currently Py2 to Py3, since that is what most new users will expect these days.
default will, however, not enforce unicode literals, because this has proven a The future default will, however, not enforce unicode literals, because this
major obstacle in the support for both Python 2.x and 3.x. The next major has proven a major obstacle in the support for both Python 2.x and 3.x. The
release is intended to make this change, so that it will parse all code that next major release is intended to make this change, so that it will parse all
does not request a specific language level as Python 3 code, but with ``str`` code that does not request a specific language level as Python 3 code, but with
literals. The language level 2 will continue to be supported for an indefinite ``str`` literals. The language level 2 will continue to be supported for an
time. indefinite time.
* The documentation was restructured, cleaned up and examples are now tested. * The documentation was restructured, cleaned up and examples are now tested.
The NumPy tutorial was also rewritten to simplify the running example. The NumPy tutorial was also rewritten to simplify the running example.
......
...@@ -165,6 +165,8 @@ def parse_args(args): ...@@ -165,6 +165,8 @@ def parse_args(args):
help='use Python 2 syntax mode by default') help='use Python 2 syntax mode by default')
parser.add_option('-3', dest='language_level', action='store_const', const=3, parser.add_option('-3', dest='language_level', action='store_const', const=3,
help='use Python 3 syntax mode by default') help='use Python 3 syntax mode by default')
parser.add_option('--3str', dest='language_level', action='store_const', const='3str',
help='use Python 3 syntax mode by default')
parser.add_option('-a', '--annotate', dest='annotate', action='store_true', parser.add_option('-a', '--annotate', dest='annotate', action='store_true',
help='generate annotated HTML page for source files') help='generate annotated HTML page for source files')
...@@ -198,7 +200,7 @@ def parse_args(args): ...@@ -198,7 +200,7 @@ def parse_args(args):
if multiprocessing is None: if multiprocessing is None:
options.parallel = 0 options.parallel = 0
if options.language_level: if options.language_level:
assert options.language_level in (2, 3) assert options.language_level in (2, 3, '3str')
options.options['language_level'] = options.language_level options.options['language_level'] = options.language_level
return options, args return options, args
......
...@@ -815,11 +815,14 @@ Cython code. Here is the list of currently supported directives: ...@@ -815,11 +815,14 @@ Cython code. Here is the list of currently supported directives:
expressions* is considered unsafe (due to possible overflow) and must be expressions* is considered unsafe (due to possible overflow) and must be
explicitly requested. explicitly requested.
``language_level`` (2/3) ``language_level`` (2/3/3str)
Globally set the Python language level to be used for module Globally set the Python language level to be used for module
compilation. Default is compatibility with Python 2. To enable compilation. Default is compatibility with Python 2. To enable
Python 3 source code semantics, set this to 3 at the start of a Python 3 source code semantics, set this to 3 (or 3str) at the start
module or pass the "-3" command line option to the compiler. of a module or pass the "-3" or "--3str" command line options to the
compiler. The ``3str`` option enables Python 3 semantics but does
not change the ``str`` type and unprefixed string literals to
``unicode`` when the compiled code runs in Python 2.x.
Note that cimported files inherit this setting from the module Note that cimported files inherit this setting from the module
being compiled, unless they explicitly set their own language level. being compiled, unless they explicitly set their own language level.
Included source files always inherit this setting. Included source files always inherit this setting.
......
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