0

I am trying to go from Python2 to Python3. So the first step is to program forward compatible. Thus I use the from __future__ and the from builtins imports. However this breaks slots.

While

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

test = _Test()
test.b = 1

raises an AttributeError as expected

from builtins import object

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

test = _Test()
test.b = 1

just runs. Now test.__dict__ exists. So how can I use slots in Python3?

DerWeh
  • 1,721
  • 1
  • 15
  • 26
  • I can't reproduce your issue with the new-style class in either 2.7 or 3.6. In both Python versions it produces an `AttributeError` as expected. – blhsing Jul 12 '18 at 06:26
  • With `python3.5.2` the code properly raises the error. However, `python2.7.12` just runs the code. I don't have any other Python versions to test. I expect only `python2` to fail, as the `from builtins import object` line should do nothing for `python3`. – DerWeh Jul 12 '18 at 06:32

0 Answers0