diff --git a/github/Installation.py b/github/Installation.py index 46119c0b..a7c3f66a 100644 --- a/github/Installation.py +++ b/github/Installation.py @@ -23,8 +23,9 @@ # along with PyGithub. If not, see . # # # ################################################################################ +from __future__ import annotations -from typing import Any, Dict +from typing import TYPE_CHECKING, Any import github.Authorization import github.Event @@ -37,19 +38,30 @@ import github.PaginatedList import github.Plan import github.Repository import github.UserKey +from github import Consts from github.Auth import AppAuth +from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet +from github.PaginatedList import PaginatedList +from github.Requester import Requester -from . import Consts +if TYPE_CHECKING: + from github.MainClass import Github INTEGRATION_PREVIEW_HEADERS = {"Accept": Consts.mediaTypeIntegrationPreview} -class Installation(github.GithubObject.NonCompletableGithubObject): +class Installation(NonCompletableGithubObject): """ This class represents Installations. The reference can be found here https://docs.github.com/en/rest/reference/apps#installations """ - def __init__(self, requester, headers, attributes, completed): + def __init__( + self, + requester: Requester, + headers: dict[str, str | int], + attributes: Any, + completed: bool, + ) -> None: super().__init__(requester, headers, attributes, completed) auth = self._requester.auth if self._requester is not None else None @@ -59,48 +71,41 @@ class Installation(github.GithubObject.NonCompletableGithubObject): auth = auth.get_installation_auth(self.id, requester=self._requester) self._requester = self._requester.withAuth(auth) + def _initAttributes(self) -> None: + self._id: Attribute[int] = NotSet + self._app_id: Attribute[int] = NotSet + self._target_id: Attribute[int] = NotSet + self._target_type: Attribute[str] = NotSet + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value}) - def get_github_for_installation(self): + def get_github_for_installation(self) -> Github: return github.Github(**self._requester.kwargs) @property - def id(self): - """ - :type: integer - """ + def id(self) -> int: return self._id.value @property - def app_id(self): - """ - :type: integer - """ + def app_id(self) -> int: return self._app_id.value @property - def target_id(self): - """ - :type: integer - """ + def target_id(self) -> int: return self._target_id.value @property - def target_type(self): - """ - :type: string - """ + def target_type(self) -> str: return self._target_type.value - def get_repos(self): + def get_repos(self) -> PaginatedList[github.Repository.Repository]: """ :calls: `GET /installation/repositories `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository` """ - url_parameters = dict() + url_parameters: dict[str, Any] = {} - return github.PaginatedList.PaginatedList( + return PaginatedList( contentClass=github.Repository.Repository, requester=self._requester, firstUrl="/installation/repositories", @@ -109,13 +114,7 @@ class Installation(github.GithubObject.NonCompletableGithubObject): list_item="repositories", ) - def _initAttributes(self) -> None: - self._id = github.GithubObject.NotSet - self._app_id = github.GithubObject.NotSet - self._target_id = github.GithubObject.NotSet - self._target_type = github.GithubObject.NotSet - - def _useAttributes(self, attributes: Dict[str, Any]) -> None: + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) if "app_id" in attributes: # pragma no branch diff --git a/github/Installation.pyi b/github/Installation.pyi deleted file mode 100644 index 46ec8bcd..00000000 --- a/github/Installation.pyi +++ /dev/null @@ -1,14 +0,0 @@ -from typing import Any, Dict - -import github -from github.GithubObject import NonCompletableGithubObject -from github.PaginatedList import PaginatedList -from github.Repository import Repository - -class Installation(NonCompletableGithubObject): - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: Dict[str, Any]) -> None: ... - def get_github_for_installation(self) -> github.Github: ... - @property - def id(self) -> int: ... - def get_repos(self) -> PaginatedList[Repository]: ...