Bluenix <bluenix...@gmail.com> added the comment:
>>> (1).__dict__ Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'int' object has no attribute '__dict__' >>> 4.5.__dict__ Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'float' object has no attribute '__dict__' >>> 'Hello'.__dict__ Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'str' object has no attribute '__dict__' >>> b'50'.__dict__ Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'bytes' object has no attribute '__dict__' >>> [2.72, 3.14].__dict__ Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'list' object has no attribute '__dict__' > __slots__ allow us to explicitly declare data members (like properties) and > deny the creation of __dict__ and __weakref__ (unless explicitly declared in > __slots__ or available in a parent.) >From https://docs.python.org/3/reference/datamodel.html They don't have __slots__, nor a __dict__ or __weakref__: >>> (1).__weakref__ Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'int' object has no attribute '__weakref__' >>> 4.5.__weakref__ Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'float' object has no attribute '__weakref__' >>> 'Hello'.__weakref__ Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'str' object has no attribute '__weakref__' >>> b'50'.__weakref__ Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'bytes' object has no attribute '__weakref__' >>> [2.72, 3.14].__weakref__ Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'list' object has no attribute '__weakref__' They're essentially C extension classes: https://docs.python.org/3/extending/newtypes_tutorial.html I am not sure what this argument was meant to prove. What would be the downside to adding __slots__ to asyncio's classes? Other than that someone can no longer arbitrarily add attributes? ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue44318> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com