From 39fb254e019c920516bb317d4b48a8de7cac850e Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 28 Jan 2023 15:57:20 +0000 Subject: Fix the type annotations --- libmat2/torrent.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'libmat2/torrent.py') diff --git a/libmat2/torrent.py b/libmat2/torrent.py index c547a20..e6407ff 100644 --- a/libmat2/torrent.py +++ b/libmat2/torrent.py @@ -1,5 +1,5 @@ import logging -from typing import Union +from typing import Union, Dict, List, Tuple from . import abstract @@ -15,7 +15,7 @@ class TorrentParser(abstract.AbstractParser): if self.dict_repr is None: raise ValueError - def get_meta(self) -> dict[str, Union[str, dict]]: + def get_meta(self) -> Dict[str, Union[str, Dict]]: metadata = {} for key, value in self.dict_repr.items(): if key not in self.allowlist: @@ -56,7 +56,7 @@ class _BencodeHandler: } @staticmethod - def __decode_int(s: bytes) -> tuple[int, bytes]: + def __decode_int(s: bytes) -> Tuple[int, bytes]: s = s[1:] next_idx = s.index(b'e') if s.startswith(b'-0'): @@ -66,7 +66,7 @@ class _BencodeHandler: return int(s[:next_idx]), s[next_idx+1:] @staticmethod - def __decode_string(s: bytes) -> tuple[bytes, bytes]: + def __decode_string(s: bytes) -> Tuple[bytes, bytes]: colon = s.index(b':') # FIXME Python3 is broken here, the call to `ord` shouldn't be needed, # but apparently it is. This is utterly idiotic. @@ -76,7 +76,7 @@ class _BencodeHandler: s = s[1:] return s[colon:colon+str_len], s[colon+str_len:] - def __decode_list(self, s: bytes) -> tuple[list, bytes]: + def __decode_list(self, s: bytes) -> Tuple[List, bytes]: ret = list() s = s[1:] # skip leading `l` while s[0] != ord('e'): @@ -84,7 +84,7 @@ class _BencodeHandler: ret.append(value) return ret, s[1:] - def __decode_dict(self, s: bytes) -> tuple[dict, bytes]: + def __decode_dict(self, s: bytes) -> Tuple[Dict, bytes]: ret = dict() s = s[1:] # skip leading `d` while s[0] != ord(b'e'): @@ -113,10 +113,10 @@ class _BencodeHandler: ret += self.__encode_func[type(value)](value) return b'd' + ret + b'e' - def bencode(self, s: Union[dict, list, bytes, int]) -> bytes: + def bencode(self, s: Union[Dict, List, bytes, int]) -> bytes: return self.__encode_func[type(s)](s) - def bdecode(self, s: bytes) -> Union[dict, None]: + def bdecode(self, s: bytes) -> Union[Dict, None]: try: ret, trail = self.__decode_func[s[0]](s) except (IndexError, KeyError, ValueError) as e: -- cgit v1.3