MCPcopy Create free account
hub / github.com/anomalyco/opencode-sdk-python / extract_files

Function extract_files

src/opencode_ai/_utils/_utils.py:38–54  ·  view source on GitHub ↗

Recursively extract files from the given dictionary based on specified paths. A path may look like this ['foo', 'files', ' ', 'data']. Note: this mutates the given dictionary.

(
    # TODO: this needs to take Dict but variance issues.....
    # create protocol type ?
    query: Mapping[str, object],
    *,
    paths: Sequence[Sequence[str]],
)

Source from the content-addressed store, hash-verified

36
37
38def extract_files(
39 # TODO: this needs to take Dict but variance issues.....
40 # create protocol type ?
41 query: Mapping[str, object],
42 *,
43 paths: Sequence[Sequence[str]],
44) -> list[tuple[str, FileTypes]]:
45 """Recursively extract files from the given dictionary based on specified paths.
46
47 A path may look like this ['foo', 'files', '<array>', 'data'].
48
49 Note: this mutates the given dictionary.
50 """
51 files: list[tuple[str, FileTypes]] = []
52 for path in paths:
53 files.extend(_extract_items(query, path, index=0, flattened_key=None))
54 return files
55
56
57def _extract_items(

Callers 3

test_multiple_filesFunction · 0.90

Calls 1

_extract_itemsFunction · 0.85

Tested by 3

test_multiple_filesFunction · 0.72