ratchet(types): make YetiPackage collection fields non-optional#1289
Merged
Conversation
YetiPackage declared its collection fields as Optional (tags/observables/
entities/indicators/relationships: Optional[...] = [] or {}), but the code
always treats them as collections — __init__ and the model validators iterate,
subscript, and membership-test them directly. Passing None would crash at
runtime; the Optional annotation was both wrong and the root cause of ~33 ty
warnings in this file (not-iterable / not-subscriptable / unsupported-operator
cascading from the possibly-None type).
Drop the Optional. YetiPackage is internal (used only by package.py and its
tests — not an API request/response model, not in the OpenAPI schema), so this
has no wire impact. Omitting a field still uses its empty default; only an
explicit None is now rejected, which would have crashed anyway.
core/schemas/package.py: 38 ty diagnostics -> 5. Overall core warnings 268 -> 220.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Third ty ratchet PR — a frontend-safe root-cause fix that clears a large cascade.
What
YetiPackagedeclared its collection fields asOptional:…but the code always treats them as collections —
__init__and the model validators iterate, subscript, and membership-test them directly. PassingNonewould crash at runtime, so theOptionalwas both wrong and the root cause of ~33 ty warnings in this file (not-iterable/not-subscriptable/unsupported-operator, all cascading from the possibly-Nonetype).Dropped the
Optional(and the now-unused import).Frontend-safe
YetiPackageis internal — referenced only bypackage.pyand its tests, not an API request/response model, not in the OpenAPI schema. (ThePackage-Input/Outputschemas in OpenAPI are the unrelated observablepackagetype.) Omitting a field still uses its empty default; only an explicitNoneis now rejected — which would have crashed anyway.Effect
core/schemas/package.py: 38 → 5 ty diagnostics.core/warnings: 268 → 220.not-subscriptable16→4,not-iterable11→5,unsupported-operator15→7 (no rule fully cleared yet, so no flip this round).tests/schemas/package.py); ruff clean; ty exits 0.