Re: Misleading error message of the day
On 12/09/2011 03:57 PM, alex23 wrote: On Dec 9, 11:46 am, Lie Ryan wrote: perhaps the one that talks about `a, a.foo = 1, 2` blowing up? Are you sure you're not confusing this with the recent thread on 'x = x.thing = 1'? Ah, yes I do -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
Jean-Michel Pichavant wrote: Ethan Furman wrote: Jean-Michel Pichavant wrote: You have to opportunity to not use unpacking anymore :o) There is a recent thread were the dark side of unpacking was exposed. Unpacking is a cool feautre for very small applications but should be avoided whenever possible otherwise. Which thread was that? ~Ethan~ "A tuple in order to pass returned values ?" was the thread. Thanks. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
In article , Jean-Michel Pichavant wrote: > Ethan Furman wrote: > > Jean-Michel Pichavant wrote: > >> You have to opportunity to not use unpacking anymore :o) There is a > >> recent thread were the dark side of unpacking was exposed. Unpacking > >> is a cool feautre for very small applications but should be avoided > >> whenever possible otherwise. > > > > Which thread was that? > > > > > > ~Ethan~ > "A tuple in order to pass returned values ?" was the thread. > > JM To save everybody the effort of finding it, I think he's talking about https://groups.google.com/d/topic/comp.lang.python/2vcwYfIQSOM/discussion -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
Ethan Furman wrote: Jean-Michel Pichavant wrote: You have to opportunity to not use unpacking anymore :o) There is a recent thread were the dark side of unpacking was exposed. Unpacking is a cool feautre for very small applications but should be avoided whenever possible otherwise. Which thread was that? ~Ethan~ "A tuple in order to pass returned values ?" was the thread. JM -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
In article , Chris Angelico wrote: > http://thedailywtf.com/Series/Error_0x27_d.aspx > > This is getting quite off-topic though. Getting off-topic, perhaps, but your comment really does bring some closure. When I was pondering the original, "too many values to unpack" message, I did indeed utter a few WTFs :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On Fri, Dec 9, 2011 at 1:07 PM, Steven D'Aprano wrote: > I forget where I saw this, but somebody took a screen shot of an error > message from a GUI application that said something like: > > A fatal error occurred: no error > > and then aborted the app. An errant error! Sounds like the stuff that happens here... http://thedailywtf.com/Series/Error_0x27_d.aspx This is getting quite off-topic though. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On Thu, 08 Dec 2011 18:10:17 +, Grant Edwards wrote: > On 2011-12-08, Roy Smith wrote: >> On Thursday, December 8, 2011 10:03:38 AM UTC-5, Jean-Michel Pichavant >> wrote: >>> string are iterable, considering this, the error is correct. >> >> Yes, I understand that the exception is correct. I'm not saying the >> exception should be changed, just that we have the opportunity to >> produce a more useful error message. The exception would be equally >> correct if it was: >> >> ValueError: you did something wrong > > My favorite is still the old classic error from and old Unix printer > port driver: > > "lp0 on fire" > >> but most people would probably agree that it's not the most useful >> message that could have been produced. I forget where I saw this, but somebody took a screen shot of an error message from a GUI application that said something like: A fatal error occurred: no error and then aborted the app. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On 12/09/2011 07:13 AM, Ethan Furman wrote: Jean-Michel Pichavant wrote: You have to opportunity to not use unpacking anymore :o) There is a recent thread were the dark side of unpacking was exposed. Unpacking is a cool feautre for very small applications but should be avoided whenever possible otherwise. Which thread was that? perhaps the one that talks about `a, a.foo = 1, 2` blowing up? -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
In article , Grant Edwards wrote: > On 2011-12-08, Roy Smith wrote: > > On Thursday, December 8, 2011 10:03:38 AM UTC-5, Jean-Michel Pichavant > > wrote: > >> string are iterable, considering this, the error is correct. > > > > Yes, I understand that the exception is correct. I'm not saying the > > exception should be changed, just that we have the opportunity to produce a > > more useful error message. The exception would be equally correct if it > > was: > > > > ValueError: you did something wrong > > My favorite is still the old classic error from and old Unix printer > port driver: > > "lp0 on fire" Well, if you're going to go there, ed had (and probably still does) have but a single all-purpose error message: "?". The old v6 unix chess program was somewhat more verbose. It said, "eh?" (unless I'm mixing that up with something else). -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On Fri, Dec 9, 2011 at 7:58 AM, alister wrote: > not as useless as "Keyboard Error press F1 to continue" If it said "press F1 to ignore" then I would agree. This, however, is more akin to "replace user and strike any key to continue", but more implicit. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On Thu, 08 Dec 2011 18:10:17 +, Grant Edwards wrote: > On 2011-12-08, Roy Smith wrote: >> On Thursday, December 8, 2011 10:03:38 AM UTC-5, Jean-Michel Pichavant >> wrote: >>> string are iterable, considering this, the error is correct. >> >> Yes, I understand that the exception is correct. I'm not saying the >> exception should be changed, just that we have the opportunity to >> produce a more useful error message. The exception would be equally >> correct if it was: >> >> ValueError: you did something wrong > > My favorite is still the old classic error from and old Unix printer > port driver: > > "lp0 on fire" > >> but most people would probably agree that it's not the most useful >> message that could have been produced. not as useless as "Keyboard Error press F1 to continue" -- "I once witnessed a long-winded, month-long flamewar over the use of mice vs. trackballs...It was very silly." (By Matt Welsh) -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
Benjamin Kaplan wrote: On Thu, Dec 8, 2011 at 2:09 PM, Ethan Furman wrote: Benjamin Kaplan wrote: If the RHS was a tuple or a list, yes you could know immediately. But unpacking works with any iterable, so it probably doesn't special-case lists and tuples. Iterables don't have a size- they just keep going until StopIteration is raised. So in EVERY SINGLE CASE, you would get "expected n args, got n+1" even if the iterable would return 24 items instead of 14, or would never stop returning items. Not so. There could be fewer, in which you could see "expected 13 args, got 7." You mean like this? a,b,c = ['a','b'] Traceback (most recent call last): File "", line 1, in ValueError: need more than 2 values to unpack This is still not as helpful as this would be: ValueError: need 3 values, received 2 ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
Jean-Michel Pichavant wrote: You have to opportunity to not use unpacking anymore :o) There is a recent thread were the dark side of unpacking was exposed. Unpacking is a cool feautre for very small applications but should be avoided whenever possible otherwise. Which thread was that? ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On 12/8/11 4:21 PM, Chris Angelico wrote: On Fri, Dec 9, 2011 at 2:55 AM, Andrea Crotti wrote: Yes but how do you know how many values you generated when it quits? I mean I don't know how it work internally, but it should keep a temporary list of the yielded values to be able to find out how many values are there.. Iterator unpacking works roughly thus: 1) Count up how many results you need (call that N) 2) N times, get a value from the iterator. If StopIteration is raised, swallow it and raise ValueError because there were too few values. 3) Attempt to get one more value from the iterator. If StopIteration is NOT raised, raise ValueError because there were too many values. At no point is the "total size" of the iterator counted (it could, after all, be infinite). When ValueError is raised, all that's known is that StopIteration wasn't raised at the end of the process. unpack_iterable() has the original object available to it, not just the iterator. It could opportunistically check for __len__() and fall back to the less informative message when it is absent. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
Roy Smith wrote: On Thursday, December 8, 2011 10:03:38 AM UTC-5, Jean-Michel Pichavant wrote: string are iterable, considering this, the error is correct. Yes, I understand that the exception is correct. I'm not saying the exception should be changed, just that we have the opportunity to produce a more useful error message. The exception would be equally correct if it was: ValueError: you did something wrong but most people would probably agree that it's not the most useful message that could have been produced. You have to opportunity to not use unpacking anymore :o) There is a recent thread were the dark side of unpacking was exposed. Unpacking is a cool feautre for very small applications but should be avoided whenever possible otherwise. JM -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On Thu, Dec 8, 2011 at 2:09 PM, Ethan Furman wrote: > Benjamin Kaplan wrote: >> >> On Thu, Dec 8, 2011 at 1:42 PM, Roy Smith wrote: >>> >>> (some, >>> very, >>> long, >>> list, >>> of, >>> variable, >>> names, >>> to, >>> get, >>> the, >>> stuff, >>> unpacked, >>> into) = function_that_should_return_a_14_tuple() >>> >>> raises >>> >>> ValueError: too many values to unpack >>> >>> Quick, what's the bug? Did I forget a variable on the LHS, or is my >>> function returning more things than it should? I know it's supposed to be >>> 14, but I don't know which side is wrong. Had it said "... expected 13, got >>> 14", I would know immediately. >>> >> >> If the RHS was a tuple or a list, yes you could know immediately. But >> unpacking works with any iterable, so it probably doesn't special-case >> lists and tuples. Iterables don't have a size- they just keep going >> until StopIteration is raised. So in EVERY SINGLE CASE, you would get >> "expected n args, got n+1" even if the iterable would return 24 items >> instead of 14, or would never stop returning items. > > > Not so. There could be fewer, in which you could see "expected 13 args, got > 7." > You mean like this? >>> a,b,c = ['a','b'] Traceback (most recent call last): File "", line 1, in ValueError: need more than 2 values to unpack -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
Benjamin Kaplan wrote: On Thu, Dec 8, 2011 at 1:42 PM, Roy Smith wrote: (some, very, long, list, of, variable, names, to, get, the, stuff, unpacked, into) = function_that_should_return_a_14_tuple() raises ValueError: too many values to unpack Quick, what's the bug? Did I forget a variable on the LHS, or is my function returning more things than it should? I know it's supposed to be 14, but I don't know which side is wrong. Had it said "... expected 13, got 14", I would know immediately. If the RHS was a tuple or a list, yes you could know immediately. But unpacking works with any iterable, so it probably doesn't special-case lists and tuples. Iterables don't have a size- they just keep going until StopIteration is raised. So in EVERY SINGLE CASE, you would get "expected n args, got n+1" even if the iterable would return 24 items instead of 14, or would never stop returning items. Not so. There could be fewer, in which you could see "expected 13 args, got 7." ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On Thu, Dec 8, 2011 at 1:42 PM, Roy Smith wrote: > (some, > very, > long, > list, > of, > variable, > names, > to, > get, > the, > stuff, > unpacked, > into) = function_that_should_return_a_14_tuple() > > raises > > ValueError: too many values to unpack > > Quick, what's the bug? Did I forget a variable on the LHS, or is my function > returning more things than it should? I know it's supposed to be 14, but I > don't know which side is wrong. Had it said "... expected 13, got 14", I > would know immediately. > If the RHS was a tuple or a list, yes you could know immediately. But unpacking works with any iterable, so it probably doesn't special-case lists and tuples. Iterables don't have a size- they just keep going until StopIteration is raised. So in EVERY SINGLE CASE, you would get "expected n args, got n+1" even if the iterable would return 24 items instead of 14, or would never stop returning items. > Error messages should be as explicit as possible. It's just like bug > reports. The basic mantra of a bug report is: > > 1) This is what I did > > 2) This is what I expected to happen > > 3) This is what I observed happen > > 4) This is how what I observed differed from what I expected > > Saying, "expected X, got Y" is more explicit than "got too many" > > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
(some, very, long, list, of, variable, names, to, get, the, stuff, unpacked, into) = function_that_should_return_a_14_tuple() raises ValueError: too many values to unpack Quick, what's the bug? Did I forget a variable on the LHS, or is my function returning more things than it should? I know it's supposed to be 14, but I don't know which side is wrong. Had it said "... expected 13, got 14", I would know immediately. Error messages should be as explicit as possible. It's just like bug reports. The basic mantra of a bug report is: 1) This is what I did 2) This is what I expected to happen 3) This is what I observed happen 4) This is how what I observed differed from what I expected Saying, "expected X, got Y" is more explicit than "got too many" -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On 2011-12-08, Roy Smith wrote: > On Thursday, December 8, 2011 10:03:38 AM UTC-5, Jean-Michel Pichavant wrote: >> string are iterable, considering this, the error is correct. > > Yes, I understand that the exception is correct. I'm not saying the > exception should be changed, just that we have the opportunity to produce a > more useful error message. The exception would be equally correct if it was: > > ValueError: you did something wrong My favorite is still the old classic error from and old Unix printer port driver: "lp0 on fire" > but most people would probably agree that it's not the most useful > message that could have been produced. -- Grant Edwards grant.b.edwardsYow! Don't hit me!! I'm in at the Twilight Zone!!! gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On 12/08/11 09:30, Roy Smith wrote: On Thursday, December 8, 2011 9:47:02 AM UTC-5, Robert Kern wrote: Would including the respective numbers help your thought processes? ValueError: too many values to unpack (expected 2, got 3) I don't know if that would have done the trick for me on this particular one. On the other hand, adding "expected X, got Y" to the message would generally be a good thing. given the nature of the message, and the interaction with iterators-of-arbitrary/infinite length, it might have to be reduced to "Expected N, got more" or for the case where you didn't get enough, you know how many you got: "Expected N, but only got M". But the extra information would certainly be useful in tracking it down. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On Fri, Dec 9, 2011 at 2:55 AM, Andrea Crotti wrote: > Yes but how do you know how many values you generated when it quits? > I mean I don't know how it work internally, but it should keep a temporary > list of the yielded values to be able to find out how many values are > there.. Iterator unpacking works roughly thus: 1) Count up how many results you need (call that N) 2) N times, get a value from the iterator. If StopIteration is raised, swallow it and raise ValueError because there were too few values. 3) Attempt to get one more value from the iterator. If StopIteration is NOT raised, raise ValueError because there were too many values. At no point is the "total size" of the iterator counted (it could, after all, be infinite). When ValueError is raised, all that's known is that StopIteration wasn't raised at the end of the process. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On 12/08/2011 03:42 PM, Roy Smith wrote: Why not? Take this example: def i(): i = 0 while True: print "returning:", i yield i i += 1 a, b = i() ./iter.py returning: 0 returning: 1 returning: 2 Traceback (most recent call last): File "./iter.py", line 10, in a, b = i() ValueError: too many values to unpack The exception was raised when i() returned it's third value, so saying "expected 2, got 3" is exactly correct. Yes, it is true that it might have gotten more if it kept going, but that's immaterial; the fact that it got to 3 is what caused the Holy Hand Grenade to be thrown. Yes but how do you know how many values you generated when it quits? I mean I don't know how it work internally, but it should keep a temporary list of the yielded values to be able to find out how many values are there.. -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
Am 08.12.2011 16:42, schrieb Roy Smith: The exception was raised when i() returned it's third value, so saying "expected 2, got 3" is exactly correct. Yes, it is true that it might have gotten more if it kept going, but that's immaterial; the fact that it got to 3 is what caused the Holy Hand Grenade to be thrown. Please explain how that error message (in case you're not aiming at the actual count of elements in the source) differs from the curent wording "too many values", as you're simply displaying "expected n, got n+1" where n is visible from the immediate exception output... -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On Thursday, December 8, 2011 10:16:56 AM UTC-5, Heiko Wundram wrote: > Am 08.12.2011 15:47, schrieb Robert Kern: > > Would including the respective numbers help your thought processes? > > ValueError: too many values to unpack (expected 2, got 3) > > Not possible in the general case (as the right-hand side might be an > arbitrary iterable/iterator...). Why not? Take this example: def i(): i = 0 while True: print "returning:", i yield i i += 1 a, b = i() ./iter.py returning: 0 returning: 1 returning: 2 Traceback (most recent call last): File "./iter.py", line 10, in a, b = i() ValueError: too many values to unpack The exception was raised when i() returned it's third value, so saying "expected 2, got 3" is exactly correct. Yes, it is true that it might have gotten more if it kept going, but that's immaterial; the fact that it got to 3 is what caused the Holy Hand Grenade to be thrown. -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On Thursday, December 8, 2011 10:03:38 AM UTC-5, Jean-Michel Pichavant wrote: > string are iterable, considering this, the error is correct. Yes, I understand that the exception is correct. I'm not saying the exception should be changed, just that we have the opportunity to produce a more useful error message. The exception would be equally correct if it was: ValueError: you did something wrong but most people would probably agree that it's not the most useful message that could have been produced. -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On Thursday, December 8, 2011 9:47:02 AM UTC-5, Robert Kern wrote: > Would including the respective numbers help your thought processes? > > ValueError: too many values to unpack (expected 2, got 3) I don't know if that would have done the trick for me on this particular one. On the other hand, adding "expected X, got Y" to the message would generally be a good thing. -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
Am 08.12.2011 15:47, schrieb Robert Kern: Would including the respective numbers help your thought processes? ValueError: too many values to unpack (expected 2, got 3) Not possible in the general case (as the right-hand side might be an arbitrary iterable/iterator...). -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
Roy Smith wrote: I just spent a while beating my head against this one. # Python 2.6 a, b = 'foo' Traceback (most recent call last): File "", line 1, in ValueError: too many values to unpack The real problem is that there's too *few* values to unpack! It should have been a, b = 'foo', 'bar' I understand why it's generating the exception it does (the string is an iterable), but man, did that message throw off my thought processes and lead me down some totally bogus debugging paths. It's an unusual case to want to unpack a string. Maybe the message should changed to "too {many, few} values to unpack (are you sure you wanted to unpack a string?)" if the RHS is a basestring? string are iterable, considering this, the error is correct. Values to unpack in 'foo' are 'f', 'o', 'o' > a,b,c = 'foo' > print a,b,c f o o JM -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On 12/8/11 2:23 PM, Roy Smith wrote: I just spent a while beating my head against this one. # Python 2.6 a, b = 'foo' Traceback (most recent call last): File "", line 1, in ValueError: too many values to unpack The real problem is that there's too *few* values to unpack! It should have been a, b = 'foo', 'bar' I understand why it's generating the exception it does (the string is an iterable), but man, did that message throw off my thought processes and lead me down some totally bogus debugging paths. It's an unusual case to want to unpack a string. Maybe the message should changed to "too {many, few} values to unpack (are you sure you wanted to unpack a string?)" if the RHS is a basestring? Would including the respective numbers help your thought processes? ValueError: too many values to unpack (expected 2, got 3) -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On Fri, Dec 9, 2011 at 1:23 AM, Roy Smith wrote: > I just spent a while beating my head against this one. > > # Python 2.6 a, b = 'foo' > Traceback (most recent call last): > File "", line 1, in > ValueError: too many values to unpack Definitely weird! I smell a job for a linter though. If you had just happened to have a two-character string there, it would have quietly succeeded, and left you wondering what was going on - imho rather worse. This isn't something for the language to solve; the same issue would come up if you had something like: a=[1,2,3] b=[4,5,6] c,d=a # oops, mucked up the "a,b" side Or any other iterable. Looks to me like a chance for an informational note from your lint facility, not a change to the language. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On 12/08/2011 02:23 PM, Roy Smith wrote: I just spent a while beating my head against this one. # Python 2.6 a, b = 'foo' Traceback (most recent call last): File "", line 1, in ValueError: too many values to unpack The real problem is that there's too *few* values to unpack! It should have been a, b = 'foo', 'bar' I understand why it's generating the exception it does (the string is an iterable), but man, did that message throw off my thought processes and lead me down some totally bogus debugging paths. It's an unusual case to want to unpack a string. Maybe the message should changed to "too {many, few} values to unpack (are you sure you wanted to unpack a string?)" if the RHS is a basestring? I had a few errors sometimes because I thought I passed in a list while I passed only a string, which since it's still iterable would just work but explode later. A nicer message wouldn't have really actually helped though, not sure it's worth to make an exception for such a thing.. -- http://mail.python.org/mailman/listinfo/python-list