File tree 2 files changed +16
-1
lines changed
2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change 4
4
import collections .abc
5
5
import typing
6
6
from collections import OrderedDict
7
- from typing import Any , Sequence
7
+ from typing import Any , KeysView , Sequence
8
8
9
9
import numpy as np
10
10
@@ -180,6 +180,10 @@ def __getitem__(self, key: str) -> Space[Any]:
180
180
"""Get the space that is associated to `key`."""
181
181
return self .spaces [key ]
182
182
183
+ def keys (self ) -> KeysView :
184
+ """Returns the keys of the Dict."""
185
+ return KeysView (self .spaces )
186
+
183
187
def __setitem__ (self , key : str , value : Space [Any ]):
184
188
"""Set the space that is associated to `key`."""
185
189
assert isinstance (
Original file line number Diff line number Diff line change @@ -145,3 +145,14 @@ def test_iterator():
145
145
assert key in DICT_SPACE .spaces
146
146
147
147
assert {key for key in DICT_SPACE } == DICT_SPACE .spaces .keys ()
148
+
149
+
150
+ def test_keys_contains ():
151
+ """Test that `Dict.keys()` will correctly assess if the key is in the space."""
152
+ space = Dict (a = Box (0 , 1 ), b = Box (1 , 2 ))
153
+
154
+ for key in space .keys ():
155
+ assert key in space .keys ()
156
+ assert "a" in space .keys ()
157
+
158
+ assert "c" not in space .keys ()
You can’t perform that action at this time.
0 commit comments