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: int() lies about base parameter
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.0, Python 2.4, Python 2.6, Python 2.5
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: belopolsky, georg.brandl, hodgestar, jwilk, loewis, mark.dickinson, rhettinger
Priority: normal Keywords: patch

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 "<stdin>", line 1, in <module>
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 "<stdin>", line 1, in <module>
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 issue2844-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:34adminsetgithub: 47093
2010-05-27 07:03:21mark.dickinsonsetnosy: + mark.dickinson
messages: + msg106595
2008-05-21 00:04:54rhettingersetmessages: + msg67139
2008-05-13 21:50:49loewissetstatus: open -> closed
nosy: + loewis
resolution: wont fix
messages: + msg66805
2008-05-13 18:30:05georg.brandlsetassignee: rhettinger
messages: + msg66788
nosy: + rhettinger, georg.brandl
2008-05-13 18:23:32belopolskysetfiles: + issue2844-1.diff
2008-05-13 18:12:35belopolskysetfiles: - issue2844-1.diff
2008-05-13 18:10:39belopolskysetfiles: - issue2844-1.diff
2008-05-13 18:10:33belopolskysetfiles: + issue2844-1.diff
2008-05-13 18:08:23belopolskysetfiles: + issue2844-1.diff
messages: + msg66787
2008-05-13 16:20:48belopolskysetversions: + Python 2.6, Python 3.0
2008-05-13 16:19:49belopolskysetfiles: + issue2844.diff
keywords: + patch
2008-05-13 16:11:36jwilksetmessages: + msg66785
2008-05-13 15:57:14belopolskysetnosy: + belopolsky
messages: + msg66784
2008-05-13 11:33:47hodgestarsetmessages: + msg66780
2008-05-13 11:27:56hodgestarsetnosy: + hodgestar
messages: + msg66779
2008-05-13 10:03:54jwilkcreate