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.

classification
Title: Make dict(object) return its attribute __dict__
Type: enhancement Stage: resolved
Components: Versions: Python 3.10
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: SmartManoj, iritkatriel, rhettinger
Priority: normal Keywords:

Created on 2020-10-04 13:44 by SmartManoj, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (7)
msg377940 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2020-10-04 14:17
dict is not a function, it's a class and the purpose of a dict() call is to create a new instance of that class.

The change you are proposing is also breaking for iterators:

>>> class Pairs(list): pass
... 
>>> pairs = Pairs([('a', 1), ('b', 2)])
>>> pairs.__dict__
{}
>>> dict(pairs)
{'a': 1, 'b': 2}

A change of this magnitude will need to be discussed on python-ideas and will require a PEP explaining why the benefits of the change outweigh its costs. I very much doubt that they do.
msg377941 - (view) Author: மனோஜ்குமார் பழனிச்சாமி (SmartManoj) * Date: 2020-10-04 14:29
Will return only if it is not an iterator
msg377965 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2020-10-04 17:38
You ignored the other point I made: dict is not a function, it is a class. dict() calls the function dict.__init__() which should create a new instance of dict (not return some field of its parameter). 


You also didn't justify your suggestion in any way. Why should this change be made?
msg377967 - (view) Author: மனோஜ்குமார் பழனிச்சாமி (SmartManoj) * Date: 2020-10-04 18:06
Your point makes sense as it takes space to allocate for the new instance to just return another dict object. 
Then the attribute name at least should be meaningful.

Instead of __dict__ , __attr__ is more appropriate.
msg377968 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-10-04 18:17
The vars() function already does this.
msg377970 - (view) Author: மனோஜ்குமார் பழனிச்சாமி (SmartManoj) * Date: 2020-10-04 18:25
Changing '__dict__' to __vars__ will be much better.

Like len() calling __len__()

Can we change the title?

Why Github Issue Tracker is not issued?
msg377994 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-10-05 04:59
Sorry, but I think there is a near zero chance that the language will be revised as you suggest. 

Marking this as closed. If you want to have more discussion, please take it to the python-ideas maillist.
History
Date User Action Args
2022-04-11 14:59:36adminsetgithub: 86097
2020-10-05 04:59:29rhettingersetstatus: open -> closed
resolution: rejected
messages: + msg377994

stage: resolved
2020-10-04 18:25:44SmartManojsetmessages: + msg377970
2020-10-04 18:17:08rhettingersetnosy: + rhettinger
messages: + msg377968
2020-10-04 18:06:21SmartManojsetmessages: + msg377967
2020-10-04 17:38:53iritkatrielsetmessages: + msg377965
2020-10-04 14:29:04SmartManojsetmessages: + msg377941
2020-10-04 14:17:27iritkatrielsetnosy: + iritkatriel
messages: + msg377940
2020-10-04 13:44:57SmartManojcreate