Enforce strict Pyright gate
This commit is contained in:
parent
90898cfd63
commit
2841042b9c
16 changed files with 214 additions and 77 deletions
|
|
@ -10,7 +10,7 @@ from collections import Counter
|
|||
from collections.abc import Mapping
|
||||
from dataclasses import replace
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from typing import Any, cast
|
||||
|
||||
from .config_validation import (
|
||||
AUTHORITIES,
|
||||
|
|
@ -82,7 +82,7 @@ def _load_descriptor(root: Path) -> ProjectDescriptor:
|
|||
raise DocForgeError("missing_config", "Missing .docforge/project.toml")
|
||||
try:
|
||||
descriptor_bytes = descriptor_path.read_bytes()
|
||||
document = tomllib.loads(descriptor_bytes.decode("utf-8"))
|
||||
document = cast(dict[str, object], tomllib.loads(descriptor_bytes.decode("utf-8")))
|
||||
except UnicodeDecodeError as error:
|
||||
raise DocForgeError("invalid_config", "Project descriptor is not UTF-8") from error
|
||||
except tomllib.TOMLDecodeError as error:
|
||||
|
|
@ -119,6 +119,10 @@ def _load_descriptor(root: Path) -> ProjectDescriptor:
|
|||
raise DocForgeError(
|
||||
"invalid_config", "sources, derived, changesets, and graph tables are required"
|
||||
)
|
||||
sources = cast(dict[str, object], sources)
|
||||
derived = cast(dict[str, object], derived)
|
||||
changesets = cast(dict[str, object], changesets)
|
||||
graph = cast(dict[str, object], graph)
|
||||
for table, allowed, name in (
|
||||
(sources, _SOURCE_KEYS, "sources"),
|
||||
(derived, _DERIVED_KEYS, "derived"),
|
||||
|
|
@ -192,9 +196,10 @@ def _load_descriptor(root: Path) -> ProjectDescriptor:
|
|||
raise DocForgeError("invalid_config", "changesets.writers must be an array of tables")
|
||||
proposal_writers: list[ProposalWriter] = []
|
||||
writer_ids: set[str] = set()
|
||||
for writer in writer_documents:
|
||||
if not isinstance(writer, dict):
|
||||
for writer_value in cast(list[object], writer_documents):
|
||||
if not isinstance(writer_value, dict):
|
||||
raise DocForgeError("invalid_config", "Each changeset writer must be a table")
|
||||
writer = cast(dict[str, object], writer_value)
|
||||
unknown_writer = sorted(set(writer) - _WRITER_KEYS)
|
||||
if unknown_writer:
|
||||
raise DocForgeError(
|
||||
|
|
@ -241,6 +246,7 @@ def _load_descriptor(root: Path) -> ProjectDescriptor:
|
|||
limit_values = document.get("limits", {})
|
||||
if not isinstance(limit_values, dict):
|
||||
raise DocForgeError("invalid_config", "limits must be a table")
|
||||
limit_values = cast(dict[str, object], limit_values)
|
||||
defaults = Limits()
|
||||
unknown_limits = sorted(set(limit_values) - set(defaults.__dataclass_fields__))
|
||||
if unknown_limits:
|
||||
|
|
@ -269,9 +275,10 @@ def _load_descriptor(root: Path) -> ProjectDescriptor:
|
|||
raise DocForgeError("invalid_config", "profiles must be an array of tables")
|
||||
profiles: list[ContextProfile] = []
|
||||
profile_ids: set[str] = set()
|
||||
for profile in profile_documents:
|
||||
if not isinstance(profile, dict):
|
||||
for profile_value in cast(list[object], profile_documents):
|
||||
if not isinstance(profile_value, dict):
|
||||
raise DocForgeError("invalid_config", "Each profile must be a table")
|
||||
profile = cast(dict[str, object], profile_value)
|
||||
unknown_profile = sorted(set(profile) - _PROFILE_KEYS)
|
||||
if unknown_profile:
|
||||
raise DocForgeError(
|
||||
|
|
@ -416,7 +423,7 @@ def _load_source_file(
|
|||
relative = path.relative_to(descriptor.root).as_posix()
|
||||
if path.suffix == ".md":
|
||||
record, content = _markdown_record(path, text)
|
||||
node, edges = validated_node_from_record(
|
||||
node, node_edges = validated_node_from_record(
|
||||
record,
|
||||
content=content,
|
||||
source=path,
|
||||
|
|
@ -424,10 +431,10 @@ def _load_source_file(
|
|||
relations=descriptor.allowed_relations,
|
||||
hash_bytes=raw,
|
||||
)
|
||||
return (node,), edges
|
||||
return (node,), node_edges
|
||||
if path.suffix == ".toml":
|
||||
try:
|
||||
document = tomllib.loads(text)
|
||||
document = cast(dict[str, object], tomllib.loads(text))
|
||||
except tomllib.TOMLDecodeError as error:
|
||||
raise DocForgeError("invalid_source", f"{path.name}: invalid TOML: {error}") from error
|
||||
records = document.get("nodes")
|
||||
|
|
@ -435,9 +442,10 @@ def _load_source_file(
|
|||
raise DocForgeError("invalid_source", f"{path.name}: TOML sources require [[nodes]]")
|
||||
nodes: list[Node] = []
|
||||
edges: list[Edge] = []
|
||||
for index, record in enumerate(records):
|
||||
if not isinstance(record, dict):
|
||||
for index, record_value in enumerate(cast(list[object], records)):
|
||||
if not isinstance(record_value, dict):
|
||||
raise DocForgeError("invalid_source", f"{path.name}: nodes must be tables")
|
||||
record = cast(dict[str, Any], record_value)
|
||||
content = record.get("content")
|
||||
if not isinstance(content, str):
|
||||
raise DocForgeError(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue