python 3 语义版本化和向前兼容

Is python 3 semantically versioned and forwards compatible

我正在查看一些想要引入 Python 3.6 以便在 3.5 为标准的环境中使用的软件。阅读 Python 的文档,我找不到关于是否:

的任何信息

this page about porting to 3.7 存在的事实让我强烈认为 不存在 但我看不到关于版本号含义的官方文档(如果有的话,ala Linux 内核版本控制)

在更一般的意义上 - 3.X 发布流中是否有关于兼容性标准的 PEP?

Here's the document on updating to 3.6.

例如,如果您在 3.5 的代码中有 open(apath, 'U+'),则它在 3.6 中会失败。所以,很明显,Python 3.6 并不完全向后兼容 3.5 中的所有用法。

实际上,您需要进行测试,尽管我很乐意告诉几乎每个领域的平均 Whosebug reader 他们应该很乐意进行此升级。

至于语义版本控制,具体来说,Python 不遵循它,但它并不完全不知道主要版本、次要版本和错误修复版本的含义。 Python 可以找到其开发人员指南 here

To clarify terminology, Python uses a major.minor.micro nomenclature for production-ready releases. So for Python 3.1.2 final, that is a major version of 3, a minor version of 1, and a micro version of 2.

  • new major versions are exceptional; they only come when strongly incompatible changes are deemed necessary, and are planned very long in advance;
  • new minor versions are feature releases; they get released annually, from the current in-development branch;
  • new micro versions are bugfix releases; they get released roughly every 2 months; they are prepared in maintenance branches.

另请阅读 PEP440,这是针对模块的,而不是发布 python 本身的新版本,但仍然与生态系统的理念相关。

简短的回答是“否”,长的回答是“他们争取接近它的东西”。

一般来说,微版本匹配语义版本控制规则;他们不应该破坏任何东西或添加功能,只是修复错误。情况并非总是如此(例如 ),但 非常 代码(尤其是 Python 级别的东西,与 C 扩展相反)中断的情况很少见跨越微边界。

次要版本主要是“添加功能”,但是它们也会做出向后不兼容的更改并事先发出警告。例如,async and await became keywords in Python 3.7, which meant code using them as variable names broke, but with warnings enabled, you would have seen a DeprecationWarning in 3.6。许多语法更改最初是作为特殊 __future__ 模块的可选导入引入的,并记录了成为默认行为的时间表。

None 在次要版本中所做的更改是广泛的更改;我怀疑任何个别的弃用或语法更改是否影响了现有源代码的 1%,但它确实发生了。如果你有一百个第三方依赖项,并且你正在跳一两个次要版本,那么其中一个将被更改破坏的可能性很大(例如:pika0.12 使用 async 作为变量名,并在 Python 3.7 上中断;他们发布了修复错误的新版本,但当然,从 0.11 和更低版本移动到 0.12 及更高版本以可能会破坏您的代码的方式更改了他们自己的 API。

主要版本大致符合您的预期;向后不兼容的更改是 expected/allowed(尽管它们通常不是轻率的;更改越大,好处就越大)。

要点是,它接近于语义版本控制,但为了不每隔几年发布一次主要版本,同时也不让语言因严格的兼容性限制而停滞不前,允许次要版本破坏少量现有版本只要有警告(通常以使用弃用行为的代码的实际警告形式,新功能文档中的注释,有时 __future__ 支持简化迁移路径)。

这些都在他们的 Development Cycle documentation:

中有正式记录(细节略少)

To clarify terminology, Python uses a major.minor.micro nomenclature for production-ready releases. So for Python 3.1.2 final, that is a major version of 3, a minor version of 1, and a micro version of 2.

  • new major versions are exceptional; they only come when strongly incompatible changes are deemed necessary, and are planned very long in advance;
  • new minor versions are feature releases; they get released annually, from the current in-development branch;
  • new micro versions are bugfix releases; they get released roughly every 2 months; they are prepared in maintenance branches.