Files
wehub-resource-sync 6b7e6b44f1
Python Build and Type Check / python-ci (ubuntu-latest, 3.11) (push) Has been cancelled
Python Build and Type Check / python-ci (ubuntu-latest, 3.13) (push) Has been cancelled
Python Build and Type Check / python-ci (windows-latest, 3.11) (push) Has been cancelled
Python Build and Type Check / python-ci (windows-latest, 3.13) (push) Has been cancelled
Python Integration Tests / python-ci (ubuntu-latest, 3.13) (push) Has been cancelled
Python Integration Tests / python-ci (windows-latest, 3.13) (push) Has been cancelled
Python Notebook Tests / python-ci (ubuntu-latest, 3.13) (push) Has been cancelled
Python Notebook Tests / python-ci (windows-latest, 3.13) (push) Has been cancelled
Python Smoke Tests / python-ci (ubuntu-latest, 3.13) (push) Has been cancelled
Python Smoke Tests / python-ci (windows-latest, 3.13) (push) Has been cancelled
Python Unit Tests / python-ci (ubuntu-latest, 3.13) (push) Has been cancelled
Python Unit Tests / python-ci (windows-latest, 3.13) (push) Has been cancelled
gh-pages / build (push) Has been cancelled
Python Publish (pypi) / Upload release to PyPI (push) Has been cancelled
Spellcheck / spellcheck (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:37:31 +08:00

37 lines
945 B
Python

# Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Utility for retrieving properties from nested dictionaries."""
from typing import Any
def get_property(data: dict[str, Any], path: str) -> Any:
"""Retrieve a property from a dictionary using dot notation.
Parameters
----------
data : dict[str, Any]
The dictionary to retrieve the property from.
path : str
A dot-separated string representing the path to the property (e.g., "foo.bar.baz").
Returns
-------
Any
The value at the specified path.
Raises
------
KeyError
If the path does not exist in the dictionary.
"""
keys = path.split(".")
current = data
for key in keys:
if not isinstance(current, dict) or key not in current:
msg = f"Property '{path}' not found"
raise KeyError(msg)
current = current[key]
return current