Skip to content

Schema diff

didactic.api.diff

diff(old: type[Model], new: type[Model]) -> JsonObject

Compute a structural diff between two Models.

Parameters:

Name Type Description Default
old type[Model]

The earlier Model.

required
new type[Model]

The later Model.

required

Returns:

Type Description
dict

The diff record from panproto.diff_schemas, exposed as a dict. Keys describe added / removed / changed sorts, ops, and constraints.

Examples:

>>> import didactic.api as dx
>>> class V1(dx.Model):
...     id: str
>>> class V2(dx.Model):
...     id: str
...     email: str = ""
>>> d = dx.diff(V1, V2)
>>> "added" in d
True

didactic.api.classify_change

classify_change(
    old: type[Model], new: type[Model]
) -> JsonObject

Diff and classify a Model change as compatible, breaking, or migrating.

Parameters:

Name Type Description Default
old type[Model]

The earlier Model.

required
new type[Model]

The later Model.

required

Returns:

Type Description
dict

The compatibility report from panproto.diff_and_classify: {"compatible": bool, "breaking_changes": [...], "non_breaking_changes": [...]}.

Examples:

>>> import didactic.api as dx
>>> class V1(dx.Model):
...     id: str
>>> class V2(dx.Model):
...     id: int  # type change is breaking
>>> report = dx.classify_change(V1, V2)
>>> report["compatible"]
False

didactic.api.is_breaking_change

is_breaking_change(
    old: type[Model], new: type[Model]
) -> bool

Return True when the change from old to new is breaking.