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: Faulty dict arg gives ValueError but mostly TypeError
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: serhiy.storchaka, tomnor
Priority: normal Keywords:

Created on 2020-04-19 14:39 by tomnor, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg366781 - (view) Author: Tomas Nordin (tomnor) Date: 2020-04-19 14:39
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
msg366783 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-04-19 14:51
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.
msg366799 - (view) Author: Tomas Nordin (tomnor) Date: 2020-04-19 18:59
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.
History
Date User Action Args
2022-04-11 14:59:29adminsetgithub: 84509
2020-04-19 18:59:46tomnorsetmessages: + msg366799
2020-04-19 14:51:55serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg366783

resolution: not a bug
stage: resolved
2020-04-19 14:39:04tomnorcreate