Skip to content

Commit 8e6e47a

Browse files
committed
Update implementation of TimedCache object
There were some odd decisions made about the implementation of some of the required methods for MuttableMapping in the TimedCache object. This cleans those up and makes the implementation, ever so slightly, easier to read. See also #3885
1 parent 41a33f2 commit 8e6e47a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

requests/structures.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ def __repr__(self):
148148
(self.maxlen, len(self._dict), self.expiration_secs)
149149

150150
def __iter__(self):
151-
return map(lambda kv: (kv[0], kv[1][1]), self._dict.items()).__iter__()
151+
return ((key, value[1]) for key, value in self._dict.items())
152152

153153
def __delitem__(self, item):
154-
return self._dict.__delitem__(item)
154+
del self._dict[item]
155155

156156
def __getitem__(self, key):
157157
"""
@@ -166,7 +166,7 @@ def __getitem__(self, key):
166166

167167
if now - occurred > self.expiration_secs:
168168
del self._dict[key]
169-
raise KeyError
169+
raise KeyError(key)
170170
else:
171171
return value
172172

@@ -183,7 +183,7 @@ def __setitem__(self, key, value):
183183
while len(self._dict) >= self.maxlen:
184184
self._dict.popitem(last=False)
185185

186-
return self._dict.__setitem__(key, (now, value))
186+
self._dict[key] = (now, value)
187187

188188
def __len__(self):
189189
""":return: the length of the cache"""

0 commit comments

Comments
 (0)