Skip to content

Commit

Permalink
fix __repr__ and fix get items (IndexError is raising when key == 0)
Browse files Browse the repository at this point in the history
  • Loading branch information
bleudev committed May 28, 2024
1 parent 085effe commit e91f7ff
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ufpy/udict.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def sorted(self) -> 'UDict[KT, VT, DV]':
# get/set/del items
def __get_keys_from_slice_or_int(self, key: KT | int | slice) -> list[KT]:
if isinstance(key, int) and key not in self.__dict:
if key == 0:
raise IndexError("You can't use 0 as index in UDict")
return [list(self.__dict.keys())[key - 1]]
if isinstance(key, slice):
start, stop, step = key.indices(len(self) + 1)
Expand Down Expand Up @@ -180,7 +182,7 @@ def __str__(self) -> str:
return str(self.__dict)

def __repr__(self) -> str:
return f'''u{self.__dict}'''
return f'u{self.__dict}'

def __hash__(self) -> int:
return hash(self.__repr__())
Expand Down

0 comments on commit e91f7ff

Please sign in to comment.