gh-118150: difflib: expose autojunk flag from SequenceMatcher to public methods and functions - #153959
gh-118150: difflib: expose autojunk flag from SequenceMatcher to public methods and functions#153959faithlesstomas wants to merge 27 commits into
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
Quick check if this works for the original issue test: #!/usr/bin/python3
import difflib
def get_lines(filename):
with open(filename, 'r', encoding='utf8') as fd:
return fd.readlines()
for autojunk in (True, False):
old_new = list(difflib.unified_diff(
get_lines('small.external.old.json'),
get_lines('small.external.new.json'),
autojunk=autojunk
))
new_old = list(difflib.unified_diff(
get_lines('small.external.new.json'),
get_lines('small.external.old.json'),
autojunk=autojunk
))
print('Autojunk flag:', autojunk)
print('diff external.old external.new.json | wc -l')
print(len(old_new))
print('diff external.new external.old.json | wc -l')
print(len(new_old)) |
|
I think the Documentation ( |
hugovk
left a comment
There was a problem hiding this comment.
Please could you add tests to Lib/test/test_difflib.py?
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
…python#153959) * Add tests in `TestAutojunk` verifying `autojunk` propagation and behavior across `get_close_matches`, `Differ`, `ndiff`, `unified_diff`, `context_diff`, and `HtmlDiff`. * Add signature inspection tests using `inspect.signature` to verify that `autojunk=True` is present and defined as a keyword-only parameter. * Fix passing of `autojunk` as a keyword argument in `difflib._mdiff()` call to `ndiff()`.
…junk * fixed conflicts in Doc/library/difflib.rst
Documentation build overview
19 files changed ·
|
encukou
left a comment
There was a problem hiding this comment.
The change looks good; let's make the docs great :)
| .. versionchanged:: 3.16 | ||
| Added keyword-only *autojunk* parameter. | ||
|
|
||
| Optional *autojunk* flag sets on/off automatic junk heuristic of :class:`SequenceMatcher`. |
There was a problem hiding this comment.
There's now a section for the heuristic in the description; it would be good to link there:
| Optional *autojunk* flag sets on/off automatic junk heuristic of :class:`SequenceMatcher`. | |
| Setting the optional *autojunk* argument to ``False`` will turn | |
| :ref:`automatic junk heuristic <difflib-junk>` off. |
Please use the same wording for all of these (unless there's a difference that needs to be pointed out).
There was a problem hiding this comment.
This is still relevant:
Please use the same wording for all of these (unless there's a difference that needs to be pointed out).
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Add references to junk heuristic description section for *autojunk* kwarg.
Updating description of *autojunk* kwarg to have exactly the same wording everywhere.
Until now difflib methods and functions took SequenceMatcher class kwarg autojunk by default which is set up to be True in this class.. This PR aims to expose this flag to the public methods and functions of this module, in order that user can choose behavior of this option in SequenceMatcher.
Issue: #118150
Related PR: #153892