[issue39816] More descriptive error message than "too many values to unpack"

2021-09-02 Thread Dávid Nemeskey

Dávid Nemeskey  added the comment:

+1. When starting out, I always got confused about this message ("too many 
values to unpack? Does that mean my function returned too many items, which 
could not be unpacked into the expected number? Oh no, the opposite...").

Also, please note that the stack trace usually shows the offending line (e.g. 
x, y, z = fn(...)), so it is easy to see how many values are _expected_. It 
would be even more helpful to (also) show how many we _got_.

--
nosy: +nemeskeyd

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39816] More descriptive error message than "too many values to unpack"

2021-05-25 Thread malcomvx


malcomvx  added the comment:

Python functions can return multiple variables . These variables can be stored 
in variables directly. This is a unique property of Python , other programming 
languages such as C++ or Java do not support this by default.

The valueerror: too many values to unpack occurs during a multiple-assignment 
where you either don't have enough objects to assign to the variables or you 
have more objects to assign than variables. If for example myfunction() 
returned an iterable with three items instead of the expected two then you 
would have more objects than variables necessary to assign to.

http://net-informations.com/python/err/value.htm

--
nosy: +malcomvx

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39816] More descriptive error message than "too many values to unpack"

2020-03-16 Thread Zackery Spytz


Change by Zackery Spytz :


--
keywords: +patch
nosy: +ZackerySpytz
nosy_count: 4.0 -> 5.0
pull_requests: +18387
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/19036

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39816] More descriptive error message than "too many values to unpack"

2020-03-01 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +xtreak

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39816] More descriptive error message than "too many values to unpack"

2020-03-01 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

I concur with Chris and Kyle.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39816] More descriptive error message than "too many values to unpack"

2020-03-01 Thread Kyle Stanley


Kyle Stanley  added the comment:

+1, I've always found the "too many values to unpack" error messages be rather 
vague. Adding the type should make the message more clear, and easier to debug 
the error for users.

But, I think Chris Angelico raised a good point regarding the length (in the 
python-ideas thread):

> For your provided use-case, the length is almost irrelevant; the best
> way to spot the bug is to see "oh, it was trying to unpack a string,
> not a tuple". And that part can be done much more easily and safely.

So can we separate this into including the type, and including the length into 
two separate PRs? It can be part of the same issue, but I think including just 
the type for all of the unpacking error messages will be far easier to merge 
than merging the length one as well; considering that the former has 
significantly more added value.

--
nosy: +aeros

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39816] More descriptive error message than "too many values to unpack"

2020-03-01 Thread Alex Hall


New submission from Alex Hall :

Based on the discussion in 
https://mail.python.org/archives/list/python-id...@python.org/thread/C6QEAEEAELUHMLB23OBRSQK2UYU3AF5O/

When unpacking fails with an error such as:

ValueError: too many values to unpack (expected 2)

the name of the type of the unpacked object should be included, e.g.

ValueError: too many values to unpack (expected 2) from object of type 'str'

and if the type is exactly list or tuple, which are already special cased: 
https://github.com/python/cpython/blob/baf29b221682be0f4fde53a05ea3f57c3c79f431/Python/ceval.c#L2243-L2252

then the length can also be included:

ValueError: too many values to unpack (expected 2, got 3) from object of type 
'tuple'

--
components: Interpreter Core
messages: 363083
nosy: alexmojaki
priority: normal
severity: normal
status: open
title: More descriptive error message than "too many values to unpack"
type: enhancement
versions: Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com