11import collections
22
33from data_diff .diff_tables import DiffResultWrapper
4- from typing import TypedDict , Any , Optional
4+ from typing import TypedDict , Any , Optional , List , Dict , Tuple
55
66
77
88class ColumnsDiff (TypedDict ):
9- removed : list [str ]
10- added : list [str ]
11- changed : list [str ]
9+ removed : List [str ]
10+ added : List [str ]
11+ changed : List [str ]
1212
1313
1414def jsonify (diff : DiffResultWrapper ,
1515 with_summary : bool = False ,
16- with_columns : ColumnsDiff | None = None ) -> 'JsonDiff' :
16+ with_columns : Optional [ ColumnsDiff ] = None ) -> 'JsonDiff' :
1717 """
1818 Converts the diff result into a JSON-serializable format.
1919 Optionally add stats summary and schema diff.
@@ -78,14 +78,14 @@ def jsonify(diff: DiffResultWrapper,
7878 }
7979
8080class JsonDiff (TypedDict ):
81- table1 : list [str ]
82- table2 : list [str ]
81+ table1 : List [str ]
82+ table2 : List [str ]
8383 rows : TypedDict ('Rows' , {
8484 'exclusive' : TypedDict ('Exclusive' , {
85- 'table1' : list ['JsonExclusiveRow' ],
86- 'table2' : list ['JsonExclusiveRow' ],
85+ 'table1' : List ['JsonExclusiveRow' ],
86+ 'table2' : List ['JsonExclusiveRow' ],
8787 }),
88- 'diff' : list ['JsonDiffRow' ],
88+ 'diff' : List ['JsonDiffRow' ],
8989 })
9090 summary : Optional ['JsonDiffSummary' ]
9191 columns : Optional ['JsonColumnsSummary' ]
@@ -109,8 +109,8 @@ class JsonDiffRowValue(TypedDict):
109109 isPK : bool
110110
111111
112- JsonDiffRow = dict [str , JsonDiffRowValue ]
113- JsonExclusiveRow = dict [str , JsonExclusiveRowValue ]
112+ JsonDiffRow = Dict [str , JsonDiffRowValue ]
113+ JsonExclusiveRow = Dict [str , JsonExclusiveRowValue ]
114114
115115
116116class JsonDiffSummary (TypedDict ):
@@ -127,20 +127,20 @@ class JsonDiffSummary(TypedDict):
127127 'unchanged' : int ,
128128 })
129129 stats : TypedDict ('Stats' , {
130- 'diffCounts' : dict [str , int ],
130+ 'diffCounts' : Dict [str , int ],
131131 })
132132
133133class JsonColumnsSummary (TypedDict ):
134134 exclusive : TypedDict ('Exclusive' , {
135- 'table1' : list [str ],
136- 'table2' : list [str ],
135+ 'table1' : List [str ],
136+ 'table2' : List [str ],
137137 })
138- typeChanged : list [str ]
138+ typeChanged : List [str ]
139139
140140
141141
142142def _group_rows (diff_info : DiffResultWrapper ,
143- schema : list [str ]) -> tuple [ list [ dict [str , Any ]], list [ dict [str , Any ]], list [ dict [str , Any ]]]:
143+ schema : List [str ]) -> Tuple [ List [ Dict [str , Any ]], List [ Dict [str , Any ]], List [ Dict [str , Any ]]]:
144144 t1_exclusive_rows = []
145145 t2_exclusive_rows = []
146146 diff_rows = []
@@ -162,7 +162,7 @@ def _group_rows(diff_info: DiffResultWrapper,
162162 return t1_exclusive_rows , t2_exclusive_rows , diff_rows
163163
164164
165- def _jsonify_diff (row : dict [str , Any ], key_columns : list [str ]) -> JsonDiffRowValue :
165+ def _jsonify_diff (row : Dict [str , Any ], key_columns : List [str ]) -> JsonDiffRowValue :
166166 columns = collections .defaultdict (dict )
167167 for field , value in row .items ():
168168 if field in ('is_exclusive_a' , 'is_exclusive_b' ):
@@ -185,7 +185,7 @@ def _jsonify_diff(row: dict[str, Any], key_columns: list[str]) -> JsonDiffRowVal
185185 return columns
186186
187187
188- def _jsonify_exclusive (row : dict [str , Any ], key_columns : list [str ]) -> JsonExclusiveRow :
188+ def _jsonify_exclusive (row : Dict [str , Any ], key_columns : List [str ]) -> JsonExclusiveRow :
189189 columns = collections .defaultdict (dict )
190190 for field , value in row .items ():
191191 if field in ('is_exclusive_a' , 'is_exclusive_b' ):
@@ -223,9 +223,9 @@ def _jsonify_diff_summary(stats_dict: dict) -> JsonDiffSummary:
223223 }
224224
225225
226- def _jsonify_columns_diff (added_columns : list [str ],
227- removed_columns : list [str ],
228- changed_columns : list [str ]) -> JsonColumnsSummary :
226+ def _jsonify_columns_diff (added_columns : List [str ],
227+ removed_columns : List [str ],
228+ changed_columns : List [str ]) -> JsonColumnsSummary :
229229 columns = {
230230 'exclusive' : {
231231 'table2' : list (added_columns ),
0 commit comments