From e81ace02dba0b3d0d536346f7ef2543e14d7c4e4 Mon Sep 17 00:00:00 2001 From: Kaliko Jack Date: Sat, 1 Apr 2023 18:08:12 +0200 Subject: [PATCH] Some more type hints --- musicpd.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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): -- 2.39.5