Skip to content

file.readline: bad exception recovery #47771

Closed

Description

@terryjreedy
BPO 3521
Nosy @gvanrossum, @terryjreedy, @devdanzin, @benjaminp
Files
  • file.readline.diff: Adds isinstance(limit, int) to io.X.readline
  • 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/benjaminp'
    closed_at = <Date 2009-04-24.23:00:33.794>
    created_at = <Date 2008-08-07.22:36:50.012>
    labels = ['interpreter-core', 'easy', 'type-bug']
    title = 'file.readline: bad exception recovery'
    updated_at = <Date 2009-04-24.23:00:33.793>
    user = 'https://github.com/terryjreedy'

    bugs.python.org fields:

    activity = <Date 2009-04-24.23:00:33.793>
    actor = 'benjamin.peterson'
    assignee = 'benjamin.peterson'
    closed = True
    closed_date = <Date 2009-04-24.23:00:33.794>
    closer = 'benjamin.peterson'
    components = ['Interpreter Core']
    creation = <Date 2008-08-07.22:36:50.012>
    creator = 'terry.reedy'
    dependencies = []
    files = ['11276']
    hgrepos = []
    issue_num = 3521
    keywords = ['patch', 'easy']
    message_count = 5.0
    messages = ['70866', '70867', '72049', '81364', '86437']
    nosy_count = 4.0
    nosy_names = ['gvanrossum', 'terry.reedy', 'ajaksu2', 'benjamin.peterson']
    pr_nums = []
    priority = 'high'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue3521'
    versions = ['Python 3.0']

    Activity

    1. terryjreedy commented on Aug 7, 2008

      @terryjreedy
      MemberAuthor
      WinXP, 3.0b2
      >>>f=open('somefile', 'r')
      >>>f.readline(somefloat)
      Traceback (most recent call last):
        File "<pyshell#70>", line 1, in <module>
          f.readline(1.0)
        File "C:\Program Files\Python30\lib\io.py", line 1766, in readline
          return line[:endpos]
      TypeError: slice indices must be integers or None or have an __index__
      method

      At this point, any f.read or f.readline calls fail with a similar
      TypeError. The error recovery seems incomplete. The same does *not*
      happen with f.read(float). Recovery is complete and subsequent
      f.read/f.readline calls work.

      In 2.5, float size arg worked with a deprecation warning, so issue does
      not arise. I presume same is true in 2.6.

    2. added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      type-bugAn unexpected behavior, bug, or error
      on Aug 7, 2008
    3. gvanrossum commented on Aug 7, 2008

      @gvanrossum
      Member

      Good catch!

      This looks pretty simple to fix; I think a type check is missing
      (actually several, there are at least two implementations in io.py).

      In fact, the 2.6 version of io.py already has the necessary checks.
      (But merging those forward is not 100% trivial since in 3.0 the 'long'
      type doesn't exist.)

    4. devdanzin commented on Aug 27, 2008

      devdanzinmannequin
      Mannequin

      Patch attached, suggested test below.

      def test_readline():
          for mode in ('r', 'rb', 'r+', 'r+b'):
              f = open(__file__, mode)
              try:
                  f.readline(0.1)
              except TypeError:
                  tmp = f.readline()
              f.close()
          print('OK')
      
      test_readline()
    5. devdanzin commented on Feb 8, 2009

      devdanzinmannequin
      Mannequin

      Maybe this one should be in 3.0.1? Benchmarking the isinstance approach
      against int() would be interesting.

      The io-c branch doesn't have this bug, so 3.1 is OK :)

    6. self-assigned this
      on Apr 22, 2009
    7. benjaminp commented on Apr 24, 2009

      @benjaminp
      Contributor

      Fixed in r71855

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

    easyinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions