compare_dicts#
- compare_dicts(dict1, dict2, exclude_keys=None, include_only_keys=None)#
Recursively compare two dictionaries with optional key filters.
- Comparison order:
Effective key sets (after include/exclude),
Values under those keys (recursing into nested dicts),
Sets are compared via sorted order, other values via native ordering.
- Parameters:
dict1 (dict[str, Any]) – First dictionary to compare.
dict2 (dict[str, Any]) – Second dictionary to compare.
exclude_keys (Iterable[str] | None) – Keys to ignore at the top level.
include_only_keys (Iterable[str] | None) – If provided, only these top-level keys are considered.
- Returns:
1 if
dict1 > dict2
, -1 ifdict1 < dict2
, 0 if equal.- Raises:
TypeError – If corresponding values have mismatched types and cannot be compared.
- Return type:
int