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

Faulty dict arg gives ValueError but mostly TypeError #84509

Closed
tomnor mannequin opened this issue Apr 19, 2020 · 3 comments
Closed

Faulty dict arg gives ValueError but mostly TypeError #84509

tomnor mannequin opened this issue Apr 19, 2020 · 3 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@tomnor
Copy link
Mannequin

tomnor mannequin commented Apr 19, 2020

BPO 40329
Nosy @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-04-19.14:51:55.945>
created_at = <Date 2020-04-19.14:39:04.820>
labels = ['3.7', 'invalid', 'type-bug', 'library']
title = 'Faulty dict arg gives ValueError but mostly TypeError'
updated_at = <Date 2020-04-19.18:59:46.783>
user = 'https://bugs.python.org/tomnor'

bugs.python.org fields:

activity = <Date 2020-04-19.18:59:46.783>
actor = 'tomnor'
assignee = 'none'
closed = True
closed_date = <Date 2020-04-19.14:51:55.945>
closer = 'serhiy.storchaka'
components = ['Library (Lib)']
creation = <Date 2020-04-19.14:39:04.820>
creator = 'tomnor'
dependencies = []
files = []
hgrepos = []
issue_num = 40329
keywords = []
message_count = 3.0
messages = ['366781', '366783', '366799']
nosy_count = 2.0
nosy_names = ['serhiy.storchaka', 'tomnor']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue40329'
versions = ['Python 3.7']

@tomnor
Copy link
Mannequin Author

tomnor mannequin commented Apr 19, 2020

Hello Python bug tracker

Trying to create a dict with a top level set pair will fail, but how
will it fail?

Here comes a terminal session to reproduce the behavior. The same
command is just repeated.

----------------------------------8<----------------------------------

$ python3 -c 'd = dict({1, "one"})'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: cannot convert dictionary update sequence element #0 to a sequence

# Understand, can't convert 1 to sequence.

$ python3 -c 'd = dict({1, "one"})'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ValueError: dictionary update sequence element #0 has length 3; 2 is required

# Not so helpful to me, don't understand.

$ python3 -c 'd = dict({1, "one"})'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: cannot convert dictionary update sequence element #0 to a sequence

# OK, thanks

$ python3 -c 'd = dict({1, "one"})'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: cannot convert dictionary update sequence element #0 to a sequence

$ python3 -c 'd = dict({1, "one"})'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: cannot convert dictionary update sequence element #0 to a sequence

$ python3 -c 'd = dict({1, "one"})'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ValueError: dictionary update sequence element #0 has length 3; 2 is required

# Again?
---------------------------------->8----------------------------------

I searched the bug tracker on "dict typeerror valueerror" but couldn't
find something similar. What do you think about this?

$ python3 --version
Python 3.7.3

Best regards

Tomas

@tomnor tomnor mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Apr 19, 2020
@serhiy-storchaka
Copy link
Member

It is all correct. Note that set is unordered, so "element #0" can be 1, and can be "one". If it is 1, you get a type error. If it is "one", which is a sequence with length 3, you get a value error.

@tomnor
Copy link
Mannequin Author

tomnor mannequin commented Apr 19, 2020

Serhiy Storchaka <report@bugs.python.org> writes:

Serhiy Storchaka <storchaka+cpython@gmail.com> added the comment:

It is all correct. Note that set is unordered, so "element #0" can be 1, and can be "one". If it is 1, you get a type error. If it is "one", which is a sequence with length 3, you get a value error.

Yes! Thanks, sorry for the noise.

@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.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant