Skip to content

gh-118150: warn in doc about results asymmetry for difflib junk#153892

Open
Lenormju wants to merge 4 commits into
python:mainfrom
Lenormju:gh-118150-difflib-autojunk-asymmetry-doc
Open

gh-118150: warn in doc about results asymmetry for difflib junk#153892
Lenormju wants to merge 4 commits into
python:mainfrom
Lenormju:gh-118150-difflib-autojunk-asymmetry-doc

Conversation

@Lenormju

@Lenormju Lenormju commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

@python-cla-bot

python-cla-bot Bot commented Jul 18, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app bedevere-app Bot added the docs Documentation in the Doc dir label Jul 18, 2026
@github-project-automation github-project-automation Bot moved this to Todo in Docs PRs Jul 18, 2026
@read-the-docs-community

read-the-docs-community Bot commented Jul 18, 2026

Copy link
Copy Markdown

@encukou encukou added the sprint label Jul 18, 2026
@github-project-automation github-project-automation Bot moved this to Todo in Sprint Jul 18, 2026
@encukou encukou self-assigned this Jul 18, 2026
Comment thread Doc/library/difflib.rst Outdated
Comment thread Doc/library/difflib.rst Outdated

This heuristic only ever inspects the second sequence for junk. That has
an unexpected consequence: swapping the inputs can produce a different
diff than simply reversing the output, sometimes very large.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds ungrammatical.
Do we need to note that output can be very large?

Suggested change
diff than simply reversing the output, sometimes very large.
diff than reversing the output.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think yes, because it is the original issue, and the most unexpected behavior. #118150 describes a pathological case where, depending on the inputs' order, the diff can be 1186x bigger. I call that surprising, and very large. In this case, it was because most lines got autojunked.

I will fix the grammar right now, sorry for that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reworded the two junk-related paragraphs.
About the size:

But it can also cause pathological cases where too many items considered junk cause an unexpectedly large (but correct) diff result.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, is it the only case that can produce unexpectedly large result?
Your wording tends to imply that avoiding junk will result in “good” and small results.

Comment thread Doc/library/difflib.rst Outdated
Comment thread Doc/library/difflib.rst
Comment on lines 22 to 25
.. class:: SequenceMatcher
:noindex:

This is a flexible class for comparing pairs of sequences of any type, so long

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about making this an introduction to the difflib module, rather than docs for the SequenceMatcher class (which is documented properly below)?

Something like this, plus dedenting it:

All functionality in this module uses the algorithm implemented in
:class:`SequenceMatcher`, a flexible class for comparing pairs
of sequences of any type, so long […]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir sprint

Projects

Status: Todo
Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants