Skip to content

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

Closed

Description

@mdickinson
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']

    Activity

    1. mdickinson commented on Jan 27, 2009

      @mdickinson
      MemberAuthor

      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.

    2. added
      type-bug
      on Jan 27, 2009
    3. birkenfeld commented on Sep 4, 2009

      @birkenfeld
      Member

      +1.

    4. vstinner commented on Sep 7, 2009

      @vstinner
      Member

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

    5. self-assigned this
      on Nov 18, 2009
    6. pitrou commented on Nov 19, 2009

      @pitrou
      Member

      +1 for a TypeError too.

    7. pitrou commented on Nov 20, 2009

      @pitrou
      Member

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

    8. mdickinson commented on Nov 20, 2009

      @mdickinson
      MemberAuthor

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

    9. mdickinson commented on Dec 20, 2009

      @mdickinson
      MemberAuthor

      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.

    10. mdickinson commented on Dec 20, 2009

      @mdickinson
      MemberAuthor

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

    11. mdickinson commented on Dec 21, 2009

      @mdickinson
      MemberAuthor

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

    12. mdickinson commented on Jan 1, 2010

      @mdickinson
      MemberAuthor

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

    13. mdickinson commented on Jan 1, 2010

      @mdickinson
      MemberAuthor

      Merged relevant bits to py3k in r77220.

    14. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    type-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions