-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support frozenset, tuple as dict keys #3886
base: master
Are you sure you want to change the base?
Changes from 7 commits
51563bc
d0f9f2e
038904a
27986dd
a56f91c
cd09b3a
6c045a5
bb123d1
6b55983
3eb1a8b
1b7a941
0ebef3b
fcaff44
2096750
e828031
f2db7bb
ef92aa5
736f293
faf8a51
05b6147
26a29f4
0fb3a4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,38 @@ def test_recursive_casting(): | |
assert z[0].value == 7 and z[1].value == 42 | ||
|
||
|
||
def test_frozen_key(doc): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that you added tests for each container, what about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added fcaff44 that tests you can pass |
||
"""Test that we special-case C++ key types to Python immutable containers, e.g.: | ||
std::map<std::set<K>, V> <-> dict[frozenset[K], V] | ||
std::set<std::set<T>> <-> set[frozenset[T]] | ||
std::set<std::vector<T>> <-> set[tuple[T, ...]] | ||
""" | ||
s = m.cast_set_map() | ||
assert s == {frozenset({"key1", "key2"}): "value"} | ||
s[frozenset({"key3"})] = "value2" | ||
assert m.load_set_map(s) | ||
assert doc(m.cast_set_map) == "cast_set_map() -> Dict[FrozenSet[str], str]" | ||
assert ( | ||
doc(m.load_set_map) == "load_set_map(arg0: Dict[FrozenSet[str], str]) -> bool" | ||
) | ||
|
||
s = m.cast_set_set() | ||
assert s == {frozenset({"key1", "key2"})} | ||
s.add(frozenset({"key3"})) | ||
assert m.load_set_set(s) | ||
assert doc(m.cast_set_set) == "cast_set_set() -> Set[FrozenSet[str]]" | ||
assert doc(m.load_set_set) == "load_set_set(arg0: Set[FrozenSet[str]]) -> bool" | ||
|
||
s = m.cast_vector_set() | ||
assert s == {(1, 2)} | ||
s.add((3,)) | ||
assert m.load_vector_set(s) | ||
assert doc(m.cast_vector_set) == "cast_vector_set() -> Set[Tuple[int, ...]]" | ||
assert ( | ||
doc(m.load_vector_set) == "load_vector_set(arg0: Set[Tuple[int, ...]]) -> bool" | ||
) | ||
|
||
|
||
def test_move_out_container(): | ||
"""Properties use the `reference_internal` policy by default. If the underlying function | ||
returns an rvalue, the policy is automatically changed to `move` to avoid referencing | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like having add as a public function on frozen-sets. We can still call the C-API directly on the pointer for casters, but other code shouldn't be able to add objects to frozen sets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved non-const methods to protected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They would still need to be public for normal set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ecatmur Why not just move them to set subclass and use the raw C-API to interact with the frozen set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I get it now. Fixed.