three-merge

raw JSON →
0.1.1 verified Fri May 01 auth: no python

A simple library for merging two strings with respect to a base one, performing three-way string merge. Current version: 0.1.1 (stable, minor bug fixes). No regular release cadence; developed by Spyder IDE.

pip install three-merge
error ModuleNotFoundError: No module named 'three_merge'
cause The library name uses a hyphen but the Python module uses an underscore.
fix
Import with underscore: import three_merge
error NameError: name 'MergeConflict' is not defined
cause MergeConflict is not imported; it's in the three_merge module.
fix
Import it explicitly: from three_merge import MergeConflict
error AttributeError: module 'three_merge' has no attribute 'merge'
cause Trying to access merge as a module attribute incorrectly.
fix
Use: from three_merge import merge
gotcha The merge function raises a `MergeConflict` exception if it cannot resolve conflicts. You must handle this exception.
fix Wrap in try-except: from three_merge import MergeConflict; try: result = merge(...); except MergeConflict as e: ...
deprecated No deprecated features known. Version 0.1.0 vs 0.1.1: 0.1.1 fixed corner cases with PRESERVED strings and longer source texts.
fix Always use latest version (0.1.1) to avoid known bugs.

Merges strings a and b with respect to base, handling conflicts.

from three_merge import merge

base = "Hello world"
a = "Hello beautiful world"
b = "Hello cruel world"
result = merge(base, a, b)
print(result)