Skip to content

Commit

Permalink
update docstr
Browse files Browse the repository at this point in the history
  • Loading branch information
benpankow committed May 24, 2024
1 parent 32b8223 commit ff6489c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,27 @@ def __getitem__(self, key: str) -> Any:
return getattr(self, self._strip_namespace_from_key(key))

@classmethod
def extract(cls: Type[T_NamespacedKVSet], metadata: Mapping[str, Any]) -> T_NamespacedKVSet:
"""Extracts entries from the provided metadata dictionary into an instance of this class.
def extract(cls: Type[T_NamespacedKVSet], values: Mapping[str, Any]) -> T_NamespacedKVSet:
"""Extracts entries from the provided dictionary into an instance of this class.
Ignores any entries in the metadata dictionary whose keys don't correspond to fields on this
Ignores any entries in the dictionary whose keys don't correspond to fields on this
class.
In general, the following should always pass:
.. code-block:: python
class MyMetadataSet(NamedspacedMetadataSet):
class MyKVSet(NamespacedKVSet):
...
metadata: MyMetadataSet = ...
assert MyMetadataSet.extract(dict(metadata)) == metadata
metadata: MyKVSet = ...
assert MyKVSet.extract(dict(metadata)) == metadata
Args:
metadata (Mapping[str, Any]): A dictionary of metadata entries.
values (Mapping[str, Any]): A dictionary of entries to extract.
"""
kwargs = {}
for namespaced_key, value in metadata.items():
for namespaced_key, value in values.items():
splits = namespaced_key.split("/")
if len(splits) == 2:
namespace, key = splits
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any
from typing import Any, cast

from typing_extensions import TypeVar, get_args

Expand Down Expand Up @@ -40,6 +40,6 @@ def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

@classmethod
def _extract_value(cls, field_name: str, value: Any) -> Any:
def _extract_value(cls, field_name: str, value: Any) -> str:
"""Since all tag values are strings, we don't need to do any type coercion."""
return value
return cast(str, value)

0 comments on commit ff6489c

Please sign in to comment.