New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
difflib should accept arbitrary line iterators #53151
Comments
difflib operates on the lists, but it should be possible to use arbitrary generators. This will require internal limit on buffer size that has a side advantage of limiting difflib to available memory. |
If you allow me to rephrase your feature request to “difflib should allow arbitrary iterators that yield lines”, I’m +1. Adjusting the version and adding tim_one to nosy as per py3k/Misc/maintainers.rst |
A quick look at the code doesn’t immediately tells me that difflib accepts sequences, not only lists. I’m not sure iterators are accepted too. What specific functions or methods have you found too strict? |
'difflib' is a module that defines three classes and some functions. It does not do anything in itself. SequenceMatcher, which is the basis for the other functions, operates on sequences of hashable objects. The inputs must be concrete random access indexed sequences because SequenceMatcher scans the inputs and then jumps around finding good matches and the complementary differences. It is completely unlike functions that take iterables as arguments and than call iter to get an iterator. If S-M took iterables as inputs, it would have to either copy all inputs with list (bad) or figure out whether or not to copy. I think users can continue to pass file.readlines() or list(iterable) as needed. The two functions that mistakenly say inputs are 'lists' instead of 'sequences' will be fixed at part of another issue. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: