Correct type annotation for a peekable iterator from more-itertools?

177 Views Asked by At

This code doesn't type-check:

def parse_expression(lex: Iterator[Token]) -> Expression:
    left = parse_term(lex)
    if lex.peek(): # ERROR
        # ...

The error message is Cannot access member "peek" for type "Iterator[Token]", which is probably expected.

The argument I want to pass to this method is more_itertools.peekable(lex(src)). lex returns an Iterable[Token] (yields Tokens).

What type annotation should I use?

0

There are 0 best solutions below