Python 3.x Python 3兼容插槽

Python 3.x Python 3兼容插槽,python-3.x,slots,Python 3.x,Slots,我正试图从Python2转到Python3。因此,第一步是编程向前兼容。因此,我使用来自未来的和来自内置的导入。然而,这打破了槽 当 按预期引发AttributeError from builtins import object class _Test(object): __slots__ = ('a', ) test = _Test() test.b = 1 只是跑步。现在test.\uuuu dict\uuuu已存在。那么我如何使用Python3中的slot呢?我无法在2.7或

我正试图从
Python2
转到
Python3
。因此,第一步是编程向前兼容。因此,我使用来自未来的
和来自内置的
导入。然而,这打破了槽

按预期引发
AttributeError

from builtins import object

class _Test(object):
    __slots__ = ('a', )

test = _Test()
test.b = 1

只是跑步。现在
test.\uuuu dict\uuuu
已存在。那么我如何使用Python3中的slot呢?

我无法在2.7或3.6中用新样式的类重现您的问题。在两个Python版本中,它都会按预期生成一个
AttributeError
。使用
python3.5.2
时,代码会正确地引发错误。但是,
python2.7.12
只是运行代码。我没有任何其他Python版本要测试。我预计只有
python2
会失败,因为来自内置导入对象的
行不应该对
python3
起任何作用。
from builtins import object

class _Test(object):
    __slots__ = ('a', )

test = _Test()
test.b = 1