The encode_iterable method that students implement in the Tokenizer class accepts an iterable of strings. A straightforward but incorrect implementation is to iterate over the strings and yield from the output of encode for each string independently.
This approach can split pretokens across iterable boundaries. For example, consider the iterable:
["test\n", "\n", "string"]
This is similar to what you might get when iterating over a Python file pointer for a text file like:
If encode_iterable processes each string independently, the two newline characters will be tokenized separately rather than as the combined pretoken \n\n.
Currently, tests/test_tokenizer.py does not cover this edge case. I added a test for this scenario on this branch:
https://github.com/harrison-f-stropkay/assignment1-basics/tree/multi-newline-test-case
I'd open a PR, but I don't believe I have the necessary permissions.
The
encode_iterablemethod that students implement in theTokenizerclass accepts an iterable of strings. A straightforward but incorrect implementation is to iterate over the strings andyield fromthe output ofencodefor each string independently.This approach can split pretokens across iterable boundaries. For example, consider the iterable:
This is similar to what you might get when iterating over a Python file pointer for a text file like:
If
encode_iterableprocesses each string independently, the two newline characters will be tokenized separately rather than as the combined pretoken\n\n.Currently,
tests/test_tokenizer.pydoes not cover this edge case. I added a test for this scenario on this branch:https://github.com/harrison-f-stropkay/assignment1-basics/tree/multi-newline-test-case
I'd open a PR, but I don't believe I have the necessary permissions.