[docs]classCompareRules:"""Pick an appropriate comparator class according to rule precedence."""# ------------------------------------------------------------------ ## Public helpers# ------------------------------------------------------------------ #@staticmethod
[docs]defget_comparator_from_values(rules:COMPARE_RULES_TYPE,default:type["Compare"],key:str,old:Any,new:Any,)->type["Compare"]:"""Wrapper that resolves comparator from **values**."""returnCompareRules.get_comparator(rules,default,key,type(old),type(new))
@staticmethod
[docs]defget_comparator(rules:COMPARE_RULES_TYPE,default:type["Compare"],key:str,old:type,new:type,)->type["Compare"]:""" Resolve a comparator class according to the following lookup order: 1. ``(key, old_type, new_type)`` 2. ``key`` 3. ``(old_type, new_type)`` 4. ``old_type`` or ``new_type`` (if one of them is ``NoneType``) 5. *default* Parameters ---------- rules : dict Precedence map. default : Compare subclass Fallback comparator. key : str Field name. old, new : type Types being compared. """forsearchin[((key,old,new)),(key),((old,new)),]:tuple_types=rules.get(cast(Any,search),None)iftuple_typesisnotNone:returntuple_typeselse:ifoldisNoneType:returnrules.get(new,default)elifoldisnotNoneTypeoroldisnew:returnrules.get(old,default)else:returndefault