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: Should we make dict not accept a sequence of sets?
Type: enhancement Stage: resolved
Components: Versions: Python 3.9
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: DeepSpace, methane, rhettinger, serhiy.storchaka, steven.daprano
Priority: normal Keywords:

Created on 2020-01-01 14:00 by DeepSpace, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg359155 - (view) Author: Adi (DeepSpace) Date: 2020-01-01 14:00
While writing this SO answer (https://stackoverflow.com/a/59552970/1453822) I came to think, should dict preemptively make sure it doesn't accept a sequence of sets (given that it may lead to wrong output in the good case, and miserably fail in the worst case)?
msg359157 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-01-01 14:25
This is a very special case. I think it is better to leave it to third-party linters.

Actually it is so uncommon, that I have doubts that even linters will want to handle it.
msg359161 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2020-01-01 15:44
"should dict preemptively make sure it doesn't accept a sequence of sets"

No. The person on StackOverflow made a mistake in their code: they used an unordered data structure (set) instead of an ordered data structure (tuple):

    dict({i,j} for i,j in enumerate(lst))

It is a waste of time to slow down the dict constructor to check for something so unusual as this. Everyone will pay the cost of the checks and virtually no-one will get any benefit.

I'm closing this as "rejected", but if anyone disagrees they can reopen it.

By the way, the best way to initialise a dictionary in this situation is to avoid the unnecessary generator expression and just go straight to enumerate:

    dict(enumerate(lst))
History
Date User Action Args
2022-04-11 14:59:24adminsetgithub: 83359
2020-01-01 15:44:30steven.dapranosetstatus: open -> closed

nosy: + steven.daprano
messages: + msg359161

resolution: rejected
stage: resolved
2020-01-01 14:25:44serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg359157
2020-01-01 14:09:56xtreaksetnosy: + rhettinger, methane
2020-01-01 14:00:21DeepSpacecreate