兼容性策略#

语义版本控制#

PyMongo的版本号如下 semantic versioning :每个版本号都是结构化的”主要.次要.修补". 补丁版本修复bug,次要版本添加特性(并可能修复bug),主要版本包括破坏向后兼容性的API更改(并可能添加特性和修复bug)。

贬低#

在我们删除主要版本中的一个特性之前,PyMongo的维护人员会努力发布至少一个次要版本 反对 它。我们加上“ DEPRECATED ,并更新代码以引发 DeprecationWarning . 通过使用最新的PyMongo版本运行代码并查找不推荐警告,可以确保代码经得起未来的考验。

默认情况下,解释器会使DeproationWarning静默。例如,下面的代码使用过时的 insert 方法,但不会引发任何警告:

# "insert.py" (with PyMongo 3.X)
from pymongo import MongoClient

client = MongoClient()
client.test.test.insert({})

要将不推荐警告打印到stderr,请使用“-Wd”运行python:

$ python3 -Wd insert.py
insert.py:4: DeprecationWarning: insert is deprecated. Use insert_one or insert_many instead.
  client.test.test.insert({})

您可以使用“python-We”将警告转换为异常:

$ python3 -We insert.py
Traceback (most recent call last):
  File "insert.py", line 4, in <module>
    client.test.test.insert({})
  File "/home/durin/work/mongo-python-driver/pymongo/collection.py", line 2906, in insert
    "instead.", DeprecationWarning, stacklevel=2)
DeprecationWarning: insert is deprecated. Use insert_one or insert_many instead.

如果您自己的代码的测试套件通过了“python-We”,那么它不会使用不推荐使用的PyMongo特性。