Skip to content

mypy dislikes next() on file objects #2111

Closed

Description

@jhagerer

When mypy analyzes the following code:

filename = 'some.txt'
with open(filename) as fh:
    c = cast(TextIOWrapper, fh)
    next(c)  # skip line

it yields the following error:
error: No overload variant of "next" matches argument types [io.TextIOWrapper]

Since TextIOWrapper implements the next() method (which is even autocompleted by PyCharm IDE), I would not expect this error to be thrown.

Activity

  1. jhagerer commented on Sep 8, 2016

    @jhagerer
    Author

    For the moment I make a workaround like this:

    fh = cast(TextIOWrapper, open(filename))
    fh.__next__()
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions