mirror of
https://github.com/status-im/PyGithub.git
synced 2026-09-01 19:31:10 +00:00
Merge GithubException.pyi stubs back to source (#2464)
This commit is contained in:
+33
-10
@@ -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
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user