From dddc0d410ae6bb1a8e76e1e3efc694f46afea237 Mon Sep 17 00:00:00 2001 From: VarMonke Date: Mon, 16 May 2022 13:54:15 +0530 Subject: [PATCH] Small fixes --- github/client.py | 12 +++++++----- github/exceptions.py | 24 ++++++++++++++---------- github/objects.py | 16 +++++++++++++++- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/github/client.py b/github/client.py index feba655..d3b0b29 100644 --- a/github/client.py +++ b/github/client.py @@ -26,7 +26,7 @@ from .cache import ObjectCache from .http import http from .objects import Gist, Issue, Organization, Repository, User, File -__all__: Tuple[str, ...] = ('GHClient',) +__all__: Tuple[str, ...] = ('GHClient', 'Client') T = TypeVar('T') P = ParamSpec('P') @@ -40,9 +40,6 @@ class GHClient: username: Optional[:class:`str`] An optional username to be provided along with a token to make authenticated API calls. If you provide a username, the token must be provided as well. - token: Optional[:class:`str`] - An optional token to be provided along with a username to make authenticated API calls. - If you provide a token, the username must be provided as well. user_cache_size: Optional[:class:`int`] Determines the maximum number of User objects that will be cached in memory. Defaults to 30, must be between 30 and 0 inclusive. @@ -141,7 +138,7 @@ class GHClient: return self.http.session._rates # type: ignore - async def update_auth(self, username: str, token: str) -> None: + async def update_auth(self, *, username: str, token: str) -> None: """Allows you to input auth information after instantiating the client. Parameters @@ -374,3 +371,8 @@ class GHClient: async def latency(self) -> float: """:class:`float`: Returns the latency of the client.""" return await self.http.latency() + + +class Client(GHClient): + pass + diff --git a/github/exceptions.py b/github/exceptions.py index a339559..0b27540 100644 --- a/github/exceptions.py +++ b/github/exceptions.py @@ -7,22 +7,26 @@ from aiohttp import ClientResponse __all__: Tuple[str, ...] = ( 'APIError', - 'HTTPException', + 'AlreadyStarted', 'ClientException', - 'ResourceNotFound', - 'Ratelimited', - 'WillExceedRatelimit', - 'NoAuthProvided', + 'ClientResponse', + 'GistNotFound', + 'HTTPException', 'InvalidAuthCombination', 'InvalidToken', - 'LoginFailure', - 'NotStarted', - 'AlreadyStarted', - 'UserNotFound', - 'RepositoryNotFound', 'IssueNotFound', + 'LoginFailure', + 'MissingPermissions', + 'NoAuthProvided', + 'NotStarted', 'OrganizationNotFound', + 'Ratelimited', 'RepositoryAlreadyExists', + 'RepositoryNotFound', + 'ResourceAlreadyExists', + 'ResourceNotFound', + 'UserNotFound', + 'WillExceedRatelimit', ) diff --git a/github/objects.py b/github/objects.py index f774ec7..857960c 100644 --- a/github/objects.py +++ b/github/objects.py @@ -256,10 +256,12 @@ class Repository(APIObject): @property def open_issues(self) -> int: + """:class:`int`: The number of open issues on the repository.""" return self._response.get('open_issues') @property def forks(self) -> int: + """:class:`int`: The number of forks of the repository.""" return self._response.get('forks') @property @@ -275,7 +277,15 @@ class Repository(APIObject): ) # type: ignore async def add_file(self, filename: str, message: str, content: str, branch: Optional[str] = None) -> None: - """Adds a file to the repository.""" + """Adds a file to the repository. + + Parameters + ---------- + filename: :class:`str` The name of the file. + message: :class:`str` The commit message. + content: :class:`str` The content of the file. + branch: :class:`str` The branch to add the file to, defaults to the default branch. + """ if branch is None: branch = self.default_branch @@ -450,6 +460,10 @@ class Gist(APIObject): """TODO: document this.""" return self._response + async def delete(self): + """Delete the gist.""" + await self._http.delete_gist(self.id) + # === Organization stuff ===#