Skip to content

Commit

Permalink
Type annotation and test for HashTrieMap.update.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Feb 13, 2024
1 parent 7ff2d43 commit ce3bf37
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rpds-py"
version = "0.17.1"
version = "0.18.0"
edition = "2021"

[lib]
Expand Down
7 changes: 6 additions & 1 deletion rpds.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ from typing import (
_T = TypeVar("_T")
_KT_co = TypeVar("_KT_co", covariant=True)
_VT_co = TypeVar("_VT_co", covariant=True)
_KU_co = TypeVar("_KU_co", covariant=True)
_VU_co = TypeVar("_VU_co", covariant=True)

class HashTrieMap(Mapping[_KT_co, _VT_co]):
def __init__(
Expand All @@ -31,7 +33,10 @@ class HashTrieMap(Mapping[_KT_co, _VT_co]):
key: _KT_co,
val: _VT_co,
) -> HashTrieMap[_KT_co, _VT_co]: ...
def update(self, *args: Mapping): ...
def update(
self,
*args: Mapping[_KU_co, _VU_co] | Iterable[tuple[_KU_co, _VU_co]],
) -> HashTrieMap[_KT_co | _KU_co, _VT_co | _VU_co]: ...
@classmethod
def convert(
cls,
Expand Down
10 changes: 10 additions & 0 deletions tests/test_hash_trie_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,3 +535,13 @@ def test_fromkeys_explicit_value_not_copied():
got[3].append(1)

assert got == HashTrieMap((i, [1]) for i in keys)


def test_update_with_iterable_of_kvs():
assert HashTrieMap({1: 2}).update(iter([(3, 4), ("5", 6)])) == HashTrieMap(
{
1: 2,
3: 4,
"5": 6,
},
)

0 comments on commit ce3bf37

Please sign in to comment.