Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

int() lies about base parameter #47093

Closed
jwilk mannequin opened this issue May 13, 2008 · 10 comments
Closed

int() lies about base parameter #47093

jwilk mannequin opened this issue May 13, 2008 · 10 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@jwilk
Copy link
Mannequin

jwilk mannequin commented May 13, 2008

BPO 2844
Nosy @loewis, @birkenfeld, @rhettinger, @mdickinson, @abalkin, @jwilk
Files
  • issue2844.diff
  • issue2844-1.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/rhettinger'
    closed_at = <Date 2008-05-13.21:50:49.756>
    created_at = <Date 2008-05-13.10:03:54.604>
    labels = ['type-bug', 'library']
    title = 'int() lies about base parameter'
    updated_at = <Date 2010-05-27.07:03:21.714>
    user = 'https://github.com/jwilk'

    bugs.python.org fields:

    activity = <Date 2010-05-27.07:03:21.714>
    actor = 'mark.dickinson'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2008-05-13.21:50:49.756>
    closer = 'loewis'
    components = ['Library (Lib)']
    creation = <Date 2008-05-13.10:03:54.604>
    creator = 'jwilk'
    dependencies = []
    files = ['10316', '10319']
    hgrepos = []
    issue_num = 2844
    keywords = ['patch']
    message_count = 10.0
    messages = ['66777', '66779', '66780', '66784', '66785', '66787', '66788', '66805', '67139', '106595']
    nosy_count = 7.0
    nosy_names = ['loewis', 'georg.brandl', 'rhettinger', 'mark.dickinson', 'belopolsky', 'jwilk', 'hodgestar']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue2844'
    versions = ['Python 2.6', 'Python 2.5', 'Python 2.4', 'Python 3.0']

    @jwilk
    Copy link
    Mannequin Author

    jwilk mannequin commented May 13, 2008

    >>> 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

    @jwilk jwilk mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels May 13, 2008
    @hodgestar
    Copy link
    Mannequin

    hodgestar mannequin commented May 13, 2008

    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.

    @hodgestar
    Copy link
    Mannequin

    hodgestar mannequin commented May 13, 2008

    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.

    @abalkin
    Copy link
    Member

    abalkin commented May 13, 2008

    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.

    @jwilk
    Copy link
    Mannequin Author

    jwilk mannequin commented May 13, 2008

    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

    @abalkin
    Copy link
    Member

    abalkin commented May 13, 2008

    10 would *not* do the trick:

    You are right. I guess something like bpo-2844-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?

    @birkenfeld
    Copy link
    Member

    I'm -1 on complicating these simple functions. Raymond?

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented May 13, 2008

    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".

    @loewis loewis mannequin closed this as completed May 13, 2008
    @rhettinger
    Copy link
    Contributor

    Agreed. Totally a non-issue.

    @mdickinson
    Copy link
    Member

    For py3k, this was fixed in r81557.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants