ratchet(types): type connector surface on model mixins + fix tag None-safety#1287
Merged
Conversation
…one-safety The YetiTagModel/YetiContextModel/YetiAclModel mixins call self.save() / self.neighbors() / self.extended_id, which are provided at runtime by ArangoYetiConnector (mixed into every persisted subclass) but are invisible to the type checker within the mixins themselves. Declare them as TYPE_CHECKING-only stubs on YetiBaseModel so ty can resolve them. Runtime is unchanged. Also fixes a real latent crash ty surfaced: Tag.find() returns Tag | None, but the tag-removal and clear_tags paths dereferenced it (.count/.save) without a None check. Skip when the tag row is absent. model.py goes from 13 ty diagnostics to 0.
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.
First ty ratchet PR (follows #1286).
What
The
YetiTagModel/YetiContextModel/YetiAclModelmixins callself.save(),self.neighbors(),self.extended_id— provided at runtime byArangoYetiConnector(mixed into every persisted subclass), but invisible to the type checker within the mixins themselves. This is the single biggest source of ty'sunresolved-attributewarnings.YetiBaseModelcan't actually inheritAbstractYetiConnector— that would make non-persisted models likeYetiTagInstanceabstract/uninstantiable. So the fix isTYPE_CHECKING-only stubs onYetiBaseModel. Runtime is completely unchanged — frontend-safe, no wire/OpenAPI impact.Bug fixed
ty surfaced a real latent crash:
Tag.find()returnsTag | None, but the tag-removal (clear=True) andclear_tags()paths dereferenced it (.count/.save) with no None check — a crash if the tag row is ever missing. Now skips when absent.Effect
core/schemas/model.py: 13 ty diagnostics → 0.core/: 296 → 268;unresolved-attribute: 138 → 119.Not flipping any rule to
erroryet —unresolved-attributestill has ~119 instances (union-attribute access + other Optional cases) that later ratchet PRs will chip away at.