Skip to content

gh-133722: Add Difflib theme to _colorize and 'color' option to difflib.unified_diff#133725

Merged
hugovk merged 25 commits intopython:mainfrom
dougthor42:difflib-color-gh133722
Aug 8, 2025
Merged

gh-133722: Add Difflib theme to _colorize and 'color' option to difflib.unified_diff#133725
hugovk merged 25 commits intopython:mainfrom
dougthor42:difflib-color-gh133722

Conversation

@dougthor42
Copy link
Contributor

@dougthor42 dougthor42 commented May 9, 2025

Add a color arg (defaulting to False) to difflib.unified_diff. When True, ANSI color codes are injected to the diff lines so that the printed result looks like git diff --color:

>>> import difflib
>>> args = [['one', 'three'], ['two', 'three'], 'Original', 'Current']
>>> for line in difflib.unified_diff(*args, lineterm='', color=True):
...     print(line)
...     
--- Original
+++ Current
@@ -1,2 +1,2 @@
-one
+two
 three

image

Fixes #133722.

It's a bummer, I just missed the feature freeze window for 3.14 (it was yesterday! 😭), but c'est la vie!


📚 Documentation preview 📚: https://cpython-previews--133725.org.readthedocs.build/

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a color: bool arg to difflib.unified_diff

6 participants