Cython的language_level 3和3str有什么区别? [英] What are differences between Cython's language_level 3 and 3str?

查看:55
本文介绍了Cython的language_level 3和3str有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在即将到来的Cython 3.0版本中, 3str language_level(由设置方法),我们将收到以下警告:

In the upcoming Cython 3.0 version, 3str language_level (which was introduced with Cython 0.29) becomes the new default instead of the current default 2, i.e. if language_level is not set (how to set), we get the following warning:

FutureWarning:未设置Cython指令'language_level',使用'3str'现在(Py3).这与以前的版本有所不同!文件:/home/ed/mygithub/cython/foo.pyx tree = Parsing.p_module(s,pxd,full_module_name)

FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /home/ed/mygithub/cython/foo.pyx tree = Parsing.p_module(s, pxd, full_module_name)

但是 3str 3 语言级别之间有什么区别?对于哪些代码,使用 3str 和 3 语言级别?

But what are the differences between 3str and 3 language levels and for which code will there be differences in the behavior of modules compiled with 3str and 3 language levels?

推荐答案

TLDR: 3str 不假定字符串文字在Python2.x下是unicode,因此可以从Python2进行迁移.x到Python3更容易.

TLDR: 3str does not assume that string literals are unicode under Python2.x making migration from Python2.x to Python3 easier.

不是一个完整的答案,因为我不知道突出差异的代码,并且仍然留有疑问的余地,但这可能很有用,

Not a complete answer because I don't know the code to highlight the differences and this still leaves room for questions, but this may be useful, Whats new in cython 0.29:

新的语言级别'

Cython 0.29支持 language_level 指令的新设置 language_level = 3str ,它将成为Cython 3.0中新的默认语言级别.我们现在已经添加了它,以便用户可以立即加入并从中受益,并且已经为即将发生的更改准备了代码.这是介于两者之间的中间"这种设置,启用所有与Python 2.x语法不兼容的漂亮的Python 3好东西,但是当编译后的代码在Python 2.x中运行时,不需要所有未加前缀的字符串文字就成为Unicode字符串>.这是一般Py3迁移中的最大问题之一.在Cython与C代码集成的上下文中,它给我们的用户带来的障碍甚至比Python代码多得多.我们的目标是使来自Python 3的新用户可以轻松地使用Cython编译代码,并允许现有的(Cython/Python 2)代码库在可以进行100%转换之前利用这些好处.

Cython 0.29 supports a new setting for the language_level directive, language_level=3str, which will become the new default language level in Cython 3.0. We already added it now, so that users can opt in and benefit from it right away, and already prepare their code for the coming change. It's an "in between" kind of setting, which enables all the nice Python 3 goodies that are not syntax compatible with Python 2.x, but without requiring all unprefixed string literals to become Unicode strings when the compiled code runs in Python 2.x. This was one of the biggest problems in the general Py3 migration. And in the context of Cython's integration with C code, it got in the way of our users even a bit more than it would in Python code. Our goals are to make it easy for new users who come from Python 3 to compile their code with Cython and to allow existing (Cython/Python 2) code bases to make use of the benefits before they can make a 100% switch.

Debian关于cython的手册页:

-embed [=< method_name>]] 生成一个main()函数,该函数嵌入了Python解释器.
-2 根据Python-2语法和代码语义进行编译.
-3 根据Python-3语法和代码语义进行编译.
-3str 基于Python-3语法和代码语义进行编译,而默认情况下不假设unicode对Python 2下的字符串文字具有unicode.

--embed[=<method_name>] Generate a main() function that embeds the Python interpreter.
-2 Compile based on Python-2 syntax and code semantics.
-3 Compile based on Python-3 syntax and code semantics.
--3str Compile based on Python-3 syntax and code semantics without assuming unicode by default for string literals under Python 2.

cython文档:

3str 选项启用Python 3语义,但是当编译的代码在其中运行时,不会将 str 类型和未前缀的字符串文字更改为 unicode .Python 2.x.

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.

这篇关于Cython的language_level 3和3str有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆