From: Kaliko Jack Date: Sat, 1 Apr 2023 16:08:12 +0000 (+0200) Subject: Some more type hints X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=refs%2Fheads%2Fmypy;p=python-musicpd.git Some more type hints --- diff --git a/musicpd.py b/musicpd.py index e779355..c083206 100644 --- a/musicpd.py +++ b/musicpd.py @@ -13,7 +13,7 @@ import os from functools import wraps # Type hint for python <= 3.8 from typing import Any, Dict, List, Tuple -from typing import Optional, Union +from typing import Iterator, Optional, Union HELLO_PREFIX = "OK MPD " ERROR_PREFIX = "ACK " @@ -394,7 +394,7 @@ class MPDClient: self._wfile.write(f"{line!s}\n") self._wfile.flush() - def _write_command(self, command, args=None): + def _write_command(self, command, args: Optional[list[str]] = None): if args is None: args = [] parts = [command] @@ -407,7 +407,7 @@ class MPDClient: raise CommandError('new line found in the command!') self._write_line(" ".join(parts)) - def _read_binary(self, amount): + def _read_binary(self, amount: int): chunk = bytearray() while amount > 0: result = self._rbfile.read(amount) @@ -448,7 +448,7 @@ class MPDClient: raise ProtocolError(f"Could not parse pair: '{line}'") return pair - def _read_pairs(self, separator=": ", binary: bool =False): + def _read_pairs(self, separator: str =": ", binary: bool =False): pair = self._read_pair(separator, binary=binary) while pair: yield pair @@ -467,7 +467,7 @@ class MPDClient: for _, value in self._read_pairs(":"): yield value - def _read_objects(self, delimiters: Optional[List[str]] = None): + def _read_objects(self, delimiters: Optional[List[str]] = None) -> Iterator[Dict]: obj: Dict[str,Any] = {} if delimiters is None: delimiters = [] @@ -514,14 +514,14 @@ class MPDClient: def _fetch_playlist(self): return self._read_playlist() - def _fetch_object(self): + def _fetch_object(self) -> Dict: objs = list(self._read_objects()) if not objs: return {} return objs[0] @iterator_wrapper - def _fetch_objects(self, delimiters): + def _fetch_objects(self, delimiters: List[str]): return self._read_objects(delimiters) def _fetch_changes(self):