Skip to content

ratchet(types): make YetiPackage collection fields non-optional#1289

Merged
tomchop merged 1 commit into
mainfrom
ratchet/optional-access-crashes
Jul 13, 2026
Merged

ratchet(types): make YetiPackage collection fields non-optional#1289
tomchop merged 1 commit into
mainfrom
ratchet/optional-access-crashes

Conversation

@tomchop

@tomchop tomchop commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Third ty ratchet PR — a frontend-safe root-cause fix that clears a large cascade.

What

YetiPackage declared its collection fields as Optional:

tags: Optional[Dict[str, List[str]]] = {}
observables: Optional[List[observable.ObservableTypes]] = []
entities: Optional[List[entity.EntityTypes]] = []
indicators: Optional[List[indicator.IndicatorTypes]] = []
relationships: Optional[Dict[str, List[YetiPackageRelationship]]] = {}

…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, so the Optional was both wrong and the root cause of ~33 ty warnings in this file (not-iterable / not-subscriptable / unsupported-operator, all cascading from the possibly-None type).

Dropped the Optional (and the now-unused import).

Frontend-safe

YetiPackage is internal — referenced only by package.py and its tests, not an API request/response model, not in the OpenAPI schema. (The Package-Input/Output schemas in OpenAPI are the unrelated observable package type.) Omitting a field still uses its empty default; only an explicit None is now rejected — which would have crashed anyway.

Effect

  • core/schemas/package.py: 38 → 5 ty diagnostics.
  • Overall core/ warnings: 268 → 220.
  • not-subscriptable 16→4, not-iterable 11→5, unsupported-operator 15→7 (no rule fully cleared yet, so no flip this round).
  • All three unittest suites pass (incl. tests/schemas/package.py); ruff clean; ty exits 0.

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.
@tomchop tomchop merged commit eed2520 into main Jul 13, 2026
4 checks passed
@tomchop tomchop deleted the ratchet/optional-access-crashes branch July 13, 2026 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant