Repository navigation
fix: enum coercion at call sites in 3 mypy-excluded parsers/validators - #210
Conversation
Three more single-error excluded files. Each was assigning a bare `str` where a Literal/Enum was required. Gate grows from 398 → 401 files. - polylogue/sources/parsers/claude_common.py: ParsedContentBlock.type is declared `ContentBlockType` (not str). Pydantic's `coerce_type` validator accepts str at runtime, but the type system sees the annotated field type. Pass `ContentBlockType.TEXT` directly instead of the raw string "text". - polylogue/sources/parsers/claude_code_parser.py: same fix as above; add ContentBlockType to the existing `polylogue.types` import. - polylogue/schemas/validator.py: `extract_payload_samples` expects `sample_granularity: Literal["document", "record"]`. The old code fell through `isinstance(granularity, str)` without constraining the string. Widen the fallback: accept the literal strings when present in the schema, otherwise derive from provider membership in `_RECORD_VALIDATION_PROVIDERS`. A schema with an unexpected string value now falls through to the provider-based default instead of being silently propagated downstream. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
💤 Files with no reviewable changes (1)
📝 WalkthroughWalkthroughThese changes enhance type safety by normalizing granularity configuration to explicit enum types in the validator, replacing string literals with typed enum values in Claude parsers, and enabling stricter mypy analysis on previously excluded modules. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
#210) ## Summary Three excluded files each passing a bare \`str\` where the declared type is a Literal/Enum. Gate grows from 398 → 401 under \`mypy --strict\`. ## Problem - **\`polylogue/sources/parsers/claude_common.py:98\`** and **\`polylogue/sources/parsers/claude_code_parser.py:71\`** — \`ParsedContentBlock(type="text", ...)\`. The field is declared \`type: ContentBlockType\`. Pydantic has a \`coerce_type\` validator that accepts str at runtime, but mypy sees the annotated field type. - **\`polylogue/schemas/validator.py:81\`** — \`extract_payload_samples\` takes \`sample_granularity: Literal["document", "record"]\`. The caller only checked \`isinstance(granularity, str)\`; a schema with an arbitrary string value would have propagated downstream. ## Solution - **Parsers**: pass \`ContentBlockType.TEXT\` directly instead of \`"text"\`. Add \`ContentBlockType\` to the existing \`polylogue.types\` import in \`claude_code_parser.py\`; \`claude_common.py\` didn't import from \`polylogue.types\` previously — add that import too. - **validator**: constrain to the two known Literal values. Accept \`raw_granularity == "record"\` or \`"document"\`; anything else (including non-str) falls through to the provider-based default. Small behaviour tightening: a schema carrying a typo like \`"records"\` now takes the provider-based default instead of passing through to \`extract_payload_samples\` where it would have been accepted as a str and broken downstream. ## Verification - \`nix develop -c mypy --config-file pyproject.toml polylogue/sources/parsers/claude_code_parser.py polylogue/sources/parsers/claude_common.py polylogue/schemas/validator.py\` — \`Success: no issues found in 3 source files\` - \`nix develop -c devtools verify --quick\` — format, lint, mypy, render-all --check all passed - Pre-push hook (\`devtools verify --quick\`) passed Full \`devtools verify\` (with pytest) deferred to CI. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
#210) Three excluded files each passing a bare `str` where the declared type is a Literal / Enum. `sources/parsers/claude_common.py` and `sources/parsers/claude_code_parser.py`: `ParsedContentBlock(type="text", ...)` where the field is declared `type: ContentBlockType`. Pydantic's `coerce_type` validator accepts str at runtime, but mypy sees the annotated field type. Pass `ContentBlockType.TEXT` directly; add the `polylogue.types` import where missing. `schemas/validator.py`: `extract_payload_samples` declares `sample_granularity: Literal["document", "record"]`, but the caller only checked `isinstance(granularity, str)` — a schema with an arbitrary string value would have propagated downstream. Constrain to the two Literal values; anything else falls through to the provider-based default. Behavior tightening: a schema with a typo like `"records"` now takes the provider default instead of passing through as str and breaking downstream. Gate grows from 398 → 401 files. Verification: mypy clean on the three touched files; devtools verify --quick green.
#210) Three excluded files each passing a bare `str` where the declared type is a Literal / Enum. `sources/parsers/claude_common.py` and `sources/parsers/claude_code_parser.py`: `ParsedContentBlock(type="text", ...)` where the field is declared `type: ContentBlockType`. Pydantic's `coerce_type` validator accepts str at runtime, but mypy sees the annotated field type. Pass `ContentBlockType.TEXT` directly; add the `polylogue.types` import where missing. `schemas/validator.py`: `extract_payload_samples` declares `sample_granularity: Literal["document", "record"]`, but the caller only checked `isinstance(granularity, str)` — a schema with an arbitrary string value would have propagated downstream. Constrain to the two Literal values; anything else falls through to the provider-based default. Behavior tightening: a schema with a typo like `"records"` now takes the provider default instead of passing through as str and breaking downstream. Gate grows from 398 → 401 files. Verification: mypy clean on the three touched files; devtools verify --quick green.
#210) Three excluded files each passing a bare `str` where the declared type is a Literal / Enum. `sources/parsers/claude_common.py` and `sources/parsers/claude_code_parser.py`: `ParsedContentBlock(type="text", ...)` where the field is declared `type: ContentBlockType`. Pydantic's `coerce_type` validator accepts str at runtime, but mypy sees the annotated field type. Pass `ContentBlockType.TEXT` directly; add the `polylogue.types` import where missing. `schemas/validator.py`: `extract_payload_samples` declares `sample_granularity: Literal["document", "record"]`, but the caller only checked `isinstance(granularity, str)` — a schema with an arbitrary string value would have propagated downstream. Constrain to the two Literal values; anything else falls through to the provider-based default. Behavior tightening: a schema with a typo like `"records"` now takes the provider default instead of passing through as str and breaking downstream. Gate grows from 398 → 401 files. Verification: mypy clean on the three touched files; devtools verify --quick green.
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
Three excluded files each passing a bare `str` where the declared type is a Literal/Enum. Gate grows from 398 → 401 under `mypy --strict`.
Problem
Solution
Verification
Full `devtools verify` (with pytest) deferred to CI.
🤖 Generated with Claude Code