gh-118150: difflib: expose autojunk flag from SequenceMatcher to public methods and functions - #153959
Merged
Merged
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 |
Contributor
Author
|
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)) |
This was referenced Jul 18, 2026
Contributor
|
I think the Documentation ( |
Lenormju
reviewed
Jul 18, 2026
faithlesstomas
requested review from
AA-Turner,
JacobCoffee,
ezio-melotti,
hugovk,
itamaro and
webknjaz
as code owners
July 22, 2026 11:44
hugovk
reviewed
Jul 24, 2026
hugovk
left a comment
Member
There was a problem hiding this comment.
Please could you add tests to Lib/test/test_difflib.py?
hugovk
reviewed
Jul 24, 2026
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
108 files changed ·
|
encukou
reviewed
Aug 10, 2026
encukou
left a comment
Member
There was a problem hiding this comment.
The change looks good; let's make the docs great :)
webknjaz
removed their request for review
August 10, 2026 21:15
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.
encukou
enabled auto-merge (squash)
September 4, 2026 13:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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