Skip to content

Commit f824640

Browse files
committed
🚧
1 parent aceeebd commit f824640

File tree

4 files changed

+67
-2
lines changed

4 files changed

+67
-2
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: 🪄 Code Embedder Test 2 (example)
2+
3+
on: push
4+
5+
permissions:
6+
contents: write
7+
8+
jobs:
9+
code_embedder:
10+
name: "Code embedder"
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
# with:
16+
# ref: ${{ github.event.pull_request.head.ref }}
17+
18+
- name: Run code embedder
19+
uses: kvankova/[email protected]
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/code-embedder.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
uv sync --all-extras --dev
4343
uv pip install .
4444
# uv pip install typer # For code embedder
45-
pin install typer
45+
pip install typer
4646
4747
- name: 🏞️ Activate virtual environment
4848
run: |

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,4 @@ cython_debug/
171171

172172
# Dev
173173
old/
174-
dev/readme_snippets/formatted/
174+
# dev/readme_snippets/formatted/
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from nested_dict_tools import (
2+
filter_leaves,
3+
flatten_dict,
4+
get_deep,
5+
map_leaves,
6+
set_deep,
7+
unflatten_dict,
8+
)
9+
10+
nested = {"a": {"b": {"c": 42}}}
11+
12+
# Get a deeply nested value
13+
value = get_deep(nested, ["a", "b"])
14+
print(value) # Output: {'c': 42}
15+
16+
# Set a deeply nested value
17+
set_deep(nested, ["a", "z"], "new_value")
18+
print(nested) # Output: {'a': {'b': {'c': 42}, 'z': 'new_value'}}
19+
20+
# Flatten the nested dictionary
21+
flat = flatten_dict(nested, sep=".")
22+
print(flat) # Output: {'a.b.c': 42, 'a.z': 'new_value'}
23+
24+
# Unflatten the flattened dictionary
25+
unflattened = unflatten_dict(flat, sep=".")
26+
print(unflattened == nested) # Output: True
27+
28+
# Filter leaves
29+
nested = filter_leaves(lambda k, v: isinstance(v, int), nested)
30+
print(nested) # Output: {'a': {'b': {'c': 42}}}
31+
32+
# Map on leaves
33+
mapped = map_leaves(lambda x: x + 1, nested)
34+
print(mapped) # Output: {'a': {'b': {'c': 43}}}
35+
36+
# Map on leaves with several dictionaries
37+
mapped = map_leaves(lambda x, y: x + y + 1, nested, nested)
38+
print(mapped) # Output: {'a': {'b': {'c': 85}}}
39+
40+
41+
# Recursive types:
42+
type NestedDict[K, V] = dict[K, NestedDictNode[K, V]]
43+
type NestedDictNode[K, V] = V | NestedDict[K, V]
44+
# Similar types for Mapping and MutableMapping

0 commit comments

Comments
 (0)