On Wed, 22 Apr 2015 01:09:52 +1000, Chris Angelico <ros...@gmail.com> wrote: > def incremental_parser(input: FileLike) -> List[Token]: > tokens = [] > data = "" > while True: > if not data: > data = input.read(64) > token = Token(data[0]); data = data[1:] > while token.wants_more(): > token.give_more(data[0]); data = data[1:] > tokens.append(token) > if token.is_end_of_stream(): break > input.seek(-len(data), 1) > return tokens > > If you were to exhaustively stipulate the requirements on the > file-like object, you'd have to say: > > * Provides a read() method which takes an integer and returns up to > that many bytes > * Provides a seek() method which takes two integers > * Is capable of relative seeking by at least 63 bytes backward > * Is open for reading > * Etcetera > > That's not the type system's job. Not in Python. Maybe in Haskell, but
Just a note that if I'm reading the high level description right, this kind of analysis is exactly the kind of thing that Flow does for javascript. --David _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com