Return a function that will pull individual configurations out of a merged dict. For example, the merged dict might look like this: { a: ... b: ... } The returned function will generate this: [{ name: a, ... }, { name: b, ... }] In other words, this functi
(data_class_union)
| 26 | |
| 27 | |
| 28 | def separate_multiple_defaults(data_class_union): |
| 29 | """Return a function that will pull individual configurations out of a merged dict. |
| 30 | For example, the merged dict might look like this: |
| 31 | |
| 32 | { |
| 33 | a: ... |
| 34 | b: ... |
| 35 | } |
| 36 | |
| 37 | The returned function will generate this: |
| 38 | |
| 39 | [{ name: a, ... }, { name: b, ... }] |
| 40 | |
| 41 | In other words, this function makes the types for default lists with single and |
| 42 | multiple items be typed identically. |
| 43 | """ |
| 44 | |
| 45 | def separate_fn(joined: dict) -> list: |
| 46 | # The dummy allows the union to be converted. |
| 47 | @dataclass |
| 48 | class Dummy: |
| 49 | dummy: data_class_union |
| 50 | |
| 51 | return [ |
| 52 | get_typed_config(Dummy, DictConfig({"dummy": {"name": name, **cfg}})).dummy |
| 53 | for name, cfg in joined.items() |
| 54 | ] |
| 55 | |
| 56 | return separate_fn |
no outgoing calls
no test coverage detected