Skip to content

[WIP] Add difflib module for text comparison and diffing - #776

Closed
antonsynd with Copilot wants to merge 1 commit into
mainlinefrom
copilot/add-difflib-module
Closed

antonsynd with Copilot wants to merge 1 commit into
mainlinefrom
copilot/add-difflib-module

Conversation

Copilot AI commented May 29, 2026

Copy link
Copy Markdown
Contributor

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.


This section details on the original issue you should resolve

<issue_title>feat(stdlib): add difflib module — text comparison and diffing</issue_title>
<issue_description>## Summary
Add a difflib module for computing text differences, matching Python's difflib module API. Custom implementation using the Ratcliff/Obershelp pattern matching algorithm.

Proposed Sharpy API

import difflib

diff: list[str] = difflib.unified_diff(a_lines, b_lines, fromfile="a.txt", tofile="b.txt")
diff: list[str] = difflib.context_diff(a_lines, b_lines)
diff: list[str] = difflib.ndiff(a_lines, b_lines)

sm = difflib.SequenceMatcher(None, a, b)
ratio: float = sm.ratio()
blocks: list = sm.get_matching_blocks()
opcodes: list = sm.get_opcodes()

matches: list[str] = difflib.get_close_matches("appel", ["ape", "apple", "peach"], n=2, cutoff=0.6)

Key Decisions

  • SequenceMatcher implements Ratcliff/Obershelp algorithm (matching Python)
  • get_close_matches for fuzzy string matching (useful for "did you mean?" suggestions)
  • HtmlDiff for visual HTML diff tables
  • Autojunk heuristic for handling large sequences

Test Plan

  • unified_diff and context_diff output format
  • ndiff output
  • SequenceMatcher ratio/get_matching_blocks/get_opcodes
  • get_close_matches fuzzy matching
  • HtmlDiff table generation
  • Empty sequence edge cases
  • Large input performance
    </issue_description>

Comments on the Issue (you are @copilot in this section)

@antonsynd

Copy link
Copy Markdown
Owner

Superseded by batch 9 implementation on feat/stdlib-batch9 branch (commit 7668dc9). PR was empty/WIP — difflib implemented from scratch with SequenceMatcher, Differ, unified_diff, context_diff, ndiff, get_close_matches, restore.

@antonsynd antonsynd closed this Jun 1, 2026
antonsynd added a commit that referenced this pull request Jun 1, 2026
…cket (#757, #746, #753, #754)

Implement four stdlib modules from the Tier 2 roadmap Batch 9:

- **fractions**: Exact rational arithmetic via BigInteger. Fraction class with
  full operator support, GCD normalization, LimitDenominator, string/double
  parsing. 66 tests.
- **difflib**: Text comparison and diffing. SequenceMatcher (Ratcliff/Obershelp),
  Differ with intra-line guides, unified_diff, context_diff, ndiff,
  get_close_matches, restore. 34 tests.
- **threading**: Thread-based concurrency. Thread, Lock, RLock, Event, Semaphore,
  BoundedSemaphore, Barrier, Timer wrapping .NET primitives. 39 tests.
- **socket**: Low-level networking. SocketWrapper with TCP/UDP support, error type
  hierarchy (SharpySocketError/timeout/gaierror/herror), DNS functions, byte
  order conversion, inet_pton/ntop. 43 tests.

Each module includes: C# implementation, per-module .csproj, spy stub, and tests.
Salvaged and fixed code from Copilot PRs #763, #767, #766 (difflib #776 was empty).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

feat(stdlib): add difflib module — text comparison and diffing

2 participants