Skip to content

Commit

Permalink
fix: Behavior of MultiDict.get(index=999)
Browse files Browse the repository at this point in the history
  • Loading branch information
defnull committed Nov 27, 2024
1 parent d44e7a2 commit 382e8ae
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def keys(self):
return self.dict.keys()

def __getitem__(self, key):
return self.get(key, KeyError, -1)
return self.dict[key][-1]

def __setitem__(self, key, value):
self.append(key, value)
Expand All @@ -124,11 +124,10 @@ def getall(self, key):
return self.dict.get(key) or []

def get(self, key, default=None, index=-1):
# Not documented because it's likely to change.
if key not in self.dict and default != KeyError:
return [default][index]

return self.dict[key][index]
try:
return self.dict[key][index]
except (KeyError, IndexError):
return default

def iterallitems(self):
""" Yield (key, value) pairs with repeating keys for each value. """
Expand Down

0 comments on commit 382e8ae

Please sign in to comment.