vocabulary.py

clew/vocabulary.py

The schema's enumerated vocabularies — ONE definition per value set.

check

str clew.vocabulary.Vocabulary.check(self, str column)

SQL CHECK clause constraining a column to this vocabulary.

clew/vocabulary.py:129

Show on the map →

Called by none

Calls none

Source · 11 lines
    def check(self, column: str) -> str:
        """Explicit quote-and-join, never `{tuple!r}` — a 1-tuple repr carries a
        trailing comma that SQLite rejects, and repr quotes an apostrophe-bearing
        value with double quotes, which SQLite reads as an identifier.

        @brief Generate this vocabulary's CHECK clause for one column.
        @version 1
        """
        inner = ", ".join("'" + v.replace("'", "''") + "'" for v in self.values)
        return f"CHECK({column} IN ({inner}))"
Activity · 2 steps
lines 137–137inner = ", ".join("'" + v.replace("'", "''") + "'" for v in self.values)lines 138–138return f"CHECK({column} IN ({inner}))"
check(table: str, column: str)

clew/vocabulary.py:1233

Show on the map →

Called by none

Calls none

Source · 11 lines
def check(table: str, column: str) -> str:
    """Raises rather than returning an empty string for an unregistered column:
    a silently-absent CHECK is the exact hole this module exists to close.

    @brief Look up a column's vocabulary and generate its CHECK clause.
    @version 1
    """
    vocab = COLUMNS.get((table, column))
    if vocab is None:
        raise KeyError(f"no vocabulary registered for {table}.{column} — add it to COLUMNS")
    return vocab.check(column)
Activity · 4 steps
lines 1240–1240vocab = COLUMNS.get((table, column))lines 1241–1241◇ if vocab is Nonelines 1242–1242raise KeyError(f"no vocabulary registered for {table}.{column} — add it to COLUMNS")lines 1243–1243return vocab.check(column)

Requirements

REQ-DDB-SCHEMA-012

declaration_origin

str clew.vocabulary.declaration_origin(object source, str section)

Name the manifest a declared value came from, for an error message.

clew/vocabulary.py:85

Source · 13 lines
def declaration_origin(source: object, section: str) -> str:
    """A `DeclarationError` is only actionable if it names the file to edit, and
    the loaders receive either a standalone manifest path or an already-parsed
    `.clew.yaml` section — this collapses both into one label.

    @brief Label a declaration's origin for a fail-closed error message.
    @version 2
    """
    if isinstance(source, (str, Path)):
        return str(source)
    return f".clew.yaml [{section}]"

Activity · 3 steps
lines 93–93◇ if isinstance(source, (str, Path))lines 94–94return str(source)lines 95–95return f".clew.yaml [{section}]"

Requirements

REQ-DDB-SCHEMA-012

validated

str clew.vocabulary.Vocabulary.validated(self, str value, *str owner, str field)

Return a declared token when allowed, else raise DeclarationError.

clew/vocabulary.py:159

Show on the map →

Called by none

Calls none

Source · 18 lines
    def validated(self, value: str, *, owner: str, field: str) -> str:
        """The single choke point every declared-enum path routes through. It
        raises rather than falling back because there is no honest fallback: see
        the module docstring on lock identity collapse.

        @brief Validate one declared token, failing closed.
        @version 1
        """
        if value in self.values:
            return value
        raise DeclarationError(
            f"{owner}: invalid {field} {value!r} — allowed: {', '.join(self.values)}"
        )


# ── The registry ─────────────────────────────────────────────────────────────
# One entry per distinct MEANING, even where two entries carry identical tuples.

Requirements

REQ-DDB-SCHEMA-012