Skip to content

Commit

Permalink
Fix HashTrieMap __repr__s, which need to repr() the key as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Nov 29, 2023
1 parent 36738f6 commit 8697707
Show file tree
Hide file tree
Showing 4 changed files with 14 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.13.1"
version = "0.13.2"
edition = "2021"

[lib]
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ impl HashTrieMapPy {
let contents = self.inner.into_iter().map(|(k, v)| {
format!(
"{}: {}",
k.clone().into_py(py),
k.inner
.call_method0(py, "__repr__")
.and_then(|r| r.extract(py))
.unwrap_or("<repr error>".to_owned()),
v.call_method0(py, "__repr__")
.and_then(|r| r.extract(py))
.unwrap_or("<repr error>".to_owned())
Expand Down
8 changes: 8 additions & 0 deletions tests/test_hash_trie_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,14 @@ def test_iteration_with_many_elements():
assert actual_values == set(values + [12345, 54321])


def test_repr():
rep = repr(HashTrieMap({"foo": "12", "": 37}))
assert rep in {
"HashTrieMap({'foo': '12', '': 37})",
"HashTrieMap({'': 37, 'foo': '12'})",
}


def test_str():
s = str(HashTrieMap({1: 2, 3: 4}))
assert s == "HashTrieMap({1: 2, 3: 4})" or s == "HashTrieMap({3: 4, 1: 2})"
Expand Down

0 comments on commit 8697707

Please sign in to comment.