2
2
import copy
3
3
import operator
4
4
import re
5
- from typing import List , Sequence , Union
5
+ from typing import List , Sequence
6
6
7
7
from nbdime .diff_format import DiffEntry , SequenceDiffBuilder
8
+ from nbdime .diffing .config import DiffConfig
8
9
from nbdime .diffing .generic import default_differs , default_predicates , diff
9
10
from nbdime .diffing .notebooks import diff_attachments , diff_single_outputs
10
11
from nbdime .prettyprint import PrettyPrintConfig , pretty_print_diff
@@ -19,23 +20,24 @@ def diff_sequence_simple(
19
20
initial : Sequence ,
20
21
final : Sequence ,
21
22
path : str = "" ,
22
- predicates : Union [None , dict ] = None ,
23
- differs : Union [None , dict ] = None ,
23
+ config : DiffConfig = None ,
24
24
) -> dict :
25
25
"""Compute diff of two lists with configurable behaviour.
26
26
27
27
If the lists are of different lengths,
28
28
we assume that items have been appended or removed from the end of the initial list.
29
29
30
30
"""
31
+ if config is None :
32
+ config = DiffConfig ()
31
33
32
- if predicates is None :
33
- predicates = default_predicates ()
34
- if differs is None :
35
- differs = default_differs ()
34
+ if config . predicates is None :
35
+ config . predicates = default_predicates ()
36
+ if config . differs is None :
37
+ config . differs = default_differs ()
36
38
37
39
subpath = "/" .join ((path , "*" ))
38
- diffit = differs [subpath ]
40
+ diffit = config . differs [subpath ]
39
41
40
42
di = SequenceDiffBuilder ()
41
43
@@ -48,7 +50,7 @@ def diff_sequence_simple(
48
50
di .addrange (i , [bval ])
49
51
continue
50
52
51
- cd = diffit (aval , bval , path = subpath , predicates = predicates , differs = differs )
53
+ cd = diffit (aval , bval , path = subpath , config = config )
52
54
if cd :
53
55
di .patch (i , cd )
54
56
@@ -75,10 +77,7 @@ def diff_notebooks(
75
77
we shouldn't need to worry about insertions.
76
78
77
79
"""
78
- return diff (
79
- initial ,
80
- final ,
81
- path = initial_path ,
80
+ config = DiffConfig (
82
81
predicates = defaultdict2 (lambda : [operator .__eq__ ], {}),
83
82
differs = defaultdict2 (
84
83
lambda : diff ,
@@ -91,6 +90,12 @@ def diff_notebooks(
91
90
},
92
91
),
93
92
)
93
+ return diff (
94
+ initial ,
95
+ final ,
96
+ path = initial_path ,
97
+ config = config ,
98
+ )
94
99
95
100
96
101
R_IS_INT = re .compile (r"^[-+]?\d+$" )
0 commit comments