Skip to content

Commit

Permalink
🚧
Browse files Browse the repository at this point in the history
  • Loading branch information
Kajiih committed Dec 6, 2024
1 parent aceeebd commit f824640
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/code-embedder-test2.yaml
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 }}
2 changes: 1 addition & 1 deletion .github/workflows/code-embedder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
uv sync --all-extras --dev
uv pip install .
# uv pip install typer # For code embedder
pin install typer
pip install typer
- name: 🏞️ Activate virtual environment
run: |
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,4 @@ cython_debug/

# Dev
old/
dev/readme_snippets/formatted/
# dev/readme_snippets/formatted/
44 changes: 44 additions & 0 deletions dev/readme_snippets/formatted/features_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from nested_dict_tools import (

Check failure on line 1 in dev/readme_snippets/formatted/features_demo.py

View workflow job for this annotation

GitHub Actions / build (3.12, ubuntu-latest)

Ruff (D100)

dev/readme_snippets/formatted/features_demo.py:1:1: D100 Missing docstring in public module
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

View workflow job for this annotation

GitHub Actions / build (3.12, ubuntu-latest)

Ruff (ARG005)

dev/readme_snippets/formatted/features_demo.py:29:31: ARG005 Unused lambda argument: `k`

Check warning on line 29 in dev/readme_snippets/formatted/features_demo.py

View workflow job for this annotation

GitHub Actions / build (3.12, ubuntu-latest)

Unnecessary isinstance call; "int" is always an instance of "int" (reportUnnecessaryIsInstance)
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

0 comments on commit f824640

Please sign in to comment.