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

PyArg_Parse* should raise TypeError for float parsed with integer format #49330

Closed
mdickinson opened this issue Jan 27, 2009 · 11 comments
Closed
Assignees
Labels
type-bug An unexpected behavior, bug, or error

Comments

@mdickinson
Copy link
Member

BPO 5080
Nosy @birkenfeld, @mdickinson, @pitrou, @vstinner, @ezio-melotti
Files
  • issue5080.patch
  • 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/mdickinson'
    closed_at = <Date 2010-01-01.19:30:02.485>
    created_at = <Date 2009-01-27.12:23:56.157>
    labels = ['type-bug']
    title = 'PyArg_Parse* should raise TypeError for float parsed with integer format'
    updated_at = <Date 2010-01-01.19:30:02.484>
    user = 'https://github.com/mdickinson'

    bugs.python.org fields:

    activity = <Date 2010-01-01.19:30:02.484>
    actor = 'mark.dickinson'
    assignee = 'mark.dickinson'
    closed = True
    closed_date = <Date 2010-01-01.19:30:02.485>
    closer = 'mark.dickinson'
    components = []
    creation = <Date 2009-01-27.12:23:56.157>
    creator = 'mark.dickinson'
    dependencies = []
    files = ['15649']
    hgrepos = []
    issue_num = 5080
    keywords = ['patch']
    message_count = 11.0
    messages = ['80649', '92239', '92400', '95497', '95538', '95541', '96689', '96692', '96751', '97118', '97120']
    nosy_count = 6.0
    nosy_names = ['georg.brandl', 'mark.dickinson', 'pitrou', 'vstinner', 'ezio.melotti', 'marcin.wider']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue5080'
    versions = ['Python 2.7', 'Python 3.2']

    @mdickinson
    Copy link
    Member Author

    Since Python 2.3, PyArg_ParseTuple and friends give a DeprecationWarning
    for floating-point arguments where integers are expected. From
    http://www.python.org/download/releases/2.3/NEWS.txt:

    • The PyArg_Parse functions now issue a DeprecationWarning if a float
      argument is provided when an integer is specified (this affects the 'b',
      'B', 'h', 'H', 'i', and 'l' codes). Future versions of Python will
      raise a TypeError.

    Can we turn that DeprecationWarning into a TypeError for 2.7? (It's
    already a TypeError in 3.x.) I'd like to see things like 'range(-0.3)'
    and 'itertools.combinations(range(3), 5.1)' raise TypeError.

    N.B. The relevant format codes in 2.7 include 'I' and 'n' in addition to
    the six codes listed above.

    @mdickinson mdickinson added the type-bug An unexpected behavior, bug, or error label Jan 27, 2009
    @birkenfeld
    Copy link
    Member

    +1.

    @vstinner
    Copy link
    Member

    vstinner commented Sep 7, 2009

    +10. It would fix the os.urandom(1.2) bug. On Linux, os.urandom() displays
    the following warnings and then go into an unlimited loop...

    /usr/lib/python2.5/os.py:734: DeprecationWarning: integer argument expected,
    got float
    bytes += read(_urandomfd, n - len(bytes))

    read(1.2 - 1) ~> read(0.2) ~> read(0)...

    Tolerate float as integers introduces "subtle" bugs like byte/unicode bugs...

    @mdickinson mdickinson self-assigned this Nov 18, 2009
    @pitrou
    Copy link
    Member

    pitrou commented Nov 19, 2009

    +1 for a TypeError too.

    @pitrou
    Copy link
    Member

    pitrou commented Nov 20, 2009

    I think this should be signalled on the mailing-list, by the way. I
    expect everyone to agree of course :)

    @mdickinson
    Copy link
    Member Author

    Yes, checking with python-dev sounds sensible. I'll wait until there's
    a working patch, though.

    @mdickinson
    Copy link
    Member Author

    Hmm. That's unfortunate: for argument type in 'bBHiIlkKn', an attempt to
    pass a float results in a DeprecationWarning. For type 'L', there's no
    DeprecationWarning, and the float is silently truncated. So for type 'L'
    I guess we still have to go through a round of DeprecationWarning.

    I'm not sure what 'h' does; there don't appear to be any tests for it,
    currently.

    @mdickinson
    Copy link
    Member Author

    'h' also produces a DeprecationWarning; I just added the missing tests
    for it in r76930 (trunk) and r76931 (py3k).

    @mdickinson
    Copy link
    Member Author

    Here's a patch that makes the DeprecationWarning a TypeError, and adds a
    new DeprecationWarning for the 'L' format.

    @mdickinson
    Copy link
    Member Author

    Applied to trunk in r77218. The DeprecationWarning for the 'L' format
    needs to be merged to py3k.

    @mdickinson
    Copy link
    Member Author

    Merged relevant bits to py3k in r77220.

    @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
    type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants