-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: 🪄 Code Embedder Test 2 (example) | ||
|
||
on: push | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
code_embedder: | ||
name: "Code embedder" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
# with: | ||
# ref: ${{ github.event.pull_request.head.ref }} | ||
|
||
- name: Run code embedder | ||
uses: kvankova/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,4 +171,4 @@ cython_debug/ | |
|
||
# Dev | ||
old/ | ||
dev/readme_snippets/formatted/ | ||
# dev/readme_snippets/formatted/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from nested_dict_tools import ( | ||
filter_leaves, | ||
flatten_dict, | ||
get_deep, | ||
map_leaves, | ||
set_deep, | ||
unflatten_dict, | ||
) | ||
|
||
nested = {"a": {"b": {"c": 42}}} | ||
|
||
# Get a deeply nested value | ||
value = get_deep(nested, ["a", "b"]) | ||
print(value) # Output: {'c': 42} | ||
|
||
# Set a deeply nested value | ||
set_deep(nested, ["a", "z"], "new_value") | ||
print(nested) # Output: {'a': {'b': {'c': 42}, 'z': 'new_value'}} | ||
|
||
# Flatten the nested dictionary | ||
flat = flatten_dict(nested, sep=".") | ||
print(flat) # Output: {'a.b.c': 42, 'a.z': 'new_value'} | ||
|
||
# Unflatten the flattened dictionary | ||
unflattened = unflatten_dict(flat, sep=".") | ||
print(unflattened == nested) # Output: True | ||
|
||
# Filter leaves | ||
nested = filter_leaves(lambda k, v: isinstance(v, int), nested) | ||
Check failure on line 29 in dev/readme_snippets/formatted/features_demo.py GitHub Actions / build (3.12, ubuntu-latest)Ruff (ARG005)
|
||
print(nested) # Output: {'a': {'b': {'c': 42}}} | ||
|
||
# Map on leaves | ||
mapped = map_leaves(lambda x: x + 1, nested) | ||
print(mapped) # Output: {'a': {'b': {'c': 43}}} | ||
|
||
# Map on leaves with several dictionaries | ||
mapped = map_leaves(lambda x, y: x + y + 1, nested, nested) | ||
print(mapped) # Output: {'a': {'b': {'c': 85}}} | ||
|
||
|
||
# Recursive types: | ||
type NestedDict[K, V] = dict[K, NestedDictNode[K, V]] | ||
type NestedDictNode[K, V] = V | NestedDict[K, V] | ||
# Similar types for Mapping and MutableMapping |