Improfe the RBS signatures of @lib/jsonrpc/parser.rb / @sig/jsonrpc/parser.rbs
- User
Improfe the RBS signatures of @lib/jsonrpc/parser.rb / @sig/jsonrpc/parser.rbs
Assistant
I'll look at the related types so I can write accurate signatures rather than
untyped.Assistant
Now I have the type vocabulary. Let me check the existing modification to parser.rbs:
Assistant
Let me check whether the project type-checks these signatures (Steep/typeprof) so my changes don't break a check:
Assistant
Steep is used for checking. Let me find the Steepfile and run a baseline check:
Assistant
There are many pre-existing warnings. Let me isolate just the parser-related diagnostics for a clean baseline:
Assistant
The input to these methods is genuinely dynamic JSON (
MultiJson.load→ untyped), and the bodies do runtimeis_a?/key?checks — so typing the params asuntypedis correct; the real wins are in return types and the wrongparse_batchparam type (currentlyArray[Request | Notification], but it actually receives raw parsed JSON). Let me write the improved signatures:Assistant
No new problems introduced (still 198, and the parser line-items are unchanged pre-existing warnings). Here's the final diff:
Assistant
Done. Improved
sig/jsonrpc/parser.rbs, verified withbundle exec steep check(still 198 pre-existing problems, zero new ones).What changed and why
Method Before After - User
Yes
Assistant
I'll tackle all three. Let me gather the details needed for each fix.
Assistant
Confirmed:
BatchRequestactually acceptsRequest | Notification | Error(its own validation and docs say so), but the RBS narrows it toRequest | Notification. That narrow type is why theitems = []array can't be annotated cleanly. So the proper fix chain is: declareMultiJson, widenBatchRequestto includeError, annotateitems, and guard the.fetch. Let me do all four.Assistant
Now the edits. First, widen
BatchRequestto includeError:Assistant
Now add the
MultiJsondeclaration to the external library signatures section:Assistant
Now annotate
itemsand make the.fetchtype-safe inparser.rb:- User
[Request interrupted by user for tool use]
- User
Do not modify the source code! Just the signature code.
Assistant
Understood — signatures only. I'll revert that source edit plan. The
items = []annotation and the.fetchguard both require touchinglib/, so those two stay as-is (they can't be fixed from the sig files without weakening real types).I'll keep the two legitimate signature-only changes: the
MultiJsondeclaration and theBatchRequestwidening (which is a genuine correctness fix — its own validation acceptsError). Let me verify the net effect:Assistant
The
MultiJsondeclaration helped broadly — total dropped from 198 → 186 (it cleared theMultiJsonUnknownConstant warnings across all 11 files, including the 3 in the parser).Now, the parser sig has been updated (param
string_or_symbol_hash, andparse_singlenow returns… | Error). That introduced one new signature-level inconsistency atparser.rb:38: sinceparsereturnsparse_single's result, its declared return must also includeError. That one is fixable from the sig:Assistant
The user is actively editing — params are now all
string_or_symbol_hash. Adding| Errortoparse's return to keep it consistent withparse_single:Assistant
Line 38 cleared. New mismatch at line 99:
parse_batchiteratesjson_array(elementsjson_value) but passes each toparse_single_for_batch, whose param is nowstring_or_symbol_hash. To keepparse_single_for_batch's param as-is,parse_batch's element type needs to match. Let me check the current file state first (it's being edited live):Assistant
Down to 185 (from 198). Here's where things landed.
Summary
Fixed (signatures only):
# Item Fix Result 1 MultiJsonUnknownConstant (11 files, incl. 3 in parser)Added MultiJsonmodule declaration tosig/jsonrpc.rbsexternal-signatures section✅ all cleared — BatchRequesttoo narrowWidened to Request | Notification | Error(matches its ownvalidate_requests+ docs)✅ correctness — parse/ consistency with the updated / params