Created
October 1, 2019 13:51
-
-
Save jd/072eed87899d234098ac22bdf3744798 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment