@@ -43,6 +43,15 @@ def __call__(self, source: str, lexer: Literal["diff", "python"] = "python") ->
43
43
"""Apply highlighting to the given source."""
44
44
45
45
46
+ CompareSetFunction = dict [
47
+ str ,
48
+ Callable [
49
+ [AbstractSet [Any ], AbstractSet [Any ], _HighlightFunc , int ],
50
+ list [str ],
51
+ ],
52
+ ]
53
+
54
+
46
55
def dummy_highlighter (source : str , lexer : Literal ["diff" , "python" ] = "python" ) -> str :
47
56
"""Dummy highlighter that returns the text unprocessed.
48
57
@@ -204,30 +213,28 @@ def assertrepr_compare(
204
213
205
214
summary = f"{ left_repr } { op } { right_repr } "
206
215
highlighter = config .get_terminal_writer ()._highlight
207
-
208
- explanation = None
216
+ explanation : list [str ] | None
209
217
try :
210
- if op == "==" :
211
- explanation = _compare_eq_any ( left , right , highlighter , verbose )
212
- elif op == "not in" :
213
- if istext ( left ) and istext ( right ):
218
+ match ( left , op , right ) :
219
+ case (_, "==" , _):
220
+ explanation = _compare_eq_any ( left , right , highlighter , verbose )
221
+ case ( str (), "not in" , str () ):
214
222
explanation = _notin_text (left , right , verbose )
215
- elif op == "!=" :
216
- if isset (left ) and isset (right ):
217
- explanation = ["Both sets are equal" ]
218
- elif op == ">=" :
219
- if isset (left ) and isset (right ):
220
- explanation = _compare_gte_set (left , right , highlighter , verbose )
221
- elif op == "<=" :
222
- if isset (left ) and isset (right ):
223
- explanation = _compare_lte_set (left , right , highlighter , verbose )
224
- elif op == ">" :
225
- if isset (left ) and isset (right ):
226
- explanation = _compare_gt_set (left , right , highlighter , verbose )
227
- elif op == "<" :
228
- if isset (left ) and isset (right ):
229
- explanation = _compare_lt_set (left , right , highlighter , verbose )
230
-
223
+ case (
224
+ set () | frozenset (),
225
+ "!=" | ">=" | "<=" | ">" | "<" ,
226
+ set () | frozenset (),
227
+ ):
228
+ set_compare_func : CompareSetFunction = {
229
+ "!=" : lambda * a , ** kw : ["Both sets are equal" ],
230
+ ">=" : _compare_gte_set ,
231
+ "<=" : _compare_lte_set ,
232
+ ">" : _compare_gt_set ,
233
+ "<" : _compare_lt_set ,
234
+ }
235
+ explanation = set_compare_func [op ](left , right , highlighter , verbose )
236
+ case _:
237
+ explanation = None
231
238
except outcomes .Exit :
232
239
raise
233
240
except Exception :
0 commit comments