From 03a2f69667063de9583b9634fd7b4ee00c9856ba Mon Sep 17 00:00:00 2001 From: Trim21 Date: Tue, 23 May 2023 22:00:43 +0800 Subject: [PATCH] Merge GithubException.pyi stubs back to source (#2464) --- github/GithubException.py | 43 ++++++++++++++++++++++++++--------- github/GithubException.pyi | 46 -------------------------------------- 2 files changed, 33 insertions(+), 56 deletions(-) delete mode 100644 github/GithubException.pyi diff --git a/github/GithubException.py b/github/GithubException.py index d6148703..46fb0414 100644 --- a/github/GithubException.py +++ b/github/GithubException.py @@ -29,6 +29,7 @@ ################################################################################ import json +from typing import Any, Dict, List, Optional, Tuple, Type, Union class GithubException(Exception): @@ -38,35 +39,40 @@ class GithubException(Exception): Some other types of exceptions might be raised by underlying libraries, for example for network-related issues. """ - def __init__(self, status, data, headers): + def __init__( + self, + status: int, + data: Dict[str, Union[str, List[str], List[Dict[str, str]]]], + headers: Optional[Dict[str, str]], + ): super().__init__() self.__status = status self.__data = data self.__headers = headers - self.args = [status, data, headers] + self.args = (status, data, headers) @property - def status(self): + def status(self) -> int: """ The status returned by the Github API """ return self.__status @property - def data(self): + def data(self) -> Dict[str, Union[str, List[str], List[Dict[str, str]]]]: """ The (decoded) data returned by the Github API """ return self.__data @property - def headers(self): + def headers(self) -> Optional[Dict[str, str]]: """ The headers returned by the Github API """ return self.__headers - def __str__(self): + def __str__(self) -> str: return f"{self.status} {json.dumps(self.data)}" @@ -99,27 +105,44 @@ class BadAttributeException(Exception): Exception raised when Github returns an attribute with the wrong type. """ - def __init__(self, actualValue, expectedType, transformationException): + def __init__( + self, + actualValue: Any, + expectedType: Union[ + Dict[Tuple[Type[str], Type[str]], Type[dict]], + Tuple[Type[str], Type[str]], + List[Type[dict]], + List[Tuple[Type[str], Type[str]]], + ], + transformationException: Optional[Exception], + ): self.__actualValue = actualValue self.__expectedType = expectedType self.__transformationException = transformationException @property - def actual_value(self): + def actual_value(self) -> Any: """ The value returned by Github """ return self.__actualValue @property - def expected_type(self): + def expected_type( + self, + ) -> Union[ + List[Type[dict]], + Tuple[Type[str], Type[str]], + Dict[Tuple[Type[str], Type[str]], Type[dict]], + List[Tuple[Type[str], Type[str]]], + ]: """ The type PyGithub expected """ return self.__expectedType @property - def transformation_exception(self): + def transformation_exception(self) -> Optional[Exception]: """ The exception raised when PyGithub tried to parse the value """ diff --git a/github/GithubException.pyi b/github/GithubException.pyi deleted file mode 100644 index b26f89f5..00000000 --- a/github/GithubException.pyi +++ /dev/null @@ -1,46 +0,0 @@ -from typing import Any, Dict, List, Optional, Tuple, Type, Union - -class GithubException(Exception): - def __init__( - self, status: Union[int, str], data: Any, headers: Optional[Dict[str, str]] - ) -> None: ... - def __str__(self) -> str: ... - @property - def data(self) -> Dict[str, Union[str, List[str], List[Dict[str, str]]]]: ... - @property - def status(self) -> int: ... - @property - def headers(self) -> Union[None, Dict[str, str]]: ... - -class BadAttributeException(GithubException): - def __init__( - self, - actualValue: Any, - expectedType: Union[ - Dict[Tuple[Type[str], Type[str]], Type[dict]], - Tuple[Type[str], Type[str]], - List[Type[dict]], - List[Tuple[Type[str], Type[str]]], - ], - transformationException: Optional[ValueError], - ) -> None: ... - @property - def actual_value(self) -> Any: ... - @property - def expected_type( - self, - ) -> Union[ - List[Type[dict]], - Tuple[Type[str], Type[str]], - Dict[Tuple[Type[str], Type[str]], Type[dict]], - List[Tuple[Type[str], Type[str]]], - ]: ... - @property - def transformation_exception(self) -> Optional[ValueError]: ... - -class BadCredentialsException(GithubException): ... -class UnknownObjectException(GithubException): ... -class BadUserAgentException(GithubException): ... -class RateLimitExceededException(GithubException): ... -class TwoFactorException(GithubException): ... -class IncompletableObject(GithubException): ...