On Sat, May 02, 2020 at 01:20:01PM -0300, Soni L. wrote:
> 
> 
> On 2020-05-02 1:07 p.m., Steven D'Aprano wrote:
> >On Sat, May 02, 2020 at 12:50:19PM -0300, Soni L. wrote:
> >
> >> how about:
> >> 
> >> result = Foo.save()
> >> try:
> >>   x, y = result
> >> except ValueUnpackingError:
> >>   return ...
> >
> >If you do that, what benefit is ValueUnpackingError over just
> >ValueError?
> >
> >
> >
> unpacking (a generator) still doesn't wrap ValueError

Sorry, I don't understand that comment. What do you mean, "wrap"?

Unpacking a generator with too many values raises ValueError:

    py> a, b = (x for x in range(3))
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: too many values to unpack (expected 2)

> and ValueError is 
> raised a lot more than ValueUnpackingError.

Why does that matter, and how does that relate to the specific code 
sample given?

Given the line of code `x, y = result`, the only possible way ValueError 
could be raised is if `result` has the wrong number of items when 
unpacking. So what benefit does ValueUnpackingError bring to this 
example?


-- 
Steven
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/K6EOGW57OCDRLCF2WKPSG5ZU2A2MI6HQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to