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 Token
s).
What type annotation should I use?