[Cython] Preparing the language level change - Re: [cython-users] Cython 0.29 beta 1 released

Stefan Behnel stefan_ml at behnel.de
Mon Sep 24 16:05:37 EDT 2018


Stefan Behnel schrieb am 21.09.2018 um 17:46:
> Robert Bradshaw schrieb am 21.09.2018 um 17:30:
>> I agree that this doesn't really feel like a language-level thing.
>>
>> There seem three desired behaviors here:
>>
>> language_level=2 where currently "abc" is always a bytes object
>> langauge_level=3 where currently "abc" is always a unicode object
>>
>> and a third option, where "abc" is a str object (depending on the
>> runtime). We should support all three of these modes.
> 
> Correction: with "language_level=2", unprefixed string literals are "str",
> i.e. "bytes" in Py2 and "unicode" in Py3. "language_level=3" always makes
> them unicode strings, and that's what Jeroen was referring to.
> 
> It's really difficult to guess what the most common use case is here. The
> only reason why the type changing unprefixed "str" literals are relevant is
> that Py2 cannot handle Unicode in some cases (and Unicode strings are
> memory hogs in Py2), but Py3 requires Unicode in most cases (and handles it
> efficiently). So, the problem here is really Py2, and the problem will go
> away as soon as we dump support for it. Until then, however, we're trying
> to find a solution to make the language level switch bearable and easy the
> transition.

I added a new directive "str_is_str=True" which can be combined with
"language_level=3" to get the desired behaviour. It keeps the 'str' builtin
type as it is (it would otherwise become 'unicode' with level 3) and keeps
unprefixed string literals as type 'str' in Py2 and Py3. Everything else
should depend solely on the language_level switch.

https://github.com/cython/cython/commit/cea42915c5e9ea1da9187aa3c55f3f16d04ba1e3

I think we're now set for the release. I'll prepare a candidate.

Stefan


More information about the cython-devel mailing list