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: [decimal] ValueError -> TypeError in from_tuple
Type: Stage:
Components: Versions:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: mark.dickinson Nosy List: mark.dickinson, rhettinger, skrah
Priority: normal Keywords:

Created on 2010-01-30 14:16 by skrah, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg98564 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2010-01-30 14:16
As discussed privately, the following test cases should raise TypeError
(currently ValueError):

self.assertRaises(TypeError, Decimal, (0., (4, 3, 4, 9, 1), 2) )
self.assertRaises(TypeError, Decimal, (Decimal(1), (4, 3, 4, 9, 1), 2))
self.assertRaises(TypeError, Decimal, (1, (4, 3, 4, 9, 1), 0.) )
self.assertRaises(TypeError, Decimal, (1, (4, 3, 4, None, 1), 2) )
self.assertRaises(TypeError, Decimal, (1, (4, 3, 4, 'a', 1), 2) )
msg103342 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-04-16 16:42
It's a bit ambiguous:  the object being supplied to the Decimal constructor does have the right type (tuple), but the wrong contents (i.e., value).  So you could argue either way on this, I guess.
msg103351 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-04-16 18:59
A ValueError seems more appropriate to me.
msg103356 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-04-16 20:10
From both practical and purity points of view I think I prefer TypeError for the cases Stefan gives: if you're passing a float for the sign, then you've somehow ended up with the wrong type for that sign, and that's a TypeError rather than a ValueError.
msg103361 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-04-16 21:03
I could see a TypeError for the outer tuple a tuple wasn't passed-in.  If the contents aren't what we expect, I believe that calling it a ValueError is the Python way.
msg103428 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-04-17 20:07
Given the lack of agreement here, I propose that we just leave the current code as it is;  it doesn't seem like a big issue to me, and we should resist messing with code that isn't clearly broken.
History
Date User Action Args
2022-04-11 14:56:57adminsetgithub: 52059
2010-04-17 23:17:01rhettingersetstatus: pending -> closed
2010-04-17 20:07:53mark.dickinsonsetstatus: open -> pending
resolution: wont fix
messages: + msg103428
2010-04-16 21:03:01rhettingersetmessages: + msg103361
2010-04-16 20:10:06mark.dickinsonsetmessages: + msg103356
2010-04-16 18:59:43rhettingersetnosy: + rhettinger
messages: + msg103351
2010-04-16 16:42:20mark.dickinsonsetassignee: mark.dickinson
messages: + msg103342
2010-01-30 14:16:17skrahcreate