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

file.readline: bad exception recovery #47771

Closed
terryjreedy opened this issue Aug 7, 2008 · 5 comments
Closed

file.readline: bad exception recovery #47771

terryjreedy opened this issue Aug 7, 2008 · 5 comments
Assignees
Labels
easy interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@terryjreedy
Copy link
Member

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

    @terryjreedy
    Copy link
    Member Author

    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.

    @terryjreedy terryjreedy added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Aug 7, 2008
    @gvanrossum
    Copy link
    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.)

    @gvanrossum gvanrossum added the easy label Aug 7, 2008
    @devdanzin
    Copy link
    Mannequin

    devdanzin mannequin commented Aug 27, 2008

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

    @devdanzin
    Copy link
    Mannequin

    devdanzin mannequin commented Feb 8, 2009

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

    @benjaminp benjaminp self-assigned this Apr 22, 2009
    @benjaminp
    Copy link
    Contributor

    Fixed in r71855

    @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
    easy interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants