fix(search): keep mypy clean under sentence-transformers 6.0.0 - #95
Open
hey-august wants to merge 1 commit into
Open
fix(search): keep mypy clean under sentence-transformers 6.0.0#95hey-august wants to merge 1 commit into
hey-august wants to merge 1 commit into
Conversation
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.
What this changes
The problem
sentence-transformers6.0.0 was integrated on 2026-08-18 and broke the [TYPECHECK] check on every open PR in this repository.The pin is unbounded (sentence-transformers>=2.2.0), so CI picked up the new major version.
mypyandtorchare unchanged. Nothing in the tree moved,signalwire/search/last changed on Aug 13 and these same branches passed Test on Aug 17.All four errors are in
signalwire/search/:model.model_name = model_name, wheremypynow resolves the model to atorchnn.Modulesubclass whose__setattr__accepts only Tensor and Module.if not SentenceTransformer, which reads as atruthy-functionerror because theTYPE_CHECKINGimport binds the real class and is neverNone.The solution, in this PR
The fix annotates those two locals as
model: Any, matching thedict[str, Any]declarations sitting beside them, and makes the availability guards explicit isNonechecks. It adapts to 6.x rather than capping the dependency, since a cap would transitively hold back transformers.Two tidier-looking alternatives fail.
setattr(model, "model_name", ...)trips ruff B010 and fails the LINT gate. Moving availability onto a separate boolean breakstest_load_model_no_library, because the tests simulate the missing dependency by patching the module-level name toNone, so the guard has to keep reading that name. Themodel_nameattribute itself also has to stay: it looks like a dead write, butquery_processor.py:243reads it back throughgetattrforset_global_model.Verified mypy-clean against both sentence-transformers 6.0.0 and 5.6.0, ruff check and format clean, and the full unit suite green (5772 passed, 100 skipped).
Checklist
bash scripts/run-ci.shpasses locallymypycoverstests/)run-ci.sh: 31 gates pass locally, including TYPECHECK (the gate this PR fixes), TEST, LINT, FMT and SIGNATURES.But five fail for reasons unrelated to this change:
porting-sdkand the SDK, at paths that do not match my filesystem organization.Leaving the box un-checked.
No new tests. This is a typing-only change with no behavioral surface of its own, and the guards it rewrites are already covered:
test_load_model_no_libraryexercises theSentenceTransformer is Nonepath by patching the module-level name toNone. That test is also what constrained the fix, since it rules out moving the availability check onto a separate flag.Does this change public API?
infrastructure change:
Changing something that goes on the wire?
No. The change is confined to
signalwire/signalwire/search/, which loads local embedding models. Nothing here is emitted, no enum values or parameter names move, and no generated types are touched.