Commit d057c42
feat(resources): model-first request= overload across body endpoints (#69)
* feat(resources): model-first request= overload across body endpoints
Resource methods with a request body now accept either individual kwargs
(unchanged) or a pre-built request model via `request=Model(...)`. The
two forms produce identical wire bodies; passing both raises TypeError
with a clear message.
Affected methods (16 sync + 16 async):
- orders: create, batch_create, batch_cancel, amend, decrease
- api_keys: create, generate
- communications: create_rfq, create_quote, accept_quote
- multivariate: create_market, lookup_tickers
- order_groups: create, update_limit
- subaccounts: transfer, update_netting
Implementation: new helper `_check_request_exclusive` in resources/_base.py
centralizes the mutual-exclusion check. Each method gets a `request=None`
kwarg-only parameter; previously-required kwargs become `None`-defaulted
so the request= path doesn't require them. The kwarg path retains its
existing required-field guards (now raised as TypeError when missing).
Drift tests: TestRequestParamDrift only runs on GET/DELETE, so the only
exclusion needed is `batch_cancel.request` (DELETE-with-body).
Closes #56.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* feat(resources): typed @overload signatures for request= dispatchers
Address PR #69 review feedback (#56):
- Add @overload pairs to all 32 dispatcher methods across api_keys,
communications, multivariate, order_groups, orders, subaccounts.
mypy strict now enforces the request= XOR kwargs contract and
required-kwarg presence at call sites.
- Add negative tests for missing-required-kwarg TypeErrors
(single, multi, list-required shapes).
- Document why no async batch_cancel exclusion is needed: drift test
indexes EXCLUSIONS by the sync FQN and reuses for async siblings.
- Trim _check_request_exclusive docstring to a single line.
64 @overload decorators total (32 methods x 2 stubs). mypy strict
passes; 1405 tests pass (1402 prior + 3 new).
Refs #56
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 7a540e3 commit d057c42
9 files changed
Lines changed: 1339 additions & 199 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
35 | 47 | | |
36 | 48 | | |
37 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
15 | 20 | | |
16 | 21 | | |
17 | 22 | | |
| |||
27 | 32 | | |
28 | 33 | | |
29 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
30 | 38 | | |
31 | 39 | | |
32 | 40 | | |
33 | 41 | | |
34 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
35 | 51 | | |
36 | 52 | | |
37 | 53 | | |
38 | | - | |
39 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
40 | 67 | | |
41 | 68 | | |
42 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
43 | 73 | | |
44 | 74 | | |
45 | 75 | | |
46 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
47 | 84 | | |
48 | 85 | | |
49 | 86 | | |
50 | | - | |
51 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
52 | 95 | | |
53 | 96 | | |
54 | 97 | | |
| |||
65 | 108 | | |
66 | 109 | | |
67 | 110 | | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
68 | 114 | | |
69 | 115 | | |
70 | 116 | | |
71 | 117 | | |
72 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
73 | 127 | | |
74 | 128 | | |
75 | 129 | | |
76 | | - | |
77 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
78 | 143 | | |
79 | 144 | | |
80 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
81 | 151 | | |
82 | 152 | | |
83 | 153 | | |
84 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
85 | 162 | | |
86 | 163 | | |
87 | 164 | | |
88 | | - | |
89 | | - | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
90 | 173 | | |
91 | 174 | | |
92 | 175 | | |
| |||
0 commit comments