msg66777 - (view) |
Author: Jakub Wilk (jwilk) |
Date: 2008-05-13 10:03 |
>>> int('42', 42) Traceback (most recent call last): File "", line 1, in ValueError: int() base must be >= 2 and <= 36 >>> int('42', -909) 42 |
|
|
msg66779 - (view) |
Author: Simon Cross (hodgestar) |
Date: 2008-05-13 11:27 |
Some quick digging in the code on trunk has revealed that by the time the base reaches PyInt_FromString in intobject.c, -909 has become 10. Surrounding numbers seem to come through fine. |
|
|
msg66780 - (view) |
Author: Simon Cross (hodgestar) |
Date: 2008-05-13 11:33 |
In int_new in intobject.c the base -909 is used to indicate that no base has been passed through (presumably because NULL / 0 is a more common pitfall that -909). Thus -909 is equivalent to base 10. |
|
|
msg66784 - (view) |
Author: Alexander Belopolsky (belopolsky) *  |
Date: 2008-05-13 15:57 |
The same issue is present in long_new: >>> long('42', -909) 42L I don't see why any magic value is needed, 10 would do the trick. |
|
|
msg66785 - (view) |
Author: Jakub Wilk (jwilk) |
Date: 2008-05-13 16:11 |
10 would *not* do the trick: >>> int(42) 42 >>> int(42, 10) Traceback (most recent call last): File "", line 1, in TypeError: int() can't convert non-string with explicit base |
|
|
msg66787 - (view) |
Author: Alexander Belopolsky (belopolsky) *  |
Date: 2008-05-13 18:08 |
> 10 would *not* do the trick: You are right. I guess something like -1.diff will be necessary. I am not sure it is worth the trouble, though. Maybe just change -909 to -MAX_INT? Jakub, how did you discover this in the first place? |
|
|
msg66788 - (view) |
Author: Georg Brandl (georg.brandl) *  |
Date: 2008-05-13 18:30 |
I'm -1 on complicating these simple functions. Raymond? |
|
|
msg66805 - (view) |
Author: Martin v. Löwis (loewis) *  |
Date: 2008-05-13 21:50 |
I don't see the problem at all. The -909 value is an implementation artefact, and the submitter probably wouldn't have known it existed without reading the source code. Perhaps we should change it to something different every Python release just to denote that it is deliberately undocumented. Closing as "won't fix". |
|
|
msg67139 - (view) |
Author: Raymond Hettinger (rhettinger) *  |
Date: 2008-05-21 00:04 |
Agreed. Totally a non-issue. |
|
|
msg106595 - (view) |
Author: Mark Dickinson (mark.dickinson) *  |
Date: 2010-05-27 07:03 |
For py3k, this was fixed in r81557. |
|
|