Fix mypy type errors unmasked in the test suite - #105
Merged
Conversation
Now that the duplicate-module error from #82 is fixed, mypy reaches the test suite and reports 61 pre-existing type errors (51 originally, plus new ones added since the issue was filed). This makes `mypy vesper tests` exit 0 while keeping production code clean. Production changes (structural typing, mirroring the existing Resolver Protocol): - Add RpcClient and RpcSession Protocols in vesper/rpc.py and type the CiderRpcClient session param and all production rpc parameters against them (service, catalog, playback_controller, search_controller, session). - Accept str | SessionSearchSource in _build_session_query_pool, matching the existing runtime isinstance(source, str) handling. Test changes: - Resolver stubs now inherit from FallbackResolver (implements all 5 Protocol methods) so they satisfy the Resolver Protocol structurally. - RPC stubs gain the missing Protocol methods and default parameter values so they satisfy RpcClient. - Mechanical narrowing fixes for dict|None indexing, .text on content unions, utcoffset() None, and a generator fixture return annotation. - cast() at 7 sites that access stub-only attributes on typed service internals (is_playing, current_track, plan_calls). - Add types-jsonschema to dev deps for the jsonschema import-untyped error. Verified: mypy vesper tests exits 0; 270 tests pass.
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.
Summary
Closes #97.
Now that the duplicate-module error from #82 is fixed (#96 added
tests/__init__.py),mypy vesper testsno longer aborts early — which unmasked 61 pre-existing type errors in the test suite (51 at issue-file time, plus new ones added since). This PR makesmypy vesper testsexit 0 while keeping production code clean.Approach
The dominant pattern was test doubles not satisfying real type signatures. Mirroring the existing
ResolverProtocol, this introduces structural Protocols so test doubles satisfy the real types rather than being papered over with ignores:RpcClient/RpcSessionProtocols (vesper/rpc.py): type theCiderRpcClientsession param and all productionrpcparameters against them (service,catalog,playback_controller,search_controller,session).FallbackResolver(implements all 5 Protocol methods) so they satisfy theResolverProtocol structurally.set_failure_callback,playback_get,search_library,run_amapi_v3) and default parameter values.dict | Noneindexing,.texton content unions,utcoffset()None, and a generator fixture return annotation.cast()at 7 sites that access stub-only attributes on typed service internals (is_playing,current_track,plan_calls).types-jsonschemaadded to dev deps for thejsonschemaimport-untypederror._build_session_query_poolnow acceptsstr | SessionSearchSource, matching the existing runtimeisinstance(source, str)handling.Test commands run