Issue 2844: int() lies about base parameter (original) (raw)

Issue2844

Created on 2008-05-13 10:03 by jwilk, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue2844.diff belopolsky,2008-05-13 16:19
issue2844-1.diff belopolsky,2008-05-13 18:23
Messages (10)
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) * (Python committer) 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) * (Python committer) 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) * (Python committer) Date: 2008-05-13 18:30
I'm -1 on complicating these simple functions. Raymond?
msg66805 - (view) Author: Martin v. Löwis (loewis) * (Python committer) 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) * (Python committer) Date: 2008-05-21 00:04
Agreed. Totally a non-issue.
msg106595 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-05-27 07:03
For py3k, this was fixed in r81557.
History
Date User Action Args
2022-04-11 14:56:34 admin set github: 47093
2010-05-27 07:03:21 mark.dickinson set nosy: + mark.dickinsonmessages: +
2008-05-21 00:04:54 rhettinger set messages: +
2008-05-13 21:50:49 loewis set status: open -> closednosy: + loewisresolution: wont fixmessages: +
2008-05-13 18:30:05 georg.brandl set assignee: rhettingermessages: + nosy: + rhettinger, georg.brandl
2008-05-13 18:23:32 belopolsky set files: + issue2844-1.diff
2008-05-13 18:12:35 belopolsky set files: - issue2844-1.diff
2008-05-13 18:10:39 belopolsky set files: - issue2844-1.diff
2008-05-13 18:10:33 belopolsky set files: + issue2844-1.diff
2008-05-13 18:08:23 belopolsky set files: + issue2844-1.diffmessages: +
2008-05-13 16:20:48 belopolsky set versions: + Python 2.6, Python 3.0
2008-05-13 16:19:49 belopolsky set files: + issue2844.diffkeywords: + patch
2008-05-13 16:11:36 jwilk set messages: +
2008-05-13 15:57:14 belopolsky set nosy: + belopolskymessages: +
2008-05-13 11:33:47 hodgestar set messages: +
2008-05-13 11:27:56 hodgestar set nosy: + hodgestarmessages: +
2008-05-13 10:03:54 jwilk create