Issue1758325

classification
Title: str's formatter doesn't raise TypeError if given wrong type
Type: Severity: normal
Components: None Versions:
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: cgroves, leosoto, mehendran, pjenvey
Priority: normal Keywords: test failure causes

Created on 2007-07-22.04:50:40 by cgroves, last changed 2008-08-21.03:27:44 by leosoto.

Messages
msg1783 (view) Author: Charlie Groves (cgroves) Date: 2007-07-22.04:50:40
Passing a str as a numeric argument to format doesn't raise a TypeError

ie '%d' % '1' should raise TypeError.

test_format.py checks for this and fails as a result.
msg1784 (view) Author: Charlie Groves (cgroves) Date: 2007-08-06.00:04:02
See http://wiki.python.org/jython/JythonDeveloperGuide/VersionTransitionTestExclusions for how to get the test running again to fix this.
msg1785 (view) Author: Mehendran (mehendran) Date: 2007-08-22.16:29:07
I am looking at this bug. 
I will come with a patch for this very soon.
msg3241 (view) Author: Philip Jenvey (pjenvey) Date: 2008-06-08.00:18:14
The root of the problem is that PyString defines an __int__ method. 
__int__ is being used by the string formatter to convert any object to a 
number.

__int__ is really equivalent to CPython's tp_as_number nb_int. The 
tp_as_number interface in CPython is only defined for actual number 
types (float/long etc), not string.

__int__ really *is* what the string formatter should be calling (to get 
an integer from strictly numeric types) but the fact that PyString 
provides it means we get a conversion instead of an error here

CPython converts strings to ints (int('foo')) in a more explicit way; it 
first looks for the tp_as_number interface, and if that's not supported, 
explicitly checks for strings
msg3319 (view) Author: Leonardo Soto (leosoto) Date: 2008-07-05.20:11:12
This seems to be fixed on the asm branch.
msg3444 (view) Author: Leonardo Soto (leosoto) Date: 2008-08-21.03:27:43
Marking as fixed, as test_format runs fine now on trunk
History
Date User Action Args
2008-08-21 03:27:44leosotosetstatus: open -> closed
resolution: fixed
messages: + msg3444
2008-07-05 20:11:12leosotosetnosy: + leosoto
messages: + msg3319
2008-06-08 00:18:15pjenveysetnosy: + pjenvey
messages: + msg3241
2007-07-22 04:50:40cgrovescreate