models.py

clew/query/models.py

R2 query-library return types: frozen, JSON-serializable dataclasses.

of

OriginSplit clew.query.models.OriginSplit.of(cls, Iterable[str|None] origins)

Classify roster members by whose code they are.

clew/query/models.py:633

Show on the map →

Called by none

Calls list

Source · 40 lines
    def of(cls, origins: Iterable[str | None]) -> OriginSplit:
        """ONE PLACE THAT DECIDES THE BUCKETS, because gh#352 is a contract rather than a fix to
        one roster. A second roster computing its own split is how two payloads come to disagree
        about the same index, and that disagreement would read as a data problem rather than as a
        duplicated rule. It lives ON the type instead of in `_common` because `_common` is
        stdlib-only by design and this needs the dataclass at runtime.

        THE ARITHMETIC IS CHECKED, NOT ASSUMED. A caller's whole reason to trust a split is that
        the buckets account for the total; a silently lossy classification would report plausible
        thirds that omit rows, which is worse than no split at all because it reads as a
        measurement. The check costs nothing and cannot be phrased around.

        THE THREE-WAY DISTINCTION MAPS ONTO THE SCHEMA. `''` is a resolved first-party file; a
        non-empty string is the external root that owns it; `None` is a member whose file is not
        resolved at all — doxygen's bare-filename `#include`s — and it stays its own bucket,
        because "unknown" is not "ours".

        @brief Build a split from per-member origins.
        @return The split.
        @version 1
        """
        seen = list(origins)
        external = [o for o in seen if o]
        unresolved = [o for o in seen if o is None]
        split = cls(
            total=len(seen),
            first_party=len(seen) - len(external) - len(unresolved),
            external=len(external),
            unresolved=len(unresolved),
            external_roots=tuple(sorted(set(external))),
        )
        if split.first_party + split.external + split.unresolved != split.total:
            raise AssertionError(
                f"OriginSplit lost rows: {split.first_party}+{split.external}+"
                f"{split.unresolved} != {split.total} — a split that does not account for the "
                f"whole roster is worse than none, because it reads as a measurement"
            )
        return split

Activity · 7 steps
lines 654–654seen = list(origins)lines 655–655external = [o for o in seen if o]lines 656–656unresolved = [o for o in seen if o is None]lines 657–663split = cls( total=len(seen), first_party=len(seen) - len(external) - len(unresolved), external=len(external), unresolved=len(unresolved), external_roots=tuple(sorted(set(external))), )lines 664–664◇ if split.first_party + split.external + split.unresolved != split.totallines 665–669raise AssertionError( f"OriginSplit lost rows: {split.first_party}+{split.external}+" f"{split.unresolved} != {split.total} — a split that does not account for the " f"whole roster is worse than none, because it reads as a measurement" )lines 670–670return split

Requirements

REQ-DDB-QUERY-011

section

object | None clew.query.models.SubjectDossier.section(self)

The one populated section, whatever kind it is.

clew/query/models.py:2469

Show on the map →

Called by none

Calls none

Source · 29 lines
    def section(self) -> object | None:
        """A CONSUMER SHOULD NOT HAVE TO MAP KIND TO FIELD NAME, because two of the nine
        do not match (`class` -> `compound`, `macro` -> `function`) and a consumer that
        guessed would read `None` off a populated dossier. The mapping lives here, once,
        beside the fields it maps.

        THE HAND-WRITTEN TUPLE THAT USED TO BE HERE SHIPPED A DEFECT (gh#29's neighbour).
        This docstring already claimed "a section added to this dataclass is found without a
        second edit somewhere else" while listing seven sections by hand, and `enumeration`
        — the eighth, added by gh#6 — was left out. `_flatten_subject` reads this property to
        build the MCP payload, so `dossier` answered `found: false` for EVERY enum in every
        index: a bare definitive negative on symbols carrying a brief, a body span and their
        enumerators, on the one surface gh#6 was filed against.

        So it now reads the dataclass's own fields, minus the envelope keys. A claim about a
        mechanism is not the mechanism, and the fix is the smaller of the two: the promise was
        already the right promise.

        @brief Return whichever section this dossier populated.
        @return The populated section, or None.
        @version 2
        """
        for name in (f.name for f in fields(self) if f.name not in _ENVELOPE_FIELDS):
            value = getattr(self, name)
            if value is not None:
                return value
        return None

Activity · 5 steps
lines 2491–2491◇ for name in (f.name for f in fields(self) if f.name not in _ENVELOPE_FIELDS)lines 2492–2492value = getattr(self, name)lines 2493–2493◇ if value is not Nonelines 2494–2494return valuelines 2495–2495return None

Requirements

REQ-DDB-QUERY-001