jsonschema_diff.core.tools.compare

Attributes

COMPARE_RULES_TYPE

Mapping search patternCompare subclass.

Classes

CompareRules

Pick an appropriate comparator class according to rule precedence.

Module Contents

type COMPARE_RULES_TYPE = dict[type | tuple[type, type] | str | tuple[str, type, type] | tuple[str, type], type['Compare']][source]

Mapping search patternCompare subclass.

class CompareRules[source]

Pick an appropriate comparator class according to rule precedence.

static get_comparator_from_values(
rules: COMPARE_RULES_TYPE,
default: type[Compare],
key: str,
old: Any,
new: Any,
) type[Compare][source]

Wrapper that resolves comparator from values.

static get_comparator(
rules: COMPARE_RULES_TYPE,
default: type[Compare],
key: str,
old: type,
new: type,
) type[Compare][source]

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 (type) – Types being compared.

  • new (type) – Types being compared.