fixed type errors when pylance type checking mode is strict.

This commit is contained in:
2023-07-19 21:47:47 +09:00
parent 23025bd679
commit 08d8a0626a
24 changed files with 387 additions and 236 deletions

View File

@ -1,5 +1,7 @@
import platform
import threading
from io import BufferedReader
from typing import TypedDict, Unpack
from requests import Response, Session
@ -9,6 +11,27 @@ from mdrsclient.exceptions import MissingConfigurationException
from mdrsclient.models import Laboratories, Token, User
class _KwArgsMDRSConnectionGet(TypedDict, total=False):
params: dict[str, str | int]
stream: bool
class _KwArgsMDRSConnectionPost(TypedDict, total=False):
params: dict[str, str | int]
data: dict[str, str | int]
files: dict[str, BufferedReader]
class _KwArgsMDRSConnectionPut(TypedDict, total=False):
params: dict[str, str | int]
data: dict[str, str | int]
files: dict[str, BufferedReader]
class _KwArgsMDRSConnectionDelete(TypedDict, total=False):
params: dict[str, str | int]
class MDRSConnection:
url: str
session: Session
@ -23,20 +46,17 @@ class MDRSConnection:
self.__cache = CacheFile(remote)
self.__prepare_headers()
def get(self, url, *args, **kwargs) -> Response:
return self.session.get(self.__build_url(url), *args, **kwargs)
def get(self, url: str, **kwargs: Unpack[_KwArgsMDRSConnectionGet]) -> Response:
return self.session.get(self.__build_url(url), **kwargs)
def post(self, url, *args, **kwargs) -> Response:
return self.session.post(self.__build_url(url), *args, **kwargs)
def post(self, url: str, **kwargs: Unpack[_KwArgsMDRSConnectionPost]) -> Response:
return self.session.post(self.__build_url(url), **kwargs)
def put(self, url, *args, **kwargs) -> Response:
return self.session.put(self.__build_url(url), *args, **kwargs)
def put(self, url: str, **kwargs: Unpack[_KwArgsMDRSConnectionPut]) -> Response:
return self.session.put(self.__build_url(url), **kwargs)
def delete(self, url, *args, **kwargs) -> Response:
return self.session.delete(self.__build_url(url), *args, **kwargs)
def patch(self, url, *args, **kwargs) -> Response:
return self.session.patch(self.__build_url(url), *args, **kwargs)
def delete(self, url: str, **kwargs: Unpack[_KwArgsMDRSConnectionDelete]) -> Response:
return self.session.delete(self.__build_url(url), **kwargs)
def logout(self) -> None:
del self.__cache.user
@ -68,12 +88,10 @@ class MDRSConnection:
def laboratories(self, laboratories: Laboratories) -> None:
self.__cache.laboratories = laboratories
def __build_url(self, *args: str) -> str:
def __build_url(self, path: str) -> str:
if self.url == "":
raise MissingConfigurationException("remote host is not configured")
parts = [self.url]
parts.extend(args)
return "/".join(parts)
return f"{self.url}/{path}"
def __prepare_headers(self) -> None:
self.session.headers.update(