FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-118150: difflib: expose autojunk flag from SequenceMatcher to public methods and functions by faithlesstomas · Pull Request #153959 · python/cpython · GitHub

Repository navigation

gh-118150: difflib: expose autojunk flag from SequenceMatcher to public methods and functions - #153959

Merged
encukou merged 29 commits into
python:mainfrom
faithlesstomas:gh-118150-expose-autojunk
Sep 4, 2026
Merged

encukou merged 29 commits into
python:mainfrom
faithlesstomas:gh-118150-expose-autojunk

Conversation

faithlesstomas commented Jul 18, 2026 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

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

python-cla-bot Bot commented Jul 18, 2026 •
edited
Loading

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

bedevere-app Bot commented Jul 18, 2026

Copy link
Copy Markdown

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 skip news label instead.

faithlesstomas commented Jul 18, 2026 •
edited
Loading

Copy link
Copy Markdown
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))                                                                                                                                                     
Autojunk flag: True
diff external.old external.new.json | wc -l
90
diff -u external.new external.old.json | wc -l
25
Autojunk flag: False
diff external.old external.new.json | wc -l
25
diff -u external.new external.old.json | wc -l
25

#118150 (comment)

faithlesstomas changed the title difflib: expose autojunk flag from SequenceMatcher to public methods and functions gh-118150: difflib: expose autojunk flag from SequenceMatcher to public methods and functions Jul 18, 2026

Copy link
Copy Markdown
Contributor

I think the Documentation (Doc/library/difflib.rst) should get updated too to include this new parameter.

hugovk left a comment

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Please could you add tests to Lib/test/test_difflib.py?

Comment thread .github/workflows/build.yml Outdated
Comment thread Lib/difflib.py Outdated
Comment thread Lib/difflib.py Outdated
Comment thread Lib/difflib.py Outdated
Comment thread Lib/difflib.py Outdated
Comment thread Lib/difflib.py Outdated
Comment thread Lib/difflib.py Outdated
Comment thread Lib/difflib.py Outdated
faithlesstomas and others added 9 commits August 5, 2026 01:04
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

read-the-docs-community Bot commented Aug 5, 2026 •
edited
Loading

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34393160 | 📁 Comparing d8dff8a against main (dd5a285)

  🔍 Preview build  

108 files changed · + 1 added · ± 107 modified

+ Added

± Modified

encukou left a comment

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The change looks good; let's make the docs great :)

Comment thread Doc/library/difflib.rst Outdated
Comment thread Doc/library/difflib.rst Outdated
Comment thread Doc/library/difflib.rst Outdated
Comment thread Doc/library/difflib.rst Outdated
Comment thread Doc/library/difflib.rst Outdated
webknjaz removed their request for review August 10, 2026 21:15
faithlesstomas and others added 8 commits August 12, 2026 09:41
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

encukou left a comment

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thank you!

github-project-automation Bot moved this from Todo to In Progress in Sprint Sep 4, 2026
encukou merged commit bc977f4 into python:main Sep 4, 2026
58 checks passed
github-project-automation Bot moved this from In Progress to Done in Sprint Sep 4, 2026
clin1234 pushed a commit to clin1234/cpython that referenced this pull request Sep 12, 2026
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

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL