You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: inheritance_dict/__init__.py
+10-10Lines changed: 10 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@
20
20
defconcatMap(func, items):
21
21
"""
22
22
Yield items from the iterables produced by applying func to each element of items.
23
-
23
+
24
24
func should be a callable that accepts a single item and returns an iterable; concatMap lazily iterates over items, calls func(item) for each, and yields each element from the resulting iterable in order.
25
25
"""
26
26
foriteminitems:
@@ -37,11 +37,11 @@ class BaseDict(dict):
37
37
def_get_keys(self, key) ->Iterable[object]:
38
38
"""
39
39
Return an iterable of candidate lookup keys for dictionary lookup.
40
-
40
+
41
41
This default implementation yields only the original `key`. Subclasses (e.g., those that perform
42
42
Method Resolution Order or tuple-based fallback lookups) should override this to produce additional
43
43
candidate keys to try in order.
44
-
44
+
45
45
Returns:
46
46
Iterable[object]: An iterable yielding candidate keys; by default a single-item tuple containing `key`.
Return the value mapped to `key` by trying candidate lookup keys produced by `_get_keys`.
53
-
53
+
54
54
This performs lookups in the order produced by `self._get_keys(key)` and returns the first mapped value found. If no candidate is present in the mapping a `KeyError` is raised.
Return an iterable of candidate lookup keys, expanding tuple keys by concatenating
117
117
the candidate sequences for each element.
118
-
118
+
119
119
If `key` is a tuple, yields all items produced by applying the superclass's
120
120
`_get_keys` to each element of the tuple (flattened in element order). If `key`
121
121
is not a tuple, delegates to the superclass's `_get_keys`.
122
-
122
+
123
123
Parameters:
124
124
key: The lookup key or a tuple of lookup keys.
125
-
125
+
126
126
Returns:
127
127
An iterable of candidate keys to try for dictionary lookup.
128
128
"""
@@ -162,12 +162,12 @@ class TypeConvertingInheritanceDict(InheritanceDict):
162
162
def_get_keys(self, key):
163
163
"""
164
164
Yield candidate lookup keys for a lookup key.
165
-
165
+
166
166
Always yields the candidates produced by super()._get_keys(key). If key is not a type, also yields the candidates produced by super()._get_keys(type(key)) so lookups will fall back to the key's type (and its MRO) after the original candidates.
167
-
167
+
168
168
Parameters:
169
169
key: The lookup key. Non-type keys cause an additional sequence of candidate keys derived from type(key).
170
-
170
+
171
171
Yields:
172
172
Candidate keys (types or other lookup keys) in the order they should be tried.
0 commit comments