Skip to content

Conformance

🛈 DocStrings

conformance.toml: renames and known differences of a pinned reference.

Source code in src/aclientp/schema_reference.py
@dataclass(frozen=True)
class Conformance:
    """``conformance.toml``: renames and known differences of a pinned reference."""

    renames: dict[str, str] = field(default_factory=dict)
    """Upstream definition name to our model name."""

    known: dict[str, str] = field(default_factory=dict)
    """Finding id to the reason the difference is accepted."""

    check_nullability: bool = False
    """Compare which fields accept ``null``. For model packages that send ``None`` as
    ``null`` and leave out ``MISSING`` fields (v2), not for ``exclude_none`` ones (v1)."""

    check_parse_nullability: bool = False
    """Report fields where upstream allows ``null`` but the model rejects ``None``
    (valid messages fail to parse). Implied by ``check_nullability``; for packages
    that never send ``null`` (v1)."""

    check_constraints: bool = False
    """Compare numeric and length constraints (``minimum``, ``minItems``, ...)."""

    allow_missing: bool = False
    """Accept upstream shapes, enums and methods without a counterpart yet, while a
    model package is being written. Fields of the shapes that exist are still checked."""

    @classmethod
    def load(cls, path: UPath) -> Conformance:
        """Read ``conformance.toml``; a missing file means no renames or differences."""
        if not path.exists():
            return cls()
        data = tomllib.loads(path.read_text("utf-8"))
        return cls(
            dict(data.get("renames", {})),
            dict(data.get("known", {})),
            bool(data.get("check_nullability", False)),
            bool(data.get("check_parse_nullability", False)),
            bool(data.get("check_constraints", False)),
            bool(data.get("allow_missing", False)),
        )

allow_missing class-attribute instance-attribute

allow_missing: bool = False

Accept upstream shapes, enums and methods without a counterpart yet, while a model package is being written. Fields of the shapes that exist are still checked.

check_constraints class-attribute instance-attribute

check_constraints: bool = False

Compare numeric and length constraints (minimum, minItems, ...).

check_nullability class-attribute instance-attribute

check_nullability: bool = False

Compare which fields accept null. For model packages that send None as null and leave out MISSING fields (v2), not for exclude_none ones (v1).

check_parse_nullability class-attribute instance-attribute

check_parse_nullability: bool = False

Report fields where upstream allows null but the model rejects None (valid messages fail to parse). Implied by check_nullability; for packages that never send null (v1).

known class-attribute instance-attribute

known: dict[str, str] = field(default_factory=dict)

Finding id to the reason the difference is accepted.

renames class-attribute instance-attribute

renames: dict[str, str] = field(default_factory=dict)

Upstream definition name to our model name.

load classmethod

load(path: UPath) -> Conformance

Read conformance.toml; a missing file means no renames or differences.

Source code in src/aclientp/schema_reference.py
@classmethod
def load(cls, path: UPath) -> Conformance:
    """Read ``conformance.toml``; a missing file means no renames or differences."""
    if not path.exists():
        return cls()
    data = tomllib.loads(path.read_text("utf-8"))
    return cls(
        dict(data.get("renames", {})),
        dict(data.get("known", {})),
        bool(data.get("check_nullability", False)),
        bool(data.get("check_parse_nullability", False)),
        bool(data.get("check_constraints", False)),
        bool(data.get("allow_missing", False)),
    )

:fa-brands-github: Show source on GitHub