From e91f7ffd276dec8b9ef413e654d242806db11cce Mon Sep 17 00:00:00 2001 From: bleudev Date: Tue, 28 May 2024 20:59:37 +0300 Subject: [PATCH] fix __repr__ and fix get items (IndexError is raising when key == 0) --- ufpy/udict.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ufpy/udict.py b/ufpy/udict.py index 64777bf..ea9db2b 100644 --- a/ufpy/udict.py +++ b/ufpy/udict.py @@ -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) @@ -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__())