Commit 4a70b85
support dataclasses for component args
Summary:
This change adds the ability to provide component arguments via a single dataclass (which can still be combined with positional varargs).
One motivation for supporting dataclasses is to facilitate composition of components, eg consider a scenario where `component2` is an extension of `component1` – it takes the same args as component1 + some extra ones, calls `component1` and does some extra work on top with the additional arguments.
## Before
```lang=python
def component1(arg1: str, arg2: int, ...argN: str): ...
# need to repeat all arguments, unclear which ones are specific to component2
def component2(arg1: str, arg2: int, ... argN: str, otherArg: str):
# need to pass all component1-specific args to component1 explicitly
app_def = component1(arg1, arg2, ... argN)
return do_something(app_def, otherArg)
```
## After
```lang=python
dataclass
class Comp1Args:
arg1: str
arg2: int
...
argN: str
# separation of args for the 2 components is explicit via the dataclasses
# no need to spell out all the args thanks to inheritance
dataclass
class Comp2Args(Comp1Args):
other_arg: str
def component1(args: Comp1Args): ...
def component2(args: Comp2Args):
# no need to spell out all the args when calling component1
app_def = component1(args)
return do_something(app_def, other_arg)
```
Differential Revision: D753203161 parent 24dc0d5 commit 4a70b85
2 files changed
+120
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| 14 | + | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| |||
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
27 | | - | |
| 29 | + | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
33 | 97 | | |
34 | 98 | | |
35 | 99 | | |
| |||
69 | 133 | | |
70 | 134 | | |
71 | 135 | | |
72 | | - | |
| 136 | + | |
73 | 137 | | |
74 | 138 | | |
75 | 139 | | |
| |||
147 | 211 | | |
148 | 212 | | |
149 | 213 | | |
150 | | - | |
| 214 | + | |
151 | 215 | | |
152 | | - | |
153 | | - | |
| 216 | + | |
154 | 217 | | |
155 | 218 | | |
156 | 219 | | |
157 | 220 | | |
158 | 221 | | |
159 | 222 | | |
160 | 223 | | |
161 | | - | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
162 | 235 | | |
163 | 236 | | |
164 | 237 | | |
| |||
180 | 253 | | |
181 | 254 | | |
182 | 255 | | |
183 | | - | |
184 | | - | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
185 | 259 | | |
186 | 260 | | |
187 | 261 | | |
| |||
197 | 271 | | |
198 | 272 | | |
199 | 273 | | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
200 | 277 | | |
201 | 278 | | |
202 | 279 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
133 | 161 | | |
134 | 162 | | |
135 | 163 | | |
| |||
292 | 320 | | |
293 | 321 | | |
294 | 322 | | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
295 | 329 | | |
296 | 330 | | |
297 | 331 | | |
| |||
0 commit comments