Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class A(object):
- pass
- class B(object):
- __slots__ = ('foobar',)
- def __init__(self):
- self.x = 123
- class C(A):
- __slots__ = ('foobar',)
- def __init__(self):
- self.x = 123
- >>> A()
- <__main__.A object at 0x10caf4d10>
- >>> C()
- <__main__.C object at 0x10caf38c0>
- >>> B()
- Traceback (most recent call last):
- File "slots.py", line 18, in <module>
- B()
- File "slots.py", line 8, in __init__
- self.x = 123
- AttributeError: 'B' object has no attribute 'x'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement