Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should we make dict not accept a sequence of sets? #83359

Closed
DeepSpace mannequin opened this issue Jan 1, 2020 · 3 comments
Closed

Should we make dict not accept a sequence of sets? #83359

DeepSpace mannequin opened this issue Jan 1, 2020 · 3 comments
Labels
3.9 only security fixes type-feature A feature request or enhancement

Comments

@DeepSpace
Copy link
Mannequin

DeepSpace mannequin commented Jan 1, 2020

BPO 39178
Nosy @rhettinger, @stevendaprano, @methane, @serhiy-storchaka

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2020-01-01.15:44:30.164>
created_at = <Date 2020-01-01.14:00:21.874>
labels = ['type-feature', '3.9']
title = 'Should we make dict not accept a sequence of sets?'
updated_at = <Date 2020-01-01.15:44:30.161>
user = 'https://bugs.python.org/DeepSpace'

bugs.python.org fields:

activity = <Date 2020-01-01.15:44:30.161>
actor = 'steven.daprano'
assignee = 'none'
closed = True
closed_date = <Date 2020-01-01.15:44:30.164>
closer = 'steven.daprano'
components = []
creation = <Date 2020-01-01.14:00:21.874>
creator = 'DeepSpace'
dependencies = []
files = []
hgrepos = []
issue_num = 39178
keywords = []
message_count = 3.0
messages = ['359155', '359157', '359161']
nosy_count = 5.0
nosy_names = ['rhettinger', 'steven.daprano', 'methane', 'serhiy.storchaka', 'DeepSpace']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue39178'
versions = ['Python 3.9']

@DeepSpace
Copy link
Mannequin Author

DeepSpace mannequin commented Jan 1, 2020

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)?

@DeepSpace DeepSpace mannequin added 3.9 only security fixes type-feature A feature request or enhancement labels Jan 1, 2020
@serhiy-storchaka
Copy link
Member

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.

@stevendaprano
Copy link
Member

"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))

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.9 only security fixes type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants