【发布时间】:2019-05-27 11:02:52
【问题描述】:
在 Python 3.3 中,collections(如MutableMapping 或MutableSequence)中的“抽象基类”被移至二级模块collections.abc。所以在 Python 3.3+ 中,真正的类型是 collections.abc.MutableMapping 等等。 Documentation 声明旧别名(例如 collections.MutableMapping)将在 Python 3.7(当前最新版本)之前可用,但在 3.8 中这些别名将被删除。
当您使用别名时,当前版本的 Python 3.7 甚至会产生警告:
./scripts/generateBoard.py:145: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
elif isinstance(value, (collections.MutableMapping, collections.MutableSequence)) == True:
在 python 2.7 中没有collections.abc。
当 Python 脚本旨在与(几乎)任何 Python 版本一起使用时,如何以最方便的方式处理这种差异?我正在寻找一种解决方案,可以理想地在一个中心位置解决这个混乱,而不必在我需要这种类型的任何地方都使用try: ... except: ...?
【问题讨论】:
-
他们破坏了主要版本的向后兼容性。淘气。
标签: python python-3.x python-2.7