This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author bluenix
Recipients asvetlov, bluenix, serhiy.storchaka, yselivanov
Date 2021-06-05.18:22:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1622917360.28.0.861004027536.issue44318@roundup.psfhosted.org>
In-reply-to
Content
>>> (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?
History
Date User Action Args
2021-06-05 18:22:40bluenixsetrecipients: + bluenix, asvetlov, serhiy.storchaka, yselivanov
2021-06-05 18:22:40bluenixsetmessageid: <1622917360.28.0.861004027536.issue44318@roundup.psfhosted.org>
2021-06-05 18:22:40bluenixlinkissue44318 messages
2021-06-05 18:22:40bluenixcreate