Issue 17080: A better error message for float() (original) (raw)

Created on 2013-01-30 08:33 by Jonathan.Livni, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue17080.diff ezio.melotti,2013-01-30 08:47 review
issue17080-2.diff ezio.melotti,2013-02-01 02:24 review
Messages (9)
msg180967 - (view) Author: Jonathan Livni (Jonathan.Livni) Date: 2013-01-30 08:33
These lines of Python (2.7): y = float(x) gives the error: TypeError: float() argument must be a string or a number. In various cases such as: x = [0] x = None x = SomeClass() In addition to the information given in the error message, it could help, for debugging purposes, to state the type of the object given.
msg180968 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-01-30 08:35
Sounds reasonable to me.
msg180969 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-01-30 08:47
Here's an initial patch, still needs tests. The same should be done for complex() too. Maybe it could be applied to older branches too.
msg180971 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-01-30 09:49
You should put single quotes around the type name, i.e.: "float() argument must be a string or a number, not '%.200s'"
msg180972 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-01-30 09:59
I was thinking about that but in other places they are not used. Adding them is OK though.
msg181053 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-02-01 02:24
Attached a new patch with tests. I added the quotes around the type and fixed complex() too.
msg181073 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-02-01 10:09
LGTM.
msg202370 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-11-07 17:18
New changeset a73c47c1d374 by Ezio Melotti in branch 'default': #17080: improve error message of float/complex when the wrong type is passed. http://hg.python.org/cpython/rev/a73c47c1d374
msg202371 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-11-07 17:19
Fixed, thanks for the review.
History
Date User Action Args
2022-04-11 14:57:41 admin set github: 61282
2013-12-24 14:57:18 r.david.murray link issue20060 superseder
2013-11-07 17:19:23 ezio.melotti set status: open -> closedresolution: fixedmessages: + stage: patch review -> resolved
2013-11-07 17🔞52 python-dev set nosy: + python-devmessages: +
2013-02-01 10:09:49 serhiy.storchaka set nosy: + serhiy.storchakamessages: +
2013-02-01 02:24:14 ezio.melotti set files: + issue17080-2.diffmessages: +
2013-01-30 09:59:01 ezio.melotti set messages: +
2013-01-30 09:49:35 pitrou set nosy: + pitroumessages: + stage: needs patch -> patch review
2013-01-30 08:47:54 ezio.melotti set files: + issue17080.diffassignee: ezio.melottimessages: + keywords: + patch
2013-01-30 08:41:26 kushal.das set nosy: + kushal.das
2013-01-30 08:35:56 ezio.melotti set versions: + Python 3.4, - Python 2.7nosy: + ezio.melottimessages: + stage: needs patch
2013-01-30 08:33:13 Jonathan.Livni create