diff --git a/github/AccessToken.py b/github/AccessToken.py index 2f001ece..86201f5e 100644 --- a/github/AccessToken.py +++ b/github/AccessToken.py @@ -22,6 +22,7 @@ from __future__ import annotations from datetime import datetime, timedelta, timezone +from typing import Any from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -33,7 +34,7 @@ class AccessToken(NonCompletableGithubObject): _created: datetime - def _initAttributes(self): + def _initAttributes(self) -> None: self._token: Attribute[str] = NotSet self._type: Attribute[str] = NotSet self._scope: Attribute[str] = NotSet @@ -122,7 +123,7 @@ class AccessToken(NonCompletableGithubObject): return self._created + timedelta(seconds=seconds) return None - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: dict[str, Any]) -> None: self._created = datetime.now(timezone.utc) if "access_token" in attributes: # pragma no branch self._token = self._makeStringAttribute(attributes["access_token"]) diff --git a/github/ApplicationOAuth.py b/github/ApplicationOAuth.py index 64ed7a83..63cfa859 100644 --- a/github/ApplicationOAuth.py +++ b/github/ApplicationOAuth.py @@ -23,12 +23,13 @@ from __future__ import annotations import urllib.parse -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any import github.AccessToken import github.Auth from github.GithubException import BadCredentialsException, GithubException from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet +from github.Requester import Requester if TYPE_CHECKING: from github.AccessToken import AccessToken @@ -45,12 +46,18 @@ class ApplicationOAuth(NonCompletableGithubObject): self._client_id: Attribute[str] = NotSet self._client_secret: Attribute[str] = NotSet - def __init__(self, requester, headers, attributes, completed): + def __init__( + self, + requester: Requester, + headers: dict[str, Any], + attributes: Any, + completed: bool, + ) -> None: # this object requires a request without authentication requester = requester.withAuth(auth=None) super().__init__(requester, headers, attributes, completed) - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"client_id": self._client_id.value}) @property @@ -61,7 +68,7 @@ class ApplicationOAuth(NonCompletableGithubObject): def client_secret(self) -> str: return self._client_secret.value - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "client_id" in attributes: # pragma no branch self._client_id = self._makeStringAttribute(attributes["client_id"]) if "client_secret" in attributes: # pragma no branch @@ -162,7 +169,7 @@ class ApplicationOAuth(NonCompletableGithubObject): ) @staticmethod - def _checkError(headers, data): + def _checkError(headers: dict[str, Any], data: Any) -> tuple[dict[str, Any], Any]: if isinstance(data, dict) and "error" in data: if data["error"] == "bad_verification_code": raise BadCredentialsException(200, data, headers) diff --git a/github/Artifact.py b/github/Artifact.py index db94d6e6..53c3d11b 100644 --- a/github/Artifact.py +++ b/github/Artifact.py @@ -22,7 +22,7 @@ from __future__ import annotations from datetime import datetime -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any import github.WorkflowRun from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -36,7 +36,7 @@ class Artifact(NonCompletableGithubObject): This class represents an Artifact of Github Run """ - def _initAttributes(self): + def _initAttributes(self) -> None: self._archive_download_url: Attribute[str] = NotSet self._created_at: Attribute[datetime] = NotSet self._expired: Attribute[bool] = NotSet @@ -50,7 +50,7 @@ class Artifact(NonCompletableGithubObject): self._url: Attribute[str] = NotSet self._workflow_run: Attribute[WorkflowRun] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"name": self._name.value, "id": self._id.value}) @property @@ -108,7 +108,7 @@ class Artifact(NonCompletableGithubObject): status, headers, data = self._requester.requestBlob("DELETE", self.url) return status == 204 - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "archive_download_url" in attributes: # pragma no branch self._archive_download_url = self._makeStringAttribute(attributes["archive_download_url"]) if "created_at" in attributes: # pragma no branch diff --git a/github/Auth.py b/github/Auth.py index 3d67e4e5..e6c0d559 100644 --- a/github/Auth.py +++ b/github/Auth.py @@ -49,7 +49,6 @@ class Auth(abc.ABC): The type of the auth token as used in the HTTP Authorization header, e.g. Bearer or Basic. :return: token type """ - pass @property @abc.abstractmethod @@ -58,7 +57,6 @@ class Auth(abc.ABC): The auth token as used in the HTTP Authorization header. :return: token """ - pass class Login(Auth): @@ -177,7 +175,7 @@ class AppAuth(JWT): """ return AppInstallationAuth(self, installation_id, token_permissions, requester) - def create_jwt(self, expiration=None) -> str: + def create_jwt(self, expiration: Optional[int] = None) -> str: """ Create a signed JWT https://docs.github.com/en/developers/apps/building-github-apps/authenticating-with-github-apps#authenticating-as-a-github-app @@ -329,10 +327,10 @@ class AppUserAuth(Auth, WithRequester["AppUserAuth"]): token: str, token_type: Optional[str] = None, expires_at: Optional[datetime] = None, - refresh_token=None, - refresh_expires_at=None, + refresh_token: Optional[str] = None, + refresh_expires_at: Optional[datetime] = None, requester: Optional[Requester] = None, - ): + ) -> None: assert isinstance(client_id, str) assert len(client_id) > 0 assert isinstance(client_secret, str) @@ -398,7 +396,7 @@ class AppUserAuth(Auth, WithRequester["AppUserAuth"]): def _is_expired(self) -> bool: return self._expires_at is not None and self._expires_at < datetime.now(timezone.utc) - def _refresh(self): + def _refresh(self) -> None: if self._refresh_token is None: raise RuntimeError("Cannot refresh expired token because no refresh token has been provided") if self._refresh_expires_at is not None and self._refresh_expires_at < datetime.now(timezone.utc): diff --git a/github/AuthenticatedUser.py b/github/AuthenticatedUser.py index 3140c0f4..e8bbcb5c 100644 --- a/github/AuthenticatedUser.py +++ b/github/AuthenticatedUser.py @@ -41,6 +41,7 @@ from collections import namedtuple from datetime import datetime, timezone +from typing import Any, Dict import github.Authorization import github.Event @@ -68,7 +69,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): An AuthenticatedUser object can be created by calling ``get_user()`` on a Github object. """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"login": self._login.value}) @property @@ -1236,7 +1237,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck("GET", f"/user/memberships/orgs/{org}") return github.Membership.Membership(self._requester, headers, data, completed=True) - def _initAttributes(self): + def _initAttributes(self) -> None: self._avatar_url = github.GithubObject.NotSet self._bio = github.GithubObject.NotSet self._blog = github.GithubObject.NotSet @@ -1276,7 +1277,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject): self._url = github.GithubObject.NotSet self._two_factor_authentication = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "avatar_url" in attributes: # pragma no branch self._avatar_url = self._makeStringAttribute(attributes["avatar_url"]) if "bio" in attributes: # pragma no branch diff --git a/github/Authorization.py b/github/Authorization.py index bd6422d7..7738f559 100644 --- a/github/Authorization.py +++ b/github/Authorization.py @@ -30,7 +30,7 @@ from __future__ import annotations from datetime import datetime -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any import github.AuthorizationApplication import github.GithubObject @@ -45,7 +45,7 @@ class Authorization(github.GithubObject.CompletableGithubObject): This class represents Authorizations. The reference can be found here https://docs.github.com/en/enterprise-server@3.0/rest/reference/oauth-authorizations """ - def _initAttributes(self): + def _initAttributes(self) -> None: self._app: Attribute[AuthorizationApplication] = NotSet self._created_at: Attribute[datetime] = NotSet self._id: Attribute[int] = NotSet @@ -153,7 +153,7 @@ class Authorization(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters) self._useAttributes(data) - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "app" in attributes: # pragma no branch self._app = self._makeClassAttribute( github.AuthorizationApplication.AuthorizationApplication, diff --git a/github/AuthorizationApplication.py b/github/AuthorizationApplication.py index d0f8da50..b97260be 100644 --- a/github/AuthorizationApplication.py +++ b/github/AuthorizationApplication.py @@ -28,6 +28,8 @@ # # ################################################################################ +from typing import Any, Dict + from github.GithubObject import Attribute, CompletableGithubObject, NotSet @@ -40,7 +42,7 @@ class AuthorizationApplication(CompletableGithubObject): self._name: Attribute[str] = NotSet self._url: Attribute[str] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"name": self._name.value}) @property @@ -53,7 +55,7 @@ class AuthorizationApplication(CompletableGithubObject): self._completeIfNotSet(self._url) return self._url.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "name" in attributes: # pragma no branch self._name = self._makeStringAttribute(attributes["name"]) if "url" in attributes: # pragma no branch diff --git a/github/Autolink.py b/github/Autolink.py index 8f0f5d37..5ee2dd13 100644 --- a/github/Autolink.py +++ b/github/Autolink.py @@ -20,6 +20,8 @@ # # ################################################################################ +from typing import Any, Dict + from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -29,7 +31,7 @@ class Autolink(NonCompletableGithubObject): self._key_prefix: Attribute[str] = NotSet self._url_template: Attribute[str] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value}) @property @@ -44,7 +46,7 @@ class Autolink(NonCompletableGithubObject): def url_template(self) -> str: return self._url_template.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) if "key_prefix" in attributes: # pragma no branch diff --git a/github/Branch.py b/github/Branch.py index 51d5a147..c687e278 100644 --- a/github/Branch.py +++ b/github/Branch.py @@ -65,7 +65,7 @@ class Branch(NonCompletableGithubObject): This class represents Branches. The reference can be found here https://docs.github.com/en/rest/reference/repos#branches """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"name": self._name.value}) @property @@ -90,7 +90,7 @@ class Branch(NonCompletableGithubObject): self._protection_url: Attribute[str] = github.GithubObject.NotSet self._protected: Attribute[bool] = github.GithubObject.NotSet - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "commit" in attributes: # pragma no branch self._commit = self._makeClassAttribute(github.Commit.Commit, attributes["commit"]) if "name" in attributes: # pragma no branch @@ -134,7 +134,7 @@ class Branch(NonCompletableGithubObject): teams_bypass_pull_request_allowances: Opt[list[str]] = NotSet, apps_bypass_pull_request_allowances: Opt[list[str]] = NotSet, block_creations: Opt[bool] = NotSet, - ): + ) -> None: """ :calls: `PUT /repos/{owner}/{repo}/branches/{branch}/protection `_ @@ -297,7 +297,7 @@ class Branch(NonCompletableGithubObject): self, strict: Opt[bool] = NotSet, contexts: Opt[list[str]] = NotSet, - ): + ) -> None: """ :calls: `PATCH /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks `_ """ @@ -311,7 +311,7 @@ class Branch(NonCompletableGithubObject): input=post_parameters, ) - def remove_required_status_checks(self): + def remove_required_status_checks(self) -> None: """ :calls: `DELETE /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks `_ """ @@ -341,7 +341,7 @@ class Branch(NonCompletableGithubObject): dismiss_stale_reviews: Opt[bool] = NotSet, require_code_owner_reviews: Opt[bool] = NotSet, required_approving_review_count: Opt[int] = NotSet, - ): + ) -> None: """ :calls: `PATCH /repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews `_ """ @@ -373,7 +373,7 @@ class Branch(NonCompletableGithubObject): input=post_parameters, ) - def remove_required_pull_request_reviews(self): + def remove_required_pull_request_reviews(self) -> None: """ :calls: `DELETE /repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews `_ """ diff --git a/github/BranchProtection.py b/github/BranchProtection.py index c871ac02..2a88e3c3 100644 --- a/github/BranchProtection.py +++ b/github/BranchProtection.py @@ -44,7 +44,7 @@ class BranchProtection(github.GithubObject.CompletableGithubObject): This class represents Branch Protection. The reference can be found here https://docs.github.com/en/rest/reference/repos#get-branch-protection """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"url": self._url.value}) def _initAttributes(self) -> None: diff --git a/github/CWE.py b/github/CWE.py index 57a8c6f3..892960c1 100644 --- a/github/CWE.py +++ b/github/CWE.py @@ -20,6 +20,9 @@ # # ################################################################################ + +from typing import Any, Dict + from github.GithubObject import Attribute, CompletableGithubObject, NotSet @@ -29,7 +32,7 @@ class CWE(CompletableGithubObject): The reference can be found here https://docs.github.com/en/rest/security-advisories/repository-advisories """ - def _initAttributes(self): + def _initAttributes(self) -> None: self._cwe_id: Attribute[str] = NotSet self._name: Attribute[str] = NotSet @@ -41,7 +44,7 @@ class CWE(CompletableGithubObject): def name(self) -> str: return self._name.value - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "cwe_id" in attributes: # pragma no branch self._cwe_id = self._makeStringAttribute(attributes["cwe_id"]) if "name" in attributes: # pragma no branch diff --git a/github/CheckRun.py b/github/CheckRun.py index 87c49449..f8bc3ccc 100644 --- a/github/CheckRun.py +++ b/github/CheckRun.py @@ -21,6 +21,7 @@ ################################################################################ from datetime import datetime +from typing import Any, Dict import github.CheckRunAnnotation import github.CheckRunOutput @@ -243,7 +244,7 @@ class CheckRun(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters) self._useAttributes(data) - def _initAttributes(self): + def _initAttributes(self) -> None: self._app = github.GithubObject.NotSet self._check_suite_id = github.GithubObject.NotSet self._completed_at = github.GithubObject.NotSet @@ -261,7 +262,7 @@ class CheckRun(github.GithubObject.CompletableGithubObject): self._status = github.GithubObject.NotSet self._url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "app" in attributes: # pragma no branch self._app = self._makeClassAttribute(github.GithubApp.GithubApp, attributes["app"]) # This only gives us a dictionary with `id` attribute of `check_suite` diff --git a/github/CheckRunAnnotation.py b/github/CheckRunAnnotation.py index 4088201e..9aa4ccd3 100644 --- a/github/CheckRunAnnotation.py +++ b/github/CheckRunAnnotation.py @@ -20,6 +20,8 @@ # # ################################################################################ +from typing import Any, Dict + from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -40,7 +42,7 @@ class CheckRunAnnotation(NonCompletableGithubObject): self._start_line: Attribute[int] = NotSet self._title: Attribute[str] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"title": self._title.value}) @property @@ -79,7 +81,7 @@ class CheckRunAnnotation(NonCompletableGithubObject): def title(self) -> str: return self._title.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "annotation_level" in attributes: # pragma no branch self._annotation_level = self._makeStringAttribute(attributes["annotation_level"]) if "end_column" in attributes: # pragma no branch diff --git a/github/CheckRunOutput.py b/github/CheckRunOutput.py index 0fe88401..5d6537f2 100644 --- a/github/CheckRunOutput.py +++ b/github/CheckRunOutput.py @@ -20,6 +20,8 @@ # # ################################################################################ +from typing import Any, Dict + from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -33,7 +35,7 @@ class CheckRunOutput(NonCompletableGithubObject): self._text: Attribute[str] = NotSet self._title: Attribute[str] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"title": self._title.value}) @property @@ -56,7 +58,7 @@ class CheckRunOutput(NonCompletableGithubObject): def title(self) -> str: return self._title.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "annotations_count" in attributes: # pragma no branch self._annotations_count = self._makeIntAttribute(attributes["annotations_count"]) if "annotations_url" in attributes: # pragma no branch diff --git a/github/CheckSuite.py b/github/CheckSuite.py index a6c89eba..574b6e77 100644 --- a/github/CheckSuite.py +++ b/github/CheckSuite.py @@ -20,6 +20,8 @@ # # ################################################################################ +from typing import Any, Dict + import github @@ -28,7 +30,7 @@ class CheckSuite(github.GithubObject.CompletableGithubObject): This class represents check suites. The reference can be found here https://docs.github.com/en/rest/reference/checks#check-suites """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value, "url": self._url.value}) @property @@ -200,7 +202,7 @@ class CheckSuite(github.GithubObject.CompletableGithubObject): list_item="check_runs", ) - def _initAttributes(self): + def _initAttributes(self) -> None: self._after = github.GithubObject.NotSet self._app = github.GithubObject.NotSet self._before = github.GithubObject.NotSet @@ -218,7 +220,7 @@ class CheckSuite(github.GithubObject.CompletableGithubObject): self._updated_at = github.GithubObject.NotSet self._url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "after" in attributes: # pragma no branch self._after = self._makeStringAttribute(attributes["after"]) if "app" in attributes: # pragma no branch diff --git a/github/Clones.py b/github/Clones.py index d45a48ad..f5e2fcc6 100644 --- a/github/Clones.py +++ b/github/Clones.py @@ -24,6 +24,7 @@ # # ################################################################################ from datetime import datetime +from typing import Any, Dict from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -39,7 +40,7 @@ class Clones(NonCompletableGithubObject): self._count: Attribute[int] = NotSet self._uniques: Attribute[int] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__( { "timestamp": self._timestamp.value, @@ -60,7 +61,7 @@ class Clones(NonCompletableGithubObject): def uniques(self) -> int: return self._uniques.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "timestamp" in attributes: # pragma no branch self._timestamp = self._makeDatetimeAttribute(attributes["timestamp"]) if "count" in attributes: # pragma no branch diff --git a/github/CodeScanAlert.py b/github/CodeScanAlert.py index 214f897c..5abe1403 100644 --- a/github/CodeScanAlert.py +++ b/github/CodeScanAlert.py @@ -20,6 +20,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.CodeScanAlertInstance import github.CodeScanRule import github.CodeScanTool @@ -34,7 +36,7 @@ class CodeScanAlert(github.GithubObject.NonCompletableGithubObject): The reference can be found here https://docs.github.com/en/rest/reference/code-scanning. """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"number": self.number}) @property @@ -133,7 +135,7 @@ class CodeScanAlert(github.GithubObject.NonCompletableGithubObject): None, ) - def _initAttributes(self): + def _initAttributes(self) -> None: self._number = github.GithubObject.NotSet self._rule = github.GithubObject.NotSet self._tool = github.GithubObject.NotSet @@ -150,7 +152,7 @@ class CodeScanAlert(github.GithubObject.NonCompletableGithubObject): self._most_recent_instance = github.GithubObject.NotSet self._state = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "number" in attributes: # pragma no branch self._number = self._makeIntAttribute(attributes["number"]) if "rule" in attributes: # pragma no branch diff --git a/github/CodeScanAlertInstance.py b/github/CodeScanAlertInstance.py index b48d7f53..f3bbda0f 100644 --- a/github/CodeScanAlertInstance.py +++ b/github/CodeScanAlertInstance.py @@ -20,6 +20,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.CodeScanAlertInstanceLocation import github.GithubObject @@ -30,7 +32,7 @@ class CodeScanAlertInstance(github.GithubObject.NonCompletableGithubObject): The reference can be found here https://docs.github.com/en/rest/reference/code-scanning. """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"ref": self.ref, "analysis_key": self.analysis_key}) @property @@ -89,7 +91,7 @@ class CodeScanAlertInstance(github.GithubObject.NonCompletableGithubObject): """ return self._classifications.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._ref = github.GithubObject.NotSet self._analysis_key = github.GithubObject.NotSet self._environment = github.GithubObject.NotSet @@ -99,7 +101,7 @@ class CodeScanAlertInstance(github.GithubObject.NonCompletableGithubObject): self._location = github.GithubObject.NotSet self._classifications = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "ref" in attributes: # pragma no branch self._ref = self._makeStringAttribute(attributes["ref"]) if "analysis_key" in attributes: # pragma no branch diff --git a/github/CodeScanAlertInstanceLocation.py b/github/CodeScanAlertInstanceLocation.py index 92b6555e..ce210bef 100644 --- a/github/CodeScanAlertInstanceLocation.py +++ b/github/CodeScanAlertInstanceLocation.py @@ -20,6 +20,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject @@ -32,7 +34,7 @@ class CodeScanAlertInstanceLocation(github.GithubObject.NonCompletableGithubObje def __str__(self): return f"{self.path} @ l{self.start_line}:c{self.start_column}-l{self.end_line}:c{self.end_column}" - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__( { "path": self.path, @@ -78,14 +80,14 @@ class CodeScanAlertInstanceLocation(github.GithubObject.NonCompletableGithubObje """ return self._end_column.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._path = github.GithubObject.NotSet self._start_line = github.GithubObject.NotSet self._start_column = github.GithubObject.NotSet self._end_line = github.GithubObject.NotSet self._end_column = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "path" in attributes: # pragma no branch self._path = self._makeStringAttribute(attributes["path"]) if "start_line" in attributes: # pragma no branch diff --git a/github/CodeScanRule.py b/github/CodeScanRule.py index 60e2c746..6af74862 100644 --- a/github/CodeScanRule.py +++ b/github/CodeScanRule.py @@ -20,6 +20,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject @@ -29,7 +31,7 @@ class CodeScanRule(github.GithubObject.NonCompletableGithubObject): The reference can be found here https://docs.github.com/en/rest/reference/code-scanning. """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self.id, "name": self.name}) @property @@ -67,14 +69,14 @@ class CodeScanRule(github.GithubObject.NonCompletableGithubObject): """ return self._description.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._id = github.GithubObject.NotSet self._name = github.GithubObject.NotSet self._severity = github.GithubObject.NotSet self._security_severity_level = github.GithubObject.NotSet self._description = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "id" in attributes: # pragma no branch self._id = self._makeStringAttribute(attributes["id"]) if "name" in attributes: # pragma no branch diff --git a/github/CodeScanTool.py b/github/CodeScanTool.py index afde1a02..0f5b2cd2 100644 --- a/github/CodeScanTool.py +++ b/github/CodeScanTool.py @@ -20,6 +20,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject @@ -29,7 +31,7 @@ class CodeScanTool(github.GithubObject.NonCompletableGithubObject): The reference can be found here https://docs.github.com/en/rest/reference/code-scanning. """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__( { "guid": self.guid, @@ -59,12 +61,12 @@ class CodeScanTool(github.GithubObject.NonCompletableGithubObject): """ return self._guid.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._name = github.GithubObject.NotSet self._version = github.GithubObject.NotSet self._guid = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "name" in attributes: # pragma no branch self._name = self._makeStringAttribute(attributes["name"]) if "version" in attributes: # pragma no branch diff --git a/github/Commit.py b/github/Commit.py index 22384fd8..71a44993 100644 --- a/github/Commit.py +++ b/github/Commit.py @@ -30,6 +30,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.CheckRun import github.CheckSuite import github.CommitCombinedStatus @@ -48,7 +50,7 @@ class Commit(github.GithubObject.CompletableGithubObject): This class represents Commits. The reference can be found here https://docs.github.com/en/rest/reference/git#commits """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"sha": self._sha.value}) @property @@ -302,7 +304,7 @@ class Commit(github.GithubObject.CompletableGithubObject): def _identity(self): return self.sha - def _initAttributes(self): + def _initAttributes(self) -> None: self._author = github.GithubObject.NotSet self._comments_url = github.GithubObject.NotSet self._commit = github.GithubObject.NotSet @@ -314,7 +316,7 @@ class Commit(github.GithubObject.CompletableGithubObject): self._stats = github.GithubObject.NotSet self._url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "author" in attributes: # pragma no branch self._author = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["author"]) if "comments_url" in attributes: # pragma no branch diff --git a/github/CommitCombinedStatus.py b/github/CommitCombinedStatus.py index 3cfee8b4..058021cc 100644 --- a/github/CommitCombinedStatus.py +++ b/github/CommitCombinedStatus.py @@ -24,6 +24,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.CommitStatus import github.GithubObject import github.Repository @@ -34,7 +36,7 @@ class CommitCombinedStatus(github.GithubObject.NonCompletableGithubObject): This class represents CommitCombinedStatuses. The reference can be found here https://docs.github.com/en/rest/reference/repos#statuses """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"sha": self._sha.value, "state": self._state.value}) @property @@ -86,7 +88,7 @@ class CommitCombinedStatus(github.GithubObject.NonCompletableGithubObject): """ return self._statuses.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._state = github.GithubObject.NotSet self._sha = github.GithubObject.NotSet self._total_count = github.GithubObject.NotSet @@ -95,7 +97,7 @@ class CommitCombinedStatus(github.GithubObject.NonCompletableGithubObject): self._repository = github.GithubObject.NotSet self._statuses = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "state" in attributes: # pragma no branch self._state = self._makeStringAttribute(attributes["state"]) if "sha" in attributes: # pragma no branch diff --git a/github/CommitComment.py b/github/CommitComment.py index a9bf0388..d03b7843 100644 --- a/github/CommitComment.py +++ b/github/CommitComment.py @@ -31,6 +31,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject import github.NamedUser @@ -42,7 +44,7 @@ class CommitComment(github.GithubObject.CompletableGithubObject): This class represents CommitComments. The reference can be found here https://docs.github.com/en/rest/reference/repos#comments """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value, "user": self.user}) @property @@ -201,7 +203,7 @@ class CommitComment(github.GithubObject.CompletableGithubObject): ) return status == 204 - def _initAttributes(self): + def _initAttributes(self) -> None: self._body = github.GithubObject.NotSet self._commit_id = github.GithubObject.NotSet self._created_at = github.GithubObject.NotSet @@ -214,7 +216,7 @@ class CommitComment(github.GithubObject.CompletableGithubObject): self._url = github.GithubObject.NotSet self._user = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "body" in attributes: # pragma no branch self._body = self._makeStringAttribute(attributes["body"]) if "commit_id" in attributes: # pragma no branch diff --git a/github/CommitStats.py b/github/CommitStats.py index ad63c858..929e2632 100644 --- a/github/CommitStats.py +++ b/github/CommitStats.py @@ -27,6 +27,8 @@ # # ################################################################################ +from typing import Any, Dict + from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -52,7 +54,7 @@ class CommitStats(NonCompletableGithubObject): def total(self) -> int: return self._total.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "additions" in attributes: # pragma no branch self._additions = self._makeIntAttribute(attributes["additions"]) if "deletions" in attributes: # pragma no branch diff --git a/github/CommitStatus.py b/github/CommitStatus.py index b56b46d5..a1def298 100644 --- a/github/CommitStatus.py +++ b/github/CommitStatus.py @@ -30,6 +30,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject import github.NamedUser @@ -39,7 +41,7 @@ class CommitStatus(github.GithubObject.NonCompletableGithubObject): This class represents CommitStatuses.The reference can be found here https://docs.github.com/en/rest/reference/repos#statuses """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__( { "id": self._id.value, @@ -111,7 +113,7 @@ class CommitStatus(github.GithubObject.NonCompletableGithubObject): """ return self._url.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._created_at = github.GithubObject.NotSet self._creator = github.GithubObject.NotSet self._description = github.GithubObject.NotSet @@ -122,7 +124,7 @@ class CommitStatus(github.GithubObject.NonCompletableGithubObject): self._updated_at = github.GithubObject.NotSet self._url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "created_at" in attributes: # pragma no branch self._created_at = self._makeDatetimeAttribute(attributes["created_at"]) if "creator" in attributes: # pragma no branch diff --git a/github/Comparison.py b/github/Comparison.py index 0a58a289..01d6c188 100644 --- a/github/Comparison.py +++ b/github/Comparison.py @@ -27,6 +27,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.Commit import github.File import github.GithubObject @@ -141,7 +143,7 @@ class Comparison(github.GithubObject.CompletableGithubObject): self._completeIfNotSet(self._url) return self._url.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._ahead_by = github.GithubObject.NotSet self._base_commit = github.GithubObject.NotSet self._behind_by = github.GithubObject.NotSet @@ -156,7 +158,7 @@ class Comparison(github.GithubObject.CompletableGithubObject): self._total_commits = github.GithubObject.NotSet self._url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "ahead_by" in attributes: # pragma no branch self._ahead_by = self._makeIntAttribute(attributes["ahead_by"]) if "base_commit" in attributes: # pragma no branch diff --git a/github/ContentFile.py b/github/ContentFile.py index acd25d47..72a3cf37 100644 --- a/github/ContentFile.py +++ b/github/ContentFile.py @@ -30,6 +30,7 @@ ################################################################################ import base64 +from typing import Any, Dict import github.GithubObject import github.Repository @@ -40,7 +41,7 @@ class ContentFile(github.GithubObject.CompletableGithubObject): This class represents ContentFiles. The reference can be found here https://docs.github.com/en/rest/reference/repos#contents """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"path": self._path.value}) @property @@ -168,7 +169,7 @@ class ContentFile(github.GithubObject.CompletableGithubObject): self._completeIfNotSet(self._text_matches) return self._text_matches.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._content = github.GithubObject.NotSet self._text_matches = github.GithubObject.NotSet self._encoding = github.GithubObject.NotSet @@ -183,7 +184,7 @@ class ContentFile(github.GithubObject.CompletableGithubObject): self._size = github.GithubObject.NotSet self._type = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "content" in attributes: # pragma no branch self._content = self._makeStringAttribute(attributes["content"]) if "download_url" in attributes: # pragma no branch diff --git a/github/Deployment.py b/github/Deployment.py index 6bc430b9..aaf7ea24 100644 --- a/github/Deployment.py +++ b/github/Deployment.py @@ -22,6 +22,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.Consts import github.DeploymentStatus import github.GithubObject @@ -32,7 +34,7 @@ class Deployment(github.GithubObject.CompletableGithubObject): This class represents Deployments. The reference can be found here https://docs.github.com/en/rest/reference/repos#deployments """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value, "url": self._url.value}) @property @@ -245,7 +247,7 @@ class Deployment(github.GithubObject.CompletableGithubObject): ] ) - def _initAttributes(self): + def _initAttributes(self) -> None: self._id = github.GithubObject.NotSet self._production_environment = github.GithubObject.NotSet self._ref = github.GithubObject.NotSet @@ -263,7 +265,7 @@ class Deployment(github.GithubObject.CompletableGithubObject): self._statuses_url = github.GithubObject.NotSet self._repository_url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) if "production_environment" in attributes: # pragma no branch diff --git a/github/DeploymentStatus.py b/github/DeploymentStatus.py index 5ecb8e3f..c36065c0 100644 --- a/github/DeploymentStatus.py +++ b/github/DeploymentStatus.py @@ -21,6 +21,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject @@ -29,7 +31,7 @@ class DeploymentStatus(github.GithubObject.CompletableGithubObject): This class represents Deployment Statuses. The reference can be found here https://docs.github.com/en/rest/reference/repos#deployments """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value, "url": self._url.value}) @property @@ -136,7 +138,7 @@ class DeploymentStatus(github.GithubObject.CompletableGithubObject): self._completeIfNotSet(self._node_id) return self._node_id.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._created_at = github.GithubObject.NotSet self._creator = github.GithubObject.NotSet self._deployment_url = github.GithubObject.NotSet @@ -151,7 +153,7 @@ class DeploymentStatus(github.GithubObject.CompletableGithubObject): self._id = github.GithubObject.NotSet self._node_id = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "environment_url" in attributes: # pragma no branch self._environment_url = self._makeStringAttribute(attributes["environment_url"]) if "url" in attributes: # pragma no branch diff --git a/github/Download.py b/github/Download.py index bbdc9587..be0d4728 100644 --- a/github/Download.py +++ b/github/Download.py @@ -28,6 +28,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject @@ -36,7 +38,7 @@ class Download(github.GithubObject.CompletableGithubObject): This class represents Downloads. The reference can be found here https://docs.github.com/en/rest/reference/repos """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value}) @property @@ -206,7 +208,7 @@ class Download(github.GithubObject.CompletableGithubObject): """ headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) - def _initAttributes(self): + def _initAttributes(self) -> None: self._accesskeyid = github.GithubObject.NotSet self._acl = github.GithubObject.NotSet self._bucket = github.GithubObject.NotSet @@ -228,7 +230,7 @@ class Download(github.GithubObject.CompletableGithubObject): self._size = github.GithubObject.NotSet self._url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "accesskeyid" in attributes: # pragma no branch self._accesskeyid = self._makeStringAttribute( attributes["accesskeyid"] diff --git a/github/Environment.py b/github/Environment.py index 56eb2ae7..b611ba15 100644 --- a/github/Environment.py +++ b/github/Environment.py @@ -22,7 +22,7 @@ from __future__ import annotations from datetime import datetime -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any import github.EnvironmentDeploymentBranchPolicy import github.EnvironmentProtectionRule @@ -38,7 +38,7 @@ class Environment(CompletableGithubObject): This class represents Environment. The reference can be found here https://docs.github.com/en/rest/reference/deployments#environments """ - def _initAttributes(self): + def _initAttributes(self) -> None: self._created_at: Attribute[datetime] = NotSet self._html_url: Attribute[str] = NotSet self._id: Attribute[int] = NotSet @@ -49,7 +49,7 @@ class Environment(CompletableGithubObject): self._url: Attribute[str] = NotSet self._deployment_branch_policy: Attribute[EnvironmentDeploymentBranchPolicy] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"name": self._name.value}) @property @@ -101,7 +101,7 @@ class Environment(CompletableGithubObject): self._completeIfNotSet(self._deployment_branch_policy) return self._deployment_branch_policy.value - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "created_at" in attributes: # pragma no branch self._created_at = self._makeDatetimeAttribute(attributes["created_at"]) if "html_url" in attributes: # pragma no branch diff --git a/github/EnvironmentDeploymentBranchPolicy.py b/github/EnvironmentDeploymentBranchPolicy.py index 3b3a6797..5ec5df46 100644 --- a/github/EnvironmentDeploymentBranchPolicy.py +++ b/github/EnvironmentDeploymentBranchPolicy.py @@ -19,6 +19,7 @@ # along with PyGithub. If not, see . # # # ################################################################################ +from typing import Any, Dict from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -28,7 +29,11 @@ class EnvironmentDeploymentBranchPolicy(NonCompletableGithubObject): This class represents a deployment branch policy for an environment. The reference can be found here https://docs.github.com/en/rest/reference/deployments#environments """ - def __repr__(self): + def _initAttributes(self) -> None: + self._protected_branches: Attribute[bool] = NotSet + self._custom_branch_policies: Attribute[bool] = NotSet + + def __repr__(self) -> str: return self.get__repr__({}) @property @@ -39,11 +44,7 @@ class EnvironmentDeploymentBranchPolicy(NonCompletableGithubObject): def custom_branch_policies(self) -> bool: return self._custom_branch_policies.value - def _initAttributes(self): - self._protected_branches: Attribute[bool] = NotSet - self._custom_branch_policies: Attribute[bool] = NotSet - - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "protected_branches" in attributes: # pragma no branch self._protected_branches = self._makeBoolAttribute(attributes["protected_branches"]) if "custom_branch_policies" in attributes: # pragma no branch diff --git a/github/EnvironmentProtectionRule.py b/github/EnvironmentProtectionRule.py index 199972ee..2cefe9de 100644 --- a/github/EnvironmentProtectionRule.py +++ b/github/EnvironmentProtectionRule.py @@ -21,7 +21,7 @@ ################################################################################ from __future__ import annotations -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any import github.EnvironmentProtectionRuleReviewer from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -35,14 +35,14 @@ class EnvironmentProtectionRule(NonCompletableGithubObject): This class represents a protection rule for an environment. The reference can be found here https://docs.github.com/en/rest/reference/deployments#environments """ - def _initAttributes(self): + def _initAttributes(self) -> None: self._id: Attribute[int] = NotSet self._node_id: Attribute[str] = NotSet self._type: Attribute[str] = NotSet self._reviewers: Attribute[list[EnvironmentProtectionRuleReviewer]] = NotSet self._wait_timer: Attribute[int] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value}) @property @@ -67,7 +67,7 @@ class EnvironmentProtectionRule(NonCompletableGithubObject): def wait_timer(self) -> int: return self._wait_timer.value - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) if "node_id" in attributes: # pragma no branch diff --git a/github/EnvironmentProtectionRuleReviewer.py b/github/EnvironmentProtectionRuleReviewer.py index 0d938727..87cf7e8d 100644 --- a/github/EnvironmentProtectionRuleReviewer.py +++ b/github/EnvironmentProtectionRuleReviewer.py @@ -22,6 +22,8 @@ from __future__ import annotations +from typing import Any + import github.NamedUser import github.Team from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -32,11 +34,11 @@ class EnvironmentProtectionRuleReviewer(NonCompletableGithubObject): This class represents a reviewer for an EnvironmentProtectionRule. The reference can be found here https://docs.github.com/en/rest/reference/deployments#environments """ - def _initAttributes(self): + def _initAttributes(self) -> None: self._type: Attribute[str] = NotSet self._reviewer: Attribute[github.NamedUser.NamedUser | github.Team.Team] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"type": self._type.value}) @property @@ -47,7 +49,7 @@ class EnvironmentProtectionRuleReviewer(NonCompletableGithubObject): def reviewer(self) -> github.NamedUser.NamedUser | github.Team.Team: return self._reviewer.value - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "type" in attributes: # pragma no branch self._type = self._makeStringAttribute(attributes["type"]) if "reviewer" in attributes: # pragma no branch diff --git a/github/Event.py b/github/Event.py index dc506d31..9be31aaa 100644 --- a/github/Event.py +++ b/github/Event.py @@ -28,6 +28,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject import github.NamedUser import github.Organization @@ -39,7 +41,7 @@ class Event(github.GithubObject.NonCompletableGithubObject): This class represents Events. The reference can be found here https://docs.github.com/en/rest/reference/activity#events """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value, "type": self._type.value}) @property @@ -98,7 +100,7 @@ class Event(github.GithubObject.NonCompletableGithubObject): """ return self._type.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._actor = github.GithubObject.NotSet self._created_at = github.GithubObject.NotSet self._id = github.GithubObject.NotSet @@ -108,7 +110,7 @@ class Event(github.GithubObject.NonCompletableGithubObject): self._repo = github.GithubObject.NotSet self._type = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "actor" in attributes: # pragma no branch self._actor = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["actor"]) if "created_at" in attributes: # pragma no branch diff --git a/github/File.py b/github/File.py index 14a4941e..018bb6c9 100644 --- a/github/File.py +++ b/github/File.py @@ -30,6 +30,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject @@ -118,7 +120,7 @@ class File(github.GithubObject.NonCompletableGithubObject): """ return self._status.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._additions = github.GithubObject.NotSet self._blob_url = github.GithubObject.NotSet self._changes = github.GithubObject.NotSet @@ -131,7 +133,7 @@ class File(github.GithubObject.NonCompletableGithubObject): self._sha = github.GithubObject.NotSet self._status = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "additions" in attributes: # pragma no branch self._additions = self._makeIntAttribute(attributes["additions"]) if "blob_url" in attributes: # pragma no branch diff --git a/github/Gist.py b/github/Gist.py index 1f5b5d16..4644c4eb 100644 --- a/github/Gist.py +++ b/github/Gist.py @@ -31,6 +31,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GistComment import github.GistFile import github.GistHistoryState @@ -44,7 +46,7 @@ class Gist(github.GithubObject.CompletableGithubObject): This class represents Gists. The reference can be found here https://docs.github.com/en/rest/reference/gists """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value}) @property @@ -290,7 +292,7 @@ class Gist(github.GithubObject.CompletableGithubObject): """ headers, data = self._requester.requestJsonAndCheck("PUT", f"{self.url}/star") - def _initAttributes(self): + def _initAttributes(self) -> None: self._comments = github.GithubObject.NotSet self._comments_url = github.GithubObject.NotSet self._commits_url = github.GithubObject.NotSet @@ -311,7 +313,7 @@ class Gist(github.GithubObject.CompletableGithubObject): self._url = github.GithubObject.NotSet self._user = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "comments" in attributes: # pragma no branch self._comments = self._makeIntAttribute(attributes["comments"]) if "comments_url" in attributes: # pragma no branch diff --git a/github/GistComment.py b/github/GistComment.py index f5a0a7b9..60baf225 100644 --- a/github/GistComment.py +++ b/github/GistComment.py @@ -28,6 +28,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject import github.NamedUser @@ -37,7 +39,7 @@ class GistComment(github.GithubObject.CompletableGithubObject): This class represents GistComments. The reference can be found here https://docs.github.com/en/rest/reference/gists#comments """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value, "user": self._user.value}) @property @@ -108,7 +110,7 @@ class GistComment(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters) self._useAttributes(data) - def _initAttributes(self): + def _initAttributes(self) -> None: self._body = github.GithubObject.NotSet self._created_at = github.GithubObject.NotSet self._id = github.GithubObject.NotSet @@ -116,7 +118,7 @@ class GistComment(github.GithubObject.CompletableGithubObject): self._url = github.GithubObject.NotSet self._user = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "body" in attributes: # pragma no branch self._body = self._makeStringAttribute(attributes["body"]) if "created_at" in attributes: # pragma no branch diff --git a/github/GistFile.py b/github/GistFile.py index f540e154..f7dabe60 100644 --- a/github/GistFile.py +++ b/github/GistFile.py @@ -28,6 +28,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject @@ -36,7 +38,7 @@ class GistFile(github.GithubObject.NonCompletableGithubObject): This class represents GistFiles """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"filename": self._filename.value}) @property @@ -81,7 +83,7 @@ class GistFile(github.GithubObject.NonCompletableGithubObject): """ return self._type.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._content = github.GithubObject.NotSet self._filename = github.GithubObject.NotSet self._language = github.GithubObject.NotSet @@ -89,7 +91,7 @@ class GistFile(github.GithubObject.NonCompletableGithubObject): self._size = github.GithubObject.NotSet self._type = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "content" in attributes: # pragma no branch self._content = self._makeStringAttribute(attributes["content"]) if "filename" in attributes: # pragma no branch diff --git a/github/GistHistoryState.py b/github/GistHistoryState.py index ded73e7d..3b16168d 100644 --- a/github/GistHistoryState.py +++ b/github/GistHistoryState.py @@ -27,6 +27,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.CommitStats import github.Gist import github.GithubObject @@ -206,7 +208,7 @@ class GistHistoryState(github.GithubObject.CompletableGithubObject): self._completeIfNotSet(self._version) return self._version.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._change_status = github.GithubObject.NotSet self._comments = github.GithubObject.NotSet self._comments_url = github.GithubObject.NotSet @@ -229,7 +231,7 @@ class GistHistoryState(github.GithubObject.CompletableGithubObject): self._user = github.GithubObject.NotSet self._version = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "change_status" in attributes: # pragma no branch self._change_status = self._makeClassAttribute(github.CommitStats.CommitStats, attributes["change_status"]) if "comments" in attributes: # pragma no branch diff --git a/github/GitAuthor.py b/github/GitAuthor.py index 7324f863..b5a847f3 100644 --- a/github/GitAuthor.py +++ b/github/GitAuthor.py @@ -28,6 +28,7 @@ # # ################################################################################ from datetime import datetime +from typing import Any, Dict from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -42,7 +43,7 @@ class GitAuthor(NonCompletableGithubObject): self._email: Attribute[str] = NotSet self._date: Attribute[datetime] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"name": self._name.value}) @property @@ -57,7 +58,7 @@ class GitAuthor(NonCompletableGithubObject): def name(self) -> str: return self._name.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "date" in attributes: # pragma no branch self._date = self._makeDatetimeAttribute(attributes["date"]) if "email" in attributes: # pragma no branch diff --git a/github/GitBlob.py b/github/GitBlob.py index 64f61d22..0558d05d 100644 --- a/github/GitBlob.py +++ b/github/GitBlob.py @@ -28,6 +28,8 @@ # # ################################################################################ +from typing import Any, Dict + from github.GithubObject import Attribute, CompletableGithubObject, NotSet @@ -43,7 +45,7 @@ class GitBlob(CompletableGithubObject): self._size: Attribute[int] = NotSet self._url: Attribute[str] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"sha": self._sha.value}) @property @@ -71,7 +73,7 @@ class GitBlob(CompletableGithubObject): self._completeIfNotSet(self._url) return self._url.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "content" in attributes: # pragma no branch self._content = self._makeStringAttribute(attributes["content"]) if "encoding" in attributes: # pragma no branch diff --git a/github/GitCommit.py b/github/GitCommit.py index 4269fc4d..4a57e86e 100644 --- a/github/GitCommit.py +++ b/github/GitCommit.py @@ -28,6 +28,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GitAuthor import github.GithubObject import github.GitTree @@ -38,7 +40,7 @@ class GitCommit(github.GithubObject.CompletableGithubObject): This class represents GitCommits. The reference can be found here https://docs.github.com/en/rest/reference/git#commits """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"sha": self._sha.value}) @property @@ -109,7 +111,7 @@ class GitCommit(github.GithubObject.CompletableGithubObject): def _identity(self): return self.sha - def _initAttributes(self): + def _initAttributes(self) -> None: self._author = github.GithubObject.NotSet self._committer = github.GithubObject.NotSet self._html_url = github.GithubObject.NotSet @@ -119,7 +121,7 @@ class GitCommit(github.GithubObject.CompletableGithubObject): self._tree = github.GithubObject.NotSet self._url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "author" in attributes: # pragma no branch self._author = self._makeClassAttribute(github.GitAuthor.GitAuthor, attributes["author"]) if "committer" in attributes: # pragma no branch diff --git a/github/GitObject.py b/github/GitObject.py index 90d489b6..66948acd 100644 --- a/github/GitObject.py +++ b/github/GitObject.py @@ -28,6 +28,8 @@ # # ################################################################################ +from typing import Any, Dict + from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -41,7 +43,7 @@ class GitObject(NonCompletableGithubObject): self._type: Attribute[str] = NotSet self._url: Attribute[str] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"sha": self._sha.value}) @property @@ -56,7 +58,7 @@ class GitObject(NonCompletableGithubObject): def url(self) -> str: return self._url.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "sha" in attributes: # pragma no branch self._sha = self._makeStringAttribute(attributes["sha"]) if "type" in attributes: # pragma no branch diff --git a/github/GitRef.py b/github/GitRef.py index c161b35e..043b094f 100644 --- a/github/GitRef.py +++ b/github/GitRef.py @@ -30,7 +30,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any import github.GithubObject import github.GitObject @@ -50,7 +50,7 @@ class GitRef(CompletableGithubObject): self._ref: Attribute[str] = NotSet self._url: Attribute[str] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"ref": self._ref.value}) @property @@ -84,7 +84,7 @@ class GitRef(CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters) self._useAttributes(data) - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "object" in attributes: # pragma no branch self._object = self._makeClassAttribute(github.GitObject.GitObject, attributes["object"]) if "ref" in attributes: # pragma no branch diff --git a/github/GitRelease.py b/github/GitRelease.py index 36886c5b..3842cb22 100644 --- a/github/GitRelease.py +++ b/github/GitRelease.py @@ -34,6 +34,7 @@ ################################################################################ from os.path import basename +from typing import Any, Dict import github.GithubObject import github.GitReleaseAsset @@ -47,7 +48,7 @@ class GitRelease(github.GithubObject.CompletableGithubObject): This class represents GitReleases. The reference can be found here https://docs.github.com/en/rest/reference/repos#releases """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"title": self._title.value}) @property @@ -313,7 +314,7 @@ class GitRelease(github.GithubObject.CompletableGithubObject): None, ) - def _initAttributes(self): + def _initAttributes(self) -> None: self._id = github.GithubObject.NotSet self._body = github.GithubObject.NotSet self._title = github.GithubObject.NotSet @@ -332,7 +333,7 @@ class GitRelease(github.GithubObject.CompletableGithubObject): self._zipball_url = github.GithubObject.NotSet self._assets = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "id" in attributes: self._id = self._makeIntAttribute(attributes["id"]) if "body" in attributes: diff --git a/github/GitReleaseAsset.py b/github/GitReleaseAsset.py index 54f862e0..2cd2a61a 100644 --- a/github/GitReleaseAsset.py +++ b/github/GitReleaseAsset.py @@ -23,6 +23,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject @@ -31,7 +33,7 @@ class GitReleaseAsset(github.GithubObject.CompletableGithubObject): This class represents GitReleaseAssets. The reference can be found here https://docs.github.com/en/rest/reference/repos#releases """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"url": self.url}) @property @@ -149,7 +151,7 @@ class GitReleaseAsset(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters) return GitReleaseAsset(self._requester, headers, data, completed=True) - def _initAttributes(self): + def _initAttributes(self) -> None: self._url = github.GithubObject.NotSet self._id = github.GithubObject.NotSet self._name = github.GithubObject.NotSet @@ -163,7 +165,7 @@ class GitReleaseAsset(github.GithubObject.CompletableGithubObject): self._updated_at = github.GithubObject.NotSet self._browser_download_url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "url" in attributes: # pragma no branch self._url = self._makeStringAttribute(attributes["url"]) if "id" in attributes: # pragma no branch diff --git a/github/GitTag.py b/github/GitTag.py index 0af148e4..c576b1a2 100644 --- a/github/GitTag.py +++ b/github/GitTag.py @@ -30,7 +30,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any import github.GitAuthor import github.GithubObject @@ -56,7 +56,7 @@ class GitTag(CompletableGithubObject): self._tagger: Attribute[GitAuthor] = NotSet self._url: Attribute[str] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"sha": self._sha.value, "tag": self._tag.value}) @property @@ -89,7 +89,7 @@ class GitTag(CompletableGithubObject): self._completeIfNotSet(self._url) return self._url.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "message" in attributes: # pragma no branch self._message = self._makeStringAttribute(attributes["message"]) if "object" in attributes: # pragma no branch diff --git a/github/GitTree.py b/github/GitTree.py index 5a8a9cbd..ad26d25a 100644 --- a/github/GitTree.py +++ b/github/GitTree.py @@ -30,7 +30,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any import github.GitTreeElement from github.GithubObject import Attribute, CompletableGithubObject, NotSet @@ -49,7 +49,7 @@ class GitTree(CompletableGithubObject): self._tree: Attribute[list[GitTreeElement]] = NotSet self._url: Attribute[str] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"sha": self._sha.value}) @property @@ -71,7 +71,7 @@ class GitTree(CompletableGithubObject): def _identity(self) -> str: return self.sha - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "sha" in attributes: # pragma no branch self._sha = self._makeStringAttribute(attributes["sha"]) if "tree" in attributes: # pragma no branch diff --git a/github/GitTreeElement.py b/github/GitTreeElement.py index 3185b314..bd0b4b39 100644 --- a/github/GitTreeElement.py +++ b/github/GitTreeElement.py @@ -28,6 +28,8 @@ # # ################################################################################ +from typing import Any, Dict + from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -44,7 +46,7 @@ class GitTreeElement(NonCompletableGithubObject): self._type: Attribute[str] = NotSet self._url: Attribute[str] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"sha": self._sha.value, "path": self._path.value}) @property @@ -71,7 +73,7 @@ class GitTreeElement(NonCompletableGithubObject): def url(self) -> str: return self._url.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "mode" in attributes: # pragma no branch self._mode = self._makeStringAttribute(attributes["mode"]) if "path" in attributes: # pragma no branch diff --git a/github/GithubApp.py b/github/GithubApp.py index 08b71825..a6e48b77 100644 --- a/github/GithubApp.py +++ b/github/GithubApp.py @@ -20,6 +20,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject import github.NamedUser @@ -29,7 +31,7 @@ class GithubApp(github.GithubObject.CompletableGithubObject): This class represents github apps. The reference can be found here https://docs.github.com/en/rest/reference/apps """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value, "url": self._url.value}) @property @@ -127,7 +129,7 @@ class GithubApp(github.GithubObject.CompletableGithubObject): """ return self._url.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._created_at = github.GithubObject.NotSet self._description = github.GithubObject.NotSet self._events = github.GithubObject.NotSet @@ -141,7 +143,7 @@ class GithubApp(github.GithubObject.CompletableGithubObject): self._updated_at = github.GithubObject.NotSet self._url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "created_at" in attributes: # pragma no branch self._created_at = self._makeDatetimeAttribute(attributes["created_at"]) if "description" in attributes: # pragma no branch diff --git a/github/GithubObject.py b/github/GithubObject.py index 768f3ac2..0f075cdb 100644 --- a/github/GithubObject.py +++ b/github/GithubObject.py @@ -65,7 +65,7 @@ class Attribute(Protocol[T_co]): class _NotSetType: - def __repr__(self): + def __repr__(self) -> str: return "NotSet" @property @@ -90,11 +90,11 @@ def is_undefined(v: Union[T, _NotSetType]) -> TypeGuard[_NotSetType]: return isinstance(v, _NotSetType) -def is_optional(v, type: Union[Type, Tuple[Type, ...]]) -> bool: +def is_optional(v: Any, type: Union[Type, Tuple[Type, ...]]) -> bool: return isinstance(v, _NotSetType) or isinstance(v, type) -def is_optional_list(v, type: Union[Type, Tuple[Type, ...]]) -> bool: +def is_optional_list(v: Any, type: Union[Type, Tuple[Type, ...]]) -> bool: return isinstance(v, _NotSetType) or isinstance(v, list) and all(isinstance(element, type) for element in v) @@ -114,7 +114,7 @@ class _BadAttribute(Attribute): self.__exception = exception @property - def value(self): + def value(self) -> Any: raise BadAttributeException(self.__value, self.__expectedType, self.__exception) @@ -307,7 +307,7 @@ class GithubObject: Converts the object to a nicely printable string. """ - def format_params(params): + def format_params(params: Dict[str, Any]) -> typing.Generator[str, None, None]: items = list(params.items()) for k, v in sorted(items, key=itemgetter(0), reverse=True): if isinstance(v, bytes): @@ -324,10 +324,10 @@ class GithubObject: def _initAttributes(self) -> None: raise NotImplementedError("BUG: Not Implemented _initAttributes") - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: Dict[str, Any]) -> None: raise NotImplementedError("BUG: Not Implemented _useAttributes") - def _completeIfNeeded(self): + def _completeIfNeeded(self) -> None: raise NotImplementedError("BUG: Not Implemented _completeIfNeeded") @@ -350,7 +350,7 @@ class CompletableGithubObject(GithubObject): def __eq__(self, other: Any) -> bool: return other.__class__ is self.__class__ and other._url.value == self._url.value - def __hash__(self): + def __hash__(self) -> int: return hash(self._url.value) def __ne__(self, other: Any) -> bool: @@ -364,7 +364,7 @@ class CompletableGithubObject(GithubObject): if not self.__completed: self.__complete() - def __complete(self): + def __complete(self) -> None: if self._url.value is None: raise IncompletableObject(400, message="Returned object contains no URL") headers, data = self._requester.requestJsonAndCheck("GET", self._url.value) diff --git a/github/GithubRetry.py b/github/GithubRetry.py index 2d2f6ba1..6cfe4056 100644 --- a/github/GithubRetry.py +++ b/github/GithubRetry.py @@ -19,18 +19,21 @@ # along with PyGithub. If not, see . # # # ################################################################################ - import json import logging from datetime import datetime, timezone from logging import Logger -from typing import Optional +from types import TracebackType +from typing import Any, Optional from requests import Response from requests.models import CaseInsensitiveDict from requests.utils import get_encoding_from_headers -from urllib3 import HTTPResponse, Retry +from typing_extensions import Self +from urllib3 import Retry +from urllib3.connectionpool import ConnectionPool from urllib3.exceptions import MaxRetryError +from urllib3.response import HTTPResponse from github.GithubException import GithubException from github.Requester import Requester @@ -58,7 +61,7 @@ class GithubRetry(Retry): # references the class, not the module (due to re-exporting in github/__init__.py) __datetime = datetime - def __init__(self, secondary_rate_wait: float = DEFAULT_SECONDARY_RATE_WAIT, **kwargs): + def __init__(self, secondary_rate_wait: float = DEFAULT_SECONDARY_RATE_WAIT, **kwargs: Any) -> None: """ :param secondary_rate_wait: seconds to wait before retrying secondary rate limit errors :param kwargs: see urllib3.Retry for more arguments @@ -71,18 +74,18 @@ class GithubRetry(Retry): kwargs["allowed_methods"] = kwargs.get("allowed_methods", Retry.DEFAULT_ALLOWED_METHODS.union({"GET", "POST"})) super().__init__(**kwargs) - def new(self, **kw): + def new(self, **kw: Any) -> Self: kw.update(dict(secondary_rate_wait=self.secondary_rate_wait)) return super().new(**kw) def increment( self, - method=None, - url=None, - response=None, - error=None, - _pool=None, - _stacktrace=None, + method: Optional[str] = None, + url: Optional[str] = None, + response: Optional[HTTPResponse] = None, + error: Optional[Exception] = None, + _pool: Optional[ConnectionPool] = None, + _stacktrace: Optional[TracebackType] = None, ) -> Retry: if response: # we retry 403 only when there is a Retry-After header (indicating it is retry-able) @@ -103,16 +106,16 @@ class GithubRetry(Retry): # to identify retry-able methods, we inspect the response body try: - content = self.get_content(response, url) - content = json.loads(content) - message = content.get("message") + content = self.get_content(response, url) # type: ignore + content = json.loads(content) # type: ignore + message = content.get("message") # type: ignore except Exception as e: # we want to fall back to the actual github exception (probably a rate limit error) # but provide some context why we could not deal with it without another exception try: raise RuntimeError("Failed to inspect response message") from e except RuntimeError as e: - raise GithubException(response.status, content, response.headers) from e + raise GithubException(response.status, content, response.headers) from e # type: ignore try: if Requester.isRateLimitError(message): @@ -159,7 +162,7 @@ class GithubRetry(Retry): ) backoff = retry_backoff - def get_backoff_time(): + def get_backoff_time() -> float: return backoff self.__log( @@ -173,7 +176,7 @@ class GithubRetry(Retry): logging.DEBUG, "Response message does not indicate retry-able error", ) - raise Requester.createException(response.status, response.headers, content) + raise Requester.createException(response.status, response.headers, content) # type: ignore except (MaxRetryError, GithubException): raise except Exception as e: @@ -182,9 +185,13 @@ class GithubRetry(Retry): try: raise RuntimeError("Failed to determine retry backoff") from e except RuntimeError as e: - raise GithubException(response.status, content, response.headers) from e + raise GithubException(response.status, content, response.headers) from e # type: ignore - raise GithubException(response.status, content, response.headers) + raise GithubException( + response.status, # type: ignore + content, # type: ignore + response.headers, # type: ignore + ) # type: ignore # retry the request as usual return super().increment(method, url, response, error, _pool, _stacktrace) @@ -209,7 +216,7 @@ class GithubRetry(Retry): return response.content - def __log(self, level: int, message: str, **kwargs) -> None: + def __log(self, level: int, message: str, **kwargs: Any) -> None: if self.__logger is None: self.__logger = logging.getLogger(__name__) if self.__logger.isEnabledFor(level): diff --git a/github/GitignoreTemplate.py b/github/GitignoreTemplate.py index 951f611c..7f89a9c0 100644 --- a/github/GitignoreTemplate.py +++ b/github/GitignoreTemplate.py @@ -27,6 +27,8 @@ # # ################################################################################ +from typing import Any, Dict + from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -39,7 +41,7 @@ class GitignoreTemplate(NonCompletableGithubObject): self._source: Attribute[str] = NotSet self._name: Attribute[str] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"name": self._name.value}) @property @@ -50,7 +52,7 @@ class GitignoreTemplate(NonCompletableGithubObject): def name(self) -> str: return self._name.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "source" in attributes: # pragma no branch self._source = self._makeStringAttribute(attributes["source"]) if "name" in attributes: # pragma no branch diff --git a/github/Hook.py b/github/Hook.py index 8d5e9073..1cbdea45 100644 --- a/github/Hook.py +++ b/github/Hook.py @@ -29,6 +29,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject import github.HookResponse @@ -38,7 +40,7 @@ class Hook(github.GithubObject.CompletableGithubObject): This class represents Hooks. The reference can be found here https://docs.github.com/en/rest/reference/repos#webhooks """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value, "url": self._url.value}) @property @@ -194,7 +196,7 @@ class Hook(github.GithubObject.CompletableGithubObject): """ headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/pings") - def _initAttributes(self): + def _initAttributes(self) -> None: self._active = github.GithubObject.NotSet self._config = github.GithubObject.NotSet self._created_at = github.GithubObject.NotSet @@ -207,7 +209,7 @@ class Hook(github.GithubObject.CompletableGithubObject): self._url = github.GithubObject.NotSet self._ping_url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "active" in attributes: # pragma no branch self._active = self._makeBoolAttribute(attributes["active"]) if "config" in attributes: # pragma no branch diff --git a/github/HookDelivery.py b/github/HookDelivery.py index 77560631..2ae7c330 100644 --- a/github/HookDelivery.py +++ b/github/HookDelivery.py @@ -104,7 +104,7 @@ class HookDeliverySummary(github.GithubObject.NonCompletableGithubObject): def url(self) -> Optional[str]: return self._url.value - def _useAttributes(self, attributes: Dict[str, Any]): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) if "guid" in attributes: # pragma no branch diff --git a/github/HookDescription.py b/github/HookDescription.py index 86eb560c..38e617ee 100644 --- a/github/HookDescription.py +++ b/github/HookDescription.py @@ -29,6 +29,8 @@ ################################################################################ from __future__ import annotations +from typing import Any + from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -43,7 +45,7 @@ class HookDescription(NonCompletableGithubObject): self._schema: Attribute[list[list[str]]] = NotSet self._supported_events: Attribute[list[str]] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"name": self._name.value}) @property @@ -62,7 +64,7 @@ class HookDescription(NonCompletableGithubObject): def supported_events(self) -> list[str]: return self._supported_events.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "events" in attributes: # pragma no branch self._events = self._makeListOfStringsAttribute(attributes["events"]) if "name" in attributes: # pragma no branch diff --git a/github/HookResponse.py b/github/HookResponse.py index 27eb449a..90caa91a 100644 --- a/github/HookResponse.py +++ b/github/HookResponse.py @@ -28,6 +28,8 @@ # # ################################################################################ +from typing import Any, Dict + from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -41,7 +43,7 @@ class HookResponse(NonCompletableGithubObject): self._message: Attribute[str] = NotSet self._status: Attribute[str] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"status": self._status.value}) @property @@ -56,7 +58,7 @@ class HookResponse(NonCompletableGithubObject): def status(self) -> str: return self._status.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "code" in attributes: # pragma no branch self._code = self._makeIntAttribute(attributes["code"]) if "message" in attributes: # pragma no branch diff --git a/github/InputGitAuthor.py b/github/InputGitAuthor.py index 355f7153..dd6dcfb7 100644 --- a/github/InputGitAuthor.py +++ b/github/InputGitAuthor.py @@ -49,7 +49,7 @@ class InputGitAuthor: self.__email: str = email self.__date: Opt[str] = date - def __repr__(self): + def __repr__(self) -> str: return f'InputGitAuthor(name="{self.__name}")' @property diff --git a/github/Installation.py b/github/Installation.py index 26c1a1a7..46119c0b 100644 --- a/github/Installation.py +++ b/github/Installation.py @@ -24,6 +24,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.Authorization import github.Event import github.Gist @@ -57,7 +59,7 @@ class Installation(github.GithubObject.NonCompletableGithubObject): auth = auth.get_installation_auth(self.id, requester=self._requester) self._requester = self._requester.withAuth(auth) - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value}) def get_github_for_installation(self): @@ -107,13 +109,13 @@ class Installation(github.GithubObject.NonCompletableGithubObject): list_item="repositories", ) - def _initAttributes(self): + 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): + 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/InstallationAuthorization.py b/github/InstallationAuthorization.py index be9a903f..3e9a500f 100644 --- a/github/InstallationAuthorization.py +++ b/github/InstallationAuthorization.py @@ -25,7 +25,7 @@ from __future__ import annotations from datetime import datetime -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any import github.NamedUser import github.PaginatedList @@ -47,7 +47,7 @@ class InstallationAuthorization(NonCompletableGithubObject): self._permissions: Attribute[dict] = NotSet self._repository_selection: Attribute[str] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"expires_at": self._expires_at.value}) @property @@ -70,7 +70,7 @@ class InstallationAuthorization(NonCompletableGithubObject): def repository_selection(self) -> str: return self._repository_selection.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "token" in attributes: # pragma no branch self._token = self._makeStringAttribute(attributes["token"]) if "expires_at" in attributes: # pragma no branch diff --git a/github/Invitation.py b/github/Invitation.py index 0bed0d37..33f69e11 100644 --- a/github/Invitation.py +++ b/github/Invitation.py @@ -22,6 +22,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject @@ -30,7 +32,7 @@ class Invitation(github.GithubObject.CompletableGithubObject): This class represents repository invitations. The reference can be found here https://docs.github.com/en/rest/reference/repos#invitations """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value}) @property @@ -97,7 +99,7 @@ class Invitation(github.GithubObject.CompletableGithubObject): self._completeIfNotSet(self._repository) return self._repository.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._id = github.GithubObject.NotSet self._permissions = github.GithubObject.NotSet self._created_at = github.GithubObject.NotSet @@ -107,7 +109,7 @@ class Invitation(github.GithubObject.CompletableGithubObject): self._html_url = github.GithubObject.NotSet self._repository = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "repository" in attributes: # pragma no branch self._repository = self._makeClassAttribute(github.Repository.Repository, attributes["repository"]) if "created_at" in attributes: # pragma no branch diff --git a/github/Issue.py b/github/Issue.py index d6e95b07..d3ea5b69 100644 --- a/github/Issue.py +++ b/github/Issue.py @@ -45,7 +45,7 @@ from __future__ import annotations import urllib.parse from datetime import datetime -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any import github.GithubObject import github.IssueComment @@ -116,7 +116,7 @@ class Issue(CompletableGithubObject): self._url: Attribute[str] = NotSet self._user: Attribute[NamedUser] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"number": self._number.value, "title": self._title.value}) @property @@ -495,7 +495,7 @@ class Issue(CompletableGithubObject): def _identity(self) -> int: return self.number - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "active_lock_reason" in attributes: # pragma no branch self._active_lock_reason = self._makeStringAttribute(attributes["active_lock_reason"]) if "assignee" in attributes: # pragma no branch diff --git a/github/IssueComment.py b/github/IssueComment.py index 294aa6ec..dec44839 100644 --- a/github/IssueComment.py +++ b/github/IssueComment.py @@ -32,6 +32,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject import github.NamedUser @@ -43,7 +45,7 @@ class IssueComment(github.GithubObject.CompletableGithubObject): This class represents IssueComments. The reference can be found here https://docs.github.com/en/rest/reference/issues#comments """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value, "user": self._user.value}) @property @@ -178,7 +180,7 @@ class IssueComment(github.GithubObject.CompletableGithubObject): ) return status == 204 - def _initAttributes(self): + def _initAttributes(self) -> None: self._body = github.GithubObject.NotSet self._created_at = github.GithubObject.NotSet self._id = github.GithubObject.NotSet @@ -188,7 +190,7 @@ class IssueComment(github.GithubObject.CompletableGithubObject): self._html_url = github.GithubObject.NotSet self._user = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "body" in attributes: # pragma no branch self._body = self._makeStringAttribute(attributes["body"]) if "created_at" in attributes: # pragma no branch diff --git a/github/IssueEvent.py b/github/IssueEvent.py index 36297425..9d0c16aa 100644 --- a/github/IssueEvent.py +++ b/github/IssueEvent.py @@ -29,6 +29,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject import github.Issue import github.NamedUser @@ -39,7 +41,7 @@ class IssueEvent(github.GithubObject.CompletableGithubObject): This class represents IssueEvents. The reference can be found here https://docs.github.com/en/rest/reference/issues#events """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value}) @property @@ -186,7 +188,7 @@ class IssueEvent(github.GithubObject.CompletableGithubObject): self._completeIfNotSet(self._lock_reason) return self._lock_reason.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._actor = github.GithubObject.NotSet self._commit_id = github.GithubObject.NotSet self._created_at = github.GithubObject.NotSet @@ -206,7 +208,7 @@ class IssueEvent(github.GithubObject.CompletableGithubObject): self._dismissed_review = github.GithubObject.NotSet self._lock_reason = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "actor" in attributes: # pragma no branch self._actor = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["actor"]) if "commit_id" in attributes: # pragma no branch diff --git a/github/IssuePullRequest.py b/github/IssuePullRequest.py index f9c8eb4a..a2cc5567 100644 --- a/github/IssuePullRequest.py +++ b/github/IssuePullRequest.py @@ -28,6 +28,8 @@ ################################################################################ +from typing import Any, Dict + from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -53,7 +55,7 @@ class IssuePullRequest(NonCompletableGithubObject): def patch_url(self) -> str: return self._patch_url.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "diff_url" in attributes: # pragma no branch self._diff_url = self._makeStringAttribute(attributes["diff_url"]) if "html_url" in attributes: # pragma no branch diff --git a/github/Label.py b/github/Label.py index d8c6fdf8..c8703cd3 100644 --- a/github/Label.py +++ b/github/Label.py @@ -30,6 +30,7 @@ ################################################################################ import urllib.parse +from typing import Any, Dict import github.GithubObject @@ -41,7 +42,7 @@ class Label(github.GithubObject.CompletableGithubObject): This class represents Labels. The reference can be found here https://docs.github.com/en/rest/reference/issues#labels """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"name": self._name.value}) @property @@ -112,13 +113,13 @@ class Label(github.GithubObject.CompletableGithubObject): def _identity(self): return urllib.parse.quote(self.name) - def _initAttributes(self): + def _initAttributes(self) -> None: self._color = github.GithubObject.NotSet self._description = github.GithubObject.NotSet self._name = github.GithubObject.NotSet self._url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "color" in attributes: # pragma no branch self._color = self._makeStringAttribute(attributes["color"]) if "description" in attributes: # pragma no branch diff --git a/github/License.py b/github/License.py index 90c90245..c095c7a2 100644 --- a/github/License.py +++ b/github/License.py @@ -20,6 +20,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject @@ -28,7 +30,7 @@ class License(github.GithubObject.CompletableGithubObject): This class represents Licenses. The reference can be found here https://docs.github.com/en/rest/reference/licenses """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"name": self._name.value}) @property @@ -119,7 +121,7 @@ class License(github.GithubObject.CompletableGithubObject): self._completeIfNotSet(self._limitations) return self._limitations.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._key = github.GithubObject.NotSet self._name = github.GithubObject.NotSet self._spdx_id = github.GithubObject.NotSet @@ -132,7 +134,7 @@ class License(github.GithubObject.CompletableGithubObject): self._conditions = github.GithubObject.NotSet self._limitations = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "key" in attributes: # pragma no branch self._key = self._makeStringAttribute(attributes["key"]) if "name" in attributes: # pragma no branch diff --git a/github/MainClass.pyi b/github/MainClass.pyi index 7c770289..4862be32 100644 --- a/github/MainClass.pyi +++ b/github/MainClass.pyi @@ -10,6 +10,7 @@ from github.Commit import Commit from github.ContentFile import ContentFile from github.Event import Event from github.Gist import Gist +from github.GithubApp import GithubApp from github.GithubObject import GithubObject, _NotSetType from github.GitignoreTemplate import GitignoreTemplate from github.HookDescription import HookDescription @@ -95,7 +96,7 @@ class Github: def get_users(self, since: Union[int, _NotSetType] = ...) -> PaginatedList[NamedUser]: ... def load(self, f: BytesIO) -> Repository: ... # argument slug is deprecated, not included here - def get_app(self): ... + def get_app(self) -> GithubApp: ... def get_oauth_application(self, client_id: str, client_secret: str) -> ApplicationOAuth: ... @property def oauth_scopes(self) -> Optional[List[str]]: ... diff --git a/github/Membership.py b/github/Membership.py index 9ffca70d..f9278ae1 100644 --- a/github/Membership.py +++ b/github/Membership.py @@ -38,6 +38,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject @@ -46,7 +48,7 @@ class Membership(github.GithubObject.CompletableGithubObject): This class represents Membership of an organization. The reference can be found here https://docs.github.com/en/rest/reference/orgs """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"url": self._url.value}) @property @@ -97,7 +99,7 @@ class Membership(github.GithubObject.CompletableGithubObject): self._completeIfNotSet(self._user) return self._user.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._url = github.GithubObject.NotSet self._state = github.GithubObject.NotSet self._role = github.GithubObject.NotSet @@ -105,7 +107,7 @@ class Membership(github.GithubObject.CompletableGithubObject): self._organization = github.GithubObject.NotSet self._user = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "url" in attributes: # pragma no branch self._url = self._makeStringAttribute(attributes["url"]) if "state" in attributes: # pragma no branch diff --git a/github/Migration.py b/github/Migration.py index 20156dff..e293e829 100644 --- a/github/Migration.py +++ b/github/Migration.py @@ -30,6 +30,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject import github.NamedUser import github.PaginatedList @@ -42,7 +44,7 @@ class Migration(github.GithubObject.CompletableGithubObject): This class represents Migrations. The reference can be found here https://docs.github.com/en/rest/reference/migrations """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"state": self._state.value, "url": self._url.value}) @property @@ -172,7 +174,7 @@ class Migration(github.GithubObject.CompletableGithubObject): headers={"Accept": Consts.mediaTypeMigrationPreview}, ) - def _initAttributes(self): + def _initAttributes(self) -> None: self._id = github.GithubObject.NotSet self._owner = github.GithubObject.NotSet self._guid = github.GithubObject.NotSet @@ -184,7 +186,7 @@ class Migration(github.GithubObject.CompletableGithubObject): self._created_at = github.GithubObject.NotSet self._updated_at = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "id" in attributes: self._id = self._makeIntAttribute(attributes["id"]) if "owner" in attributes: diff --git a/github/Milestone.py b/github/Milestone.py index 778ea2fa..1a0882eb 100644 --- a/github/Milestone.py +++ b/github/Milestone.py @@ -29,6 +29,7 @@ ################################################################################ from datetime import date +from typing import Any, Dict import github.GithubObject import github.Label @@ -197,7 +198,7 @@ class Milestone(github.GithubObject.CompletableGithubObject): def _identity(self): return self.number - def _initAttributes(self): + def _initAttributes(self) -> None: self._closed_issues = github.GithubObject.NotSet self._created_at = github.GithubObject.NotSet self._creator = github.GithubObject.NotSet @@ -212,7 +213,7 @@ class Milestone(github.GithubObject.CompletableGithubObject): self._updated_at = github.GithubObject.NotSet self._url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "closed_issues" in attributes: # pragma no branch self._closed_issues = self._makeIntAttribute(attributes["closed_issues"]) if "created_at" in attributes: # pragma no branch diff --git a/github/NamedUser.py b/github/NamedUser.py index 029edc35..ad4fb623 100644 --- a/github/NamedUser.py +++ b/github/NamedUser.py @@ -36,6 +36,7 @@ ################################################################################ from datetime import datetime +from typing import Any, Dict import github.Event import github.Gist @@ -55,7 +56,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject): This class represents NamedUsers. The reference can be found here https://docs.github.com/en/rest/reference/users#get-a-user """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"login": self._login.value}) @property @@ -617,7 +618,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck("GET", f"/orgs/{org}/memberships/{self.login}") return github.Membership.Membership(self._requester, headers, data, completed=True) - def _initAttributes(self): + def _initAttributes(self) -> None: self._avatar_url = github.GithubObject.NotSet self._bio = github.GithubObject.NotSet self._blog = github.GithubObject.NotSet @@ -664,7 +665,7 @@ class NamedUser(github.GithubObject.CompletableGithubObject): self._updated_at = github.GithubObject.NotSet self._url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "avatar_url" in attributes: # pragma no branch self._avatar_url = self._makeStringAttribute(attributes["avatar_url"]) if "bio" in attributes: # pragma no branch diff --git a/github/Notification.py b/github/Notification.py index 8dbc3b35..d68abcd0 100644 --- a/github/Notification.py +++ b/github/Notification.py @@ -27,6 +27,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject import github.NotificationSubject import github.Repository @@ -37,7 +39,7 @@ class Notification(github.GithubObject.CompletableGithubObject): This class represents Notifications. The reference can be found here https://docs.github.com/en/rest/reference/activity#notifications """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value, "subject": self._subject.value}) @property @@ -135,7 +137,7 @@ class Notification(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck("GET", self.subject.url) return github.Issue.Issue(self._requester, headers, data, completed=True) - def _initAttributes(self): + def _initAttributes(self) -> None: self._id = github.GithubObject.NotSet self._last_read_at = github.GithubObject.NotSet self._repository = github.GithubObject.NotSet @@ -145,7 +147,7 @@ class Notification(github.GithubObject.CompletableGithubObject): self._updated_at = github.GithubObject.NotSet self._url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "id" in attributes: # pragma no branch self._id = self._makeStringAttribute(attributes["id"]) if "last_read_at" in attributes: # pragma no branch diff --git a/github/NotificationSubject.py b/github/NotificationSubject.py index 962f5204..74d6b87b 100644 --- a/github/NotificationSubject.py +++ b/github/NotificationSubject.py @@ -27,6 +27,8 @@ ################################################################################ +from typing import Any, Dict + from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -41,7 +43,7 @@ class NotificationSubject(NonCompletableGithubObject): self._latest_comment_url: Attribute[str] = NotSet self._type: Attribute[str] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"title": self._title.value}) @property @@ -60,7 +62,7 @@ class NotificationSubject(NonCompletableGithubObject): def type(self) -> str: return self._type.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "title" in attributes: # pragma no branch self._title = self._makeStringAttribute(attributes["title"]) if "url" in attributes: # pragma no branch diff --git a/github/Organization.py b/github/Organization.py index a50b2cc5..adee8a3e 100644 --- a/github/Organization.py +++ b/github/Organization.py @@ -43,6 +43,7 @@ from __future__ import annotations from datetime import datetime +from typing import Any import github.Event import github.GithubObject @@ -61,7 +62,7 @@ class Organization(github.GithubObject.CompletableGithubObject): This class represents Organizations. The reference can be found here https://docs.github.com/en/rest/reference/orgs """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"login": self._login.value}) @property @@ -1320,7 +1321,7 @@ class Organization(github.GithubObject.CompletableGithubObject): list_item="installations", ) - def _initAttributes(self): + def _initAttributes(self) -> None: self._default_repository_permission = github.GithubObject.NotSet self._has_organization_projects = github.GithubObject.NotSet self._has_repository_projects = github.GithubObject.NotSet @@ -1359,7 +1360,7 @@ class Organization(github.GithubObject.CompletableGithubObject): self._updated_at = github.GithubObject.NotSet self._url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "avatar_url" in attributes: # pragma no branch self._avatar_url = self._makeStringAttribute(attributes["avatar_url"]) if "billing_email" in attributes: # pragma no branch diff --git a/github/PaginatedList.py b/github/PaginatedList.py index 0a22cb62..548ae081 100644 --- a/github/PaginatedList.py +++ b/github/PaginatedList.py @@ -52,7 +52,7 @@ class PaginatedListBase(Generic[T]): def _fetchNextPage(self) -> List[T]: raise NotImplementedError - def __init__(self): + def __init__(self) -> None: self.__elements = [] def __getitem__(self, index: Union[int, slice]) -> Any: @@ -72,7 +72,7 @@ class PaginatedListBase(Generic[T]): def _isBiggerThan(self, index: int) -> bool: return len(self.__elements) > index or self._couldGrow() - def __fetchToIndex(self, index): + def __fetchToIndex(self, index: int) -> None: while len(self.__elements) <= index and self._couldGrow(): self._grow() @@ -200,13 +200,13 @@ class PaginatedList(PaginatedListBase[T]): r.__reverse() return r - def __reverse(self): + def __reverse(self) -> None: self._reversed = True lastUrl = self._getLastPageUrl() if lastUrl: self.__nextUrl = lastUrl - def _couldGrow(self): + def _couldGrow(self) -> bool: return self.__nextUrl is not None def _fetchNextPage(self) -> List[T]: diff --git a/github/Path.py b/github/Path.py index e1d26b96..f7388925 100644 --- a/github/Path.py +++ b/github/Path.py @@ -24,6 +24,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject @@ -33,7 +35,7 @@ class Path(github.GithubObject.NonCompletableGithubObject): The reference can be found here https://docs.github.com/en/rest/reference/repos#traffic """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__( { "path": self._path.value, @@ -71,13 +73,13 @@ class Path(github.GithubObject.NonCompletableGithubObject): """ return self._uniques.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._path = github.GithubObject.NotSet self._title = github.GithubObject.NotSet self._count = github.GithubObject.NotSet self._uniques = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "path" in attributes: # pragma no branch self._path = self._makeStringAttribute(attributes["path"]) if "title" in attributes: # pragma no branch diff --git a/github/Permissions.py b/github/Permissions.py index 9fc25735..af493894 100644 --- a/github/Permissions.py +++ b/github/Permissions.py @@ -28,6 +28,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject @@ -36,7 +38,7 @@ class Permissions(github.GithubObject.NonCompletableGithubObject): This class represents Permissions """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__( { "admin": self._admin.value, @@ -82,14 +84,14 @@ class Permissions(github.GithubObject.NonCompletableGithubObject): """ return self._triage.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._admin = github.GithubObject.NotSet self._maintain = github.GithubObject.NotSet self._pull = github.GithubObject.NotSet self._push = github.GithubObject.NotSet self._triage = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "admin" in attributes: # pragma no branch self._admin = self._makeBoolAttribute(attributes["admin"]) if "maintain" in attributes: # pragma no branch diff --git a/github/Plan.py b/github/Plan.py index 6bbbbfe3..12f89ce4 100644 --- a/github/Plan.py +++ b/github/Plan.py @@ -28,6 +28,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject @@ -36,7 +38,7 @@ class Plan(github.GithubObject.NonCompletableGithubObject): This class represents Plans """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"name": self._name.value}) @property @@ -81,7 +83,7 @@ class Plan(github.GithubObject.NonCompletableGithubObject): """ return self._seats.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._collaborators = github.GithubObject.NotSet self._name = github.GithubObject.NotSet self._private_repos = github.GithubObject.NotSet @@ -89,7 +91,7 @@ class Plan(github.GithubObject.NonCompletableGithubObject): self._filled_seats = github.GithubObject.NotSet self._seats = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "collaborators" in attributes: # pragma no branch self._collaborators = self._makeIntAttribute(attributes["collaborators"]) if "name" in attributes: # pragma no branch diff --git a/github/Project.py b/github/Project.py index f683776a..b443b9e7 100644 --- a/github/Project.py +++ b/github/Project.py @@ -20,6 +20,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject import github.ProjectColumn @@ -31,7 +33,7 @@ class Project(github.GithubObject.CompletableGithubObject): This class represents Projects. The reference can be found here https://docs.github.com/en/rest/reference/projects """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"name": self._name.value}) @property @@ -217,7 +219,7 @@ class Project(github.GithubObject.CompletableGithubObject): ) return github.ProjectColumn.ProjectColumn(self._requester, headers, data, completed=True) - def _initAttributes(self): + def _initAttributes(self) -> None: self._body = github.GithubObject.NotSet self._columns_url = github.GithubObject.NotSet self._created_at = github.GithubObject.NotSet @@ -232,7 +234,7 @@ class Project(github.GithubObject.CompletableGithubObject): self._updated_at = github.GithubObject.NotSet self._url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "body" in attributes: # pragma no branch self._body = self._makeStringAttribute(attributes["body"]) if "columns_url" in attributes: # pragma no branch diff --git a/github/ProjectCard.py b/github/ProjectCard.py index e4551bd8..3a6d3b01 100644 --- a/github/ProjectCard.py +++ b/github/ProjectCard.py @@ -20,6 +20,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject from . import Consts @@ -36,7 +38,7 @@ class ProjectCard(github.GithubObject.CompletableGithubObject): This class represents Project Cards. The reference can be found here https://docs.github.com/en/rest/reference/projects#cards """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value}) @property @@ -188,7 +190,7 @@ class ProjectCard(github.GithubObject.CompletableGithubObject): ) self._useAttributes(data) - def _initAttributes(self): + def _initAttributes(self) -> None: self._archived = github.GithubObject.NotSet self._column_url = github.GithubObject.NotSet self._content_url = github.GithubObject.NotSet @@ -200,7 +202,7 @@ class ProjectCard(github.GithubObject.CompletableGithubObject): self._updated_at = github.GithubObject.NotSet self._url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "archived" in attributes: # pragma no branch self._archived = self._makeBoolAttribute(attributes["archived"]) if "column_url" in attributes: # pragma no branch diff --git a/github/ProjectCard.pyi b/github/ProjectCard.pyi index e9f14dc0..fe53e848 100644 --- a/github/ProjectCard.pyi +++ b/github/ProjectCard.pyi @@ -21,7 +21,7 @@ class ProjectCard(CompletableGithubObject): @property def creator(self) -> NamedUser: ... def get_content(self, content_type: Union[_NotSetType, str] = ...) -> Optional[Union[PullRequest, Issue]]: ... - def edit(self, note=Union[_NotSetType, str], archived=Union[_NotSetType, bool]) -> None: ... + def edit(self, note: Union[_NotSetType, str] = ..., archived: Union[_NotSetType, bool] = ...) -> None: ... @property def id(self) -> int: ... @property diff --git a/github/ProjectColumn.py b/github/ProjectColumn.py index fa8e1e2e..a10e959f 100644 --- a/github/ProjectColumn.py +++ b/github/ProjectColumn.py @@ -20,6 +20,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject import github.Project import github.ProjectCard @@ -32,7 +34,7 @@ class ProjectColumn(github.GithubObject.CompletableGithubObject): This class represents Project Columns. The reference can be found here https://docs.github.com/en/rest/reference/projects#columns """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"name": self._name.value}) @property @@ -188,7 +190,7 @@ class ProjectColumn(github.GithubObject.CompletableGithubObject): self._useAttributes(data) - def _initAttributes(self): + def _initAttributes(self) -> None: self._cards_url = github.GithubObject.NotSet self._created_at = github.GithubObject.NotSet self._id = github.GithubObject.NotSet @@ -198,7 +200,7 @@ class ProjectColumn(github.GithubObject.CompletableGithubObject): self._updated_at = github.GithubObject.NotSet self._url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "cards_url" in attributes: # pragma no branch self._cards_url = self._makeStringAttribute(attributes["cards_url"]) if "created_at" in attributes: # pragma no branch diff --git a/github/PublicKey.py b/github/PublicKey.py index 3a2d7889..07b2accb 100644 --- a/github/PublicKey.py +++ b/github/PublicKey.py @@ -32,6 +32,7 @@ from __future__ import annotations from base64 import b64encode +from typing import Any from nacl import encoding, public @@ -57,7 +58,7 @@ class PublicKey(CompletableGithubObject): self._key_id: Attribute[str | int] = NotSet self._key: Attribute[str] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"key_id": self._key_id.value, "key": self._key.value}) @property @@ -70,7 +71,7 @@ class PublicKey(CompletableGithubObject): self._completeIfNotSet(self._key_id) return self._key_id.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "key" in attributes: # pragma no branch self._key = self._makeStringAttribute(attributes["key"]) if "key_id" in attributes: # pragma no branch diff --git a/github/PullRequest.py b/github/PullRequest.py index a1ea383f..6be88c95 100644 --- a/github/PullRequest.py +++ b/github/PullRequest.py @@ -42,6 +42,7 @@ import urllib.parse from datetime import datetime +from typing import Any, Dict import github.Commit import github.File @@ -938,7 +939,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject): ) return status == 202 - def _initAttributes(self): + def _initAttributes(self) -> None: self._additions = github.GithubObject.NotSet self._assignee = github.GithubObject.NotSet self._assignees = github.GithubObject.NotSet @@ -981,7 +982,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject): self._requested_reviewers = github.GithubObject.NotSet self._requested_teams = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "additions" in attributes: # pragma no branch self._additions = self._makeIntAttribute(attributes["additions"]) if "assignee" in attributes: # pragma no branch diff --git a/github/PullRequestComment.py b/github/PullRequestComment.py index d5d213d2..484e53d8 100644 --- a/github/PullRequestComment.py +++ b/github/PullRequestComment.py @@ -33,6 +33,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject import github.NamedUser @@ -44,7 +46,7 @@ class PullRequestComment(github.GithubObject.CompletableGithubObject): This class represents PullRequestComments. The reference can be found here https://docs.github.com/en/rest/reference/pulls#review-comments """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value, "user": self._user.value}) @property @@ -235,7 +237,7 @@ class PullRequestComment(github.GithubObject.CompletableGithubObject): ) return status == 204 - def _initAttributes(self): + def _initAttributes(self) -> None: self._body = github.GithubObject.NotSet self._commit_id = github.GithubObject.NotSet self._created_at = github.GithubObject.NotSet @@ -252,7 +254,7 @@ class PullRequestComment(github.GithubObject.CompletableGithubObject): self._html_url = github.GithubObject.NotSet self._user = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "body" in attributes: # pragma no branch self._body = self._makeStringAttribute(attributes["body"]) if "commit_id" in attributes: # pragma no branch diff --git a/github/PullRequestMergeStatus.py b/github/PullRequestMergeStatus.py index a479264c..578ff1e4 100644 --- a/github/PullRequestMergeStatus.py +++ b/github/PullRequestMergeStatus.py @@ -29,6 +29,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject @@ -37,7 +39,7 @@ class PullRequestMergeStatus(github.GithubObject.NonCompletableGithubObject): This class represents PullRequestMergeStatuses. The reference can be found here https://docs.github.com/en/rest/reference/pulls#check-if-a-pull-request-has-been-merged """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"sha": self._sha.value, "merged": self._merged.value}) @property @@ -61,12 +63,12 @@ class PullRequestMergeStatus(github.GithubObject.NonCompletableGithubObject): """ return self._sha.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._merged = github.GithubObject.NotSet self._message = github.GithubObject.NotSet self._sha = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "merged" in attributes: # pragma no branch self._merged = self._makeBoolAttribute(attributes["merged"]) if "message" in attributes: # pragma no branch diff --git a/github/PullRequestPart.py b/github/PullRequestPart.py index a48a376c..57fc8a80 100644 --- a/github/PullRequestPart.py +++ b/github/PullRequestPart.py @@ -29,7 +29,7 @@ ################################################################################ from __future__ import annotations -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any import github.NamedUser import github.Repository @@ -52,7 +52,7 @@ class PullRequestPart(NonCompletableGithubObject): self._sha: Attribute[str] = NotSet self._user: Attribute[NamedUser] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"sha": self._sha.value}) @property @@ -75,7 +75,7 @@ class PullRequestPart(NonCompletableGithubObject): def user(self) -> NamedUser: return self._user.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "label" in attributes: # pragma no branch self._label = self._makeStringAttribute(attributes["label"]) if "ref" in attributes: # pragma no branch diff --git a/github/PullRequestReview.py b/github/PullRequestReview.py index 01c48ee6..fd0c7f63 100644 --- a/github/PullRequestReview.py +++ b/github/PullRequestReview.py @@ -24,6 +24,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject import github.NamedUser @@ -33,7 +35,7 @@ class PullRequestReview(github.GithubObject.NonCompletableGithubObject): This class represents PullRequestReviews. The reference can be found here https://docs.github.com/en/rest/reference/pulls#reviews """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value, "user": self._user.value}) @property @@ -112,7 +114,7 @@ class PullRequestReview(github.GithubObject.NonCompletableGithubObject): """ headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.pull_request_url}/reviews/{self.id}") - def _initAttributes(self): + def _initAttributes(self) -> None: self._id = github.GithubObject.NotSet self._user = github.GithubObject.NotSet self._body = github.GithubObject.NotSet @@ -122,7 +124,7 @@ class PullRequestReview(github.GithubObject.NonCompletableGithubObject): self._pull_request_url = github.GithubObject.NotSet self._submitted_at = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) if "user" in attributes: # pragma no branch diff --git a/github/Rate.py b/github/Rate.py index 048dbe55..5c7b107e 100644 --- a/github/Rate.py +++ b/github/Rate.py @@ -27,6 +27,7 @@ ################################################################################ from datetime import datetime +from typing import Any, Dict from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -36,13 +37,13 @@ class Rate(NonCompletableGithubObject): This class represents Rates. The reference can be found here https://docs.github.com/en/rest/reference/rate-limit """ - def _initAttributes(self): + def _initAttributes(self) -> None: self._limit: Attribute[int] = NotSet self._remaining: Attribute[int] = NotSet self._reset: Attribute[datetime] = NotSet self._used: Attribute[int] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__( { "limit": self._limit.value, @@ -67,7 +68,7 @@ class Rate(NonCompletableGithubObject): def used(self) -> int: return self._used.value - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "limit" in attributes: # pragma no branch self._limit = self._makeIntAttribute(attributes["limit"]) if "remaining" in attributes: # pragma no branch diff --git a/github/RateLimit.py b/github/RateLimit.py index 73875b91..8a52e763 100644 --- a/github/RateLimit.py +++ b/github/RateLimit.py @@ -27,7 +27,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any import github.Rate from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -46,7 +46,7 @@ class RateLimit(NonCompletableGithubObject): self._search: Attribute[Rate] = NotSet self._graphql: Attribute[Rate] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"core": self._core.value}) @property @@ -76,7 +76,7 @@ class RateLimit(NonCompletableGithubObject): """ return self._graphql.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "core" in attributes: # pragma no branch self._core = self._makeClassAttribute(github.Rate.Rate, attributes["core"]) if "search" in attributes: # pragma no branch diff --git a/github/Reaction.py b/github/Reaction.py index 3cd0c43d..1daaccd6 100644 --- a/github/Reaction.py +++ b/github/Reaction.py @@ -24,7 +24,7 @@ from __future__ import annotations from datetime import datetime -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any import github.NamedUser from github.GithubObject import Attribute, CompletableGithubObject, NotSet @@ -46,7 +46,7 @@ class Reaction(CompletableGithubObject): self._id: Attribute[int] = NotSet self._user: Attribute[NamedUser] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value, "user": self._user.value}) @property @@ -80,7 +80,7 @@ class Reaction(CompletableGithubObject): headers={"Accept": Consts.mediaTypeReactionsPreview}, ) - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "content" in attributes: # pragma no branch self._content = self._makeStringAttribute(attributes["content"]) if "created_at" in attributes: # pragma no branch diff --git a/github/Referrer.py b/github/Referrer.py index 993b5c73..1176db6b 100644 --- a/github/Referrer.py +++ b/github/Referrer.py @@ -24,6 +24,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject @@ -33,7 +35,7 @@ class Referrer(github.GithubObject.NonCompletableGithubObject): The reference can be found here https://docs.github.com/en/rest/reference/repos#traffic """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__( { "referrer": self._referrer.value, @@ -63,12 +65,12 @@ class Referrer(github.GithubObject.NonCompletableGithubObject): """ return self._uniques.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._referrer = github.GithubObject.NotSet self._count = github.GithubObject.NotSet self._uniques = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "referrer" in attributes: # pragma no branch self._referrer = self._makeStringAttribute(attributes["referrer"]) if "count" in attributes: # pragma no branch diff --git a/github/Repository.py b/github/Repository.py index 90c9e64d..6220e0f4 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -129,6 +129,7 @@ import typing import urllib.parse from base64 import b64encode from datetime import date, datetime, timezone +from typing import Any, Dict from deprecated import deprecated @@ -202,7 +203,7 @@ class Repository(github.GithubObject.CompletableGithubObject): This class represents Repositories. The reference can be found here https://docs.github.com/en/rest/reference/repos """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"full_name": self._full_name.value}) @property @@ -3826,7 +3827,7 @@ class Repository(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck("DELETE", f"{self.url}/environments/{environment_name}") - def _initAttributes(self): + def _initAttributes(self) -> None: self._allow_auto_merge = github.GithubObject.NotSet self._allow_forking = github.GithubObject.NotSet self._allow_merge_commit = github.GithubObject.NotSet @@ -3915,7 +3916,7 @@ class Repository(github.GithubObject.CompletableGithubObject): self._watchers = github.GithubObject.NotSet self._watchers_count = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "allow_auto_merge" in attributes: # pragma no branch self._allow_auto_merge = self._makeBoolAttribute(attributes["allow_auto_merge"]) if "allow_forking" in attributes: # pragma no branch diff --git a/github/RepositoryAdvisory.py b/github/RepositoryAdvisory.py index 003c2b5d..8df4e144 100644 --- a/github/RepositoryAdvisory.py +++ b/github/RepositoryAdvisory.py @@ -41,7 +41,7 @@ class RepositoryAdvisory(NonCompletableGithubObject): The reference can be found here https://docs.github.com/en/rest/security-advisories/repository-advisories """ - def _initAttributes(self): + def _initAttributes(self) -> None: self._author: Attribute[NamedUser] = NotSet self._closed_at: Attribute[datetime] = NotSet self._created_at: Attribute[datetime] = NotSet @@ -62,7 +62,7 @@ class RepositoryAdvisory(NonCompletableGithubObject): self._vulnerabilities: Attribute[list[RepositoryAdvisoryVulnerability]] = NotSet self._withdrawn_at: Attribute[datetime] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"ghsa_id": self.ghsa_id, "summary": self.summary}) @property @@ -152,7 +152,7 @@ class RepositoryAdvisory(NonCompletableGithubObject): vulnerable_version_range: str | None = None, patched_versions: str | None = None, vulnerable_functions: list[str] | None = None, - ): + ) -> None: """ :calls: `PATCH /repos/{owner}/{repo}/security-advisories/:advisory_id `\ """ @@ -170,7 +170,7 @@ class RepositoryAdvisory(NonCompletableGithubObject): ] ) - def add_vulnerabilities(self, vulnerabilities: Iterable[AdvisoryVulnerability]): + def add_vulnerabilities(self, vulnerabilities: Iterable[AdvisoryVulnerability]) -> None: """ :calls: `PATCH /repos/{owner}/{repo}/security-advisories/:advisory_id ` """ @@ -197,7 +197,7 @@ class RepositoryAdvisory(NonCompletableGithubObject): self, login_or_user: str | github.NamedUser.NamedUser, credit_type: str, - ): + ) -> None: """ :calls: `PATCH /repos/{owner}/{repo}/security-advisories/:advisory_id ` Offers credit to a user for a vulnerability in a repository. @@ -208,7 +208,7 @@ class RepositoryAdvisory(NonCompletableGithubObject): def offer_credits( self, credited: Iterable[Credit], - ): + ) -> None: """ :calls: `PATCH /repos/{owner}/{repo}/security-advisories/:advisory_id ` Offers credit to a list of users for a vulnerability in a repository. @@ -229,7 +229,7 @@ class RepositoryAdvisory(NonCompletableGithubObject): ) self._useAttributes(data) - def revoke_credit(self, login_or_user: str | NamedUser): + def revoke_credit(self, login_or_user: str | github.NamedUser.NamedUser) -> None: """ :calls: `PATCH /repos/{owner}/{repo}/security-advisories/:advisory_id `_ """ @@ -248,7 +248,7 @@ class RepositoryAdvisory(NonCompletableGithubObject): ) self._useAttributes(data) - def clear_credits(self): + def clear_credits(self) -> None: """ :calls: `PATCH /repos/{owner}/{repo}/security-advisories/:advisory_id `_ """ @@ -326,7 +326,7 @@ class RepositoryAdvisory(NonCompletableGithubObject): self._useAttributes(data) return self - def accept_report(self): + def accept_report(self) -> None: """ :calls: `PATCH /repos/{owner}/{repo}/security-advisories/:advisory_id ` Accepts the advisory reported from an external reporter via private vulnerability reporting. @@ -339,7 +339,7 @@ class RepositoryAdvisory(NonCompletableGithubObject): ) self._useAttributes(data) - def publish(self): + def publish(self) -> None: """ :calls: `PATCH /repos/{owner}/{repo}/security-advisories/:advisory_id ` Publishes the advisory. @@ -352,7 +352,7 @@ class RepositoryAdvisory(NonCompletableGithubObject): ) self._useAttributes(data) - def close(self): + def close(self) -> None: """ :calls: `PATCH /repos/{owner}/{repo}/security-advisories/:advisory_id ` Closes the advisory. @@ -365,7 +365,7 @@ class RepositoryAdvisory(NonCompletableGithubObject): ) self._useAttributes(data) - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "author" in attributes: # pragma no branch self._author = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["author"]) if "closed_at" in attributes: # pragma no branch diff --git a/github/RepositoryAdvisoryCredit.py b/github/RepositoryAdvisoryCredit.py index 96a8726e..e0295366 100644 --- a/github/RepositoryAdvisoryCredit.py +++ b/github/RepositoryAdvisoryCredit.py @@ -21,7 +21,7 @@ ################################################################################ from __future__ import annotations -from typing import Union +from typing import Any, Union from typing_extensions import TypedDict @@ -61,11 +61,11 @@ class RepositoryAdvisoryCredit(NonCompletableGithubObject): """ return self._type.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._login: Attribute[str] = NotSet self._type: Attribute[str] = NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "login" in attributes: # pragma no branch self._login = self._makeStringAttribute(attributes["login"]) if "type" in attributes: # pragma no branch diff --git a/github/RepositoryAdvisoryCreditDetailed.py b/github/RepositoryAdvisoryCreditDetailed.py index d11309e4..90a18c89 100644 --- a/github/RepositoryAdvisoryCreditDetailed.py +++ b/github/RepositoryAdvisoryCreditDetailed.py @@ -21,6 +21,8 @@ ################################################################################ from __future__ import annotations +from typing import Any + import github.NamedUser from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -52,12 +54,12 @@ class RepositoryAdvisoryCreditDetailed(NonCompletableGithubObject): """ return self._user.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._state: Attribute[str] = NotSet self._type: Attribute[str] = NotSet self._user: Attribute[github.NamedUser.NamedUser] = NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "state" in attributes: # pragma no branch self._state = self._makeStringAttribute(attributes["state"]) if "type" in attributes: # pragma no branch diff --git a/github/RepositoryAdvisoryVulnerability.py b/github/RepositoryAdvisoryVulnerability.py index 8d5dfd73..46f85689 100644 --- a/github/RepositoryAdvisoryVulnerability.py +++ b/github/RepositoryAdvisoryVulnerability.py @@ -21,7 +21,7 @@ ################################################################################ from __future__ import annotations -from typing import TYPE_CHECKING, Union +from typing import TYPE_CHECKING, Any, Union from typing_extensions import TypedDict @@ -91,13 +91,13 @@ class RepositoryAdvisoryVulnerability(NonCompletableGithubObject): """ return self._vulnerable_version_range.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._package: Attribute[RepositoryAdvisoryVulnerabilityPackage] = NotSet self._patched_versions: Attribute[str] = NotSet self._vulnerable_functions: Attribute[list[str]] = NotSet self._vulnerable_version_range: Attribute[str] = NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "package" in attributes: # pragma no branch self._package = self._makeClassAttribute( github.RepositoryAdvisoryVulnerabilityPackage.RepositoryAdvisoryVulnerabilityPackage, diff --git a/github/RepositoryAdvisoryVulnerabilityPackage.py b/github/RepositoryAdvisoryVulnerabilityPackage.py index 3bf3701b..b8632833 100644 --- a/github/RepositoryAdvisoryVulnerabilityPackage.py +++ b/github/RepositoryAdvisoryVulnerabilityPackage.py @@ -21,15 +21,21 @@ ################################################################################ from __future__ import annotations +from typing import Any + from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet class RepositoryAdvisoryVulnerabilityPackage(NonCompletableGithubObject): """ - This class represents an identifier for a package that is vulnerable to a parent SecurityAdvisory. + This class represents an identifier for a package that is vulnerable tao parent SecurityAdvisory. The reference can be found here https://docs.github.com/en/rest/security-advisories/repository-advisories """ + def _initAttributes(self) -> None: + self._ecosystem: Attribute[str] = NotSet + self._name: Attribute[str | None] = NotSet + @property def ecosystem(self) -> str: """ @@ -44,11 +50,7 @@ class RepositoryAdvisoryVulnerabilityPackage(NonCompletableGithubObject): """ return self._name.value - def _initAttributes(self): - self._ecosystem: Attribute[str] = NotSet - self._name: Attribute[str | None] = NotSet - - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "ecosystem" in attributes: # pragma no branch self._ecosystem = self._makeStringAttribute(attributes["ecosystem"]) if "name" in attributes: # pragma no branch diff --git a/github/RepositoryKey.py b/github/RepositoryKey.py index 7c3dce5a..57e27419 100644 --- a/github/RepositoryKey.py +++ b/github/RepositoryKey.py @@ -33,6 +33,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject @@ -41,7 +43,7 @@ class RepositoryKey(github.GithubObject.CompletableGithubObject): This class represents RepositoryKeys. The reference can be found here https://docs.github.com/en/rest/reference/repos#deploy-keys """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value, "title": self._title.value}) @property @@ -107,7 +109,7 @@ class RepositoryKey(github.GithubObject.CompletableGithubObject): """ headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) - def _initAttributes(self): + def _initAttributes(self) -> None: self._created_at = github.GithubObject.NotSet self._id = github.GithubObject.NotSet self._key = github.GithubObject.NotSet @@ -116,7 +118,7 @@ class RepositoryKey(github.GithubObject.CompletableGithubObject): self._verified = github.GithubObject.NotSet self._read_only = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "created_at" in attributes: # pragma no branch self._created_at = self._makeDatetimeAttribute(attributes["created_at"]) if "id" in attributes: # pragma no branch diff --git a/github/RepositoryPreferences.py b/github/RepositoryPreferences.py index 93829df5..a6adbeed 100644 --- a/github/RepositoryPreferences.py +++ b/github/RepositoryPreferences.py @@ -22,7 +22,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any import github.Repository from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -49,7 +49,7 @@ class RepositoryPreferences(NonCompletableGithubObject): def repository(self) -> Repository: return self._repository.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "preferences" in attributes: # pragma no branch self._preferences = self._makeDictAttribute(attributes["preferences"]) if "repository" in attributes: # pragma no branch diff --git a/github/Requester.py b/github/Requester.py index 75f38039..fca3c8b7 100644 --- a/github/Requester.py +++ b/github/Requester.py @@ -104,14 +104,14 @@ class HTTPSRequestsConnectionClass: # mimic the httplib connection object def __init__( self, - host, + host: str, port: Optional[int] = None, strict: bool = False, timeout: Optional[int] = None, retry: Optional[Union[int, Retry]] = None, pool_size: Optional[int] = None, **kwargs: Any, - ): + ) -> None: self.port = port if port else 443 self.host = host self.protocol = "https" @@ -142,7 +142,7 @@ class HTTPSRequestsConnectionClass: url: str, input: Optional[Union[str, io.BufferedReader]], headers: Dict[str, str], - ): + ) -> None: self.verb = verb self.url = url self.input = input @@ -161,7 +161,7 @@ class HTTPSRequestsConnectionClass: ) return RequestsResponse(r) - def close(self): + def close(self) -> None: return @@ -201,7 +201,7 @@ class HTTPRequestsConnectionClass: ) self.session.mount("http://", self.adapter) - def request(self, verb: str, url: str, input: None, headers: Dict[str, str]): + def request(self, verb: str, url: str, input: None, headers: Dict[str, str]) -> None: self.verb = verb self.url = url self.input = input @@ -232,7 +232,7 @@ class Requester: __httpsConnectionClass = HTTPSRequestsConnectionClass __connection = None __persist = True - __logger = None + __logger: Optional[logging.Logger] = None _frameBuffer: List[Any] @@ -241,7 +241,7 @@ class Requester: cls, httpConnectionClass: Type[HTTPRequestsConnectionClass], httpsConnectionClass: Type[HTTPSRequestsConnectionClass], - ): + ) -> None: cls.__persist = False cls.__httpConnectionClass = httpConnectionClass cls.__httpsConnectionClass = httpsConnectionClass @@ -253,11 +253,11 @@ class Requester: cls.__httpsConnectionClass = HTTPSRequestsConnectionClass @classmethod - def injectLogger(cls, logger): + def injectLogger(cls, logger: logging.Logger) -> None: cls.__logger = logger @classmethod - def resetLogger(cls): + def resetLogger(cls) -> None: cls.__logger = None ############################################################# @@ -294,7 +294,7 @@ class Requester: self._frameCount = len(self._frameBuffer) - 1 - def DEBUG_ON_RESPONSE(self, statusCode: int, responseHeader: Dict[str, Union[str, int]], data: str): + def DEBUG_ON_RESPONSE(self, statusCode: int, responseHeader: Dict[str, Union[str, int]], data: str) -> None: """ Update current frame with response Current frame index will be attached to responseHeader @@ -307,7 +307,7 @@ class Requester: ] responseHeader[self.DEBUG_HEADER_KEY] = self._frameCount - def check_me(self, obj: "GithubObject"): + def check_me(self, obj: "GithubObject") -> None: if self.DEBUG_FLAG and self.ON_CHECK_ME is not None: # pragma no branch (Flag always set in tests) frame = None if self.DEBUG_HEADER_KEY in obj._headers: @@ -315,7 +315,7 @@ class Requester: frame = self._frameBuffer[frame_index] # type: ignore self.ON_CHECK_ME(obj, frame) - def _initializeDebugFeature(self): + def _initializeDebugFeature(self) -> None: self._frameCount = 0 self._frameBuffer = [] @@ -386,7 +386,7 @@ class Requester: self.__auth.withRequester(self) @property - def kwargs(self): + def kwargs(self) -> Dict[str, Any]: """ Returns arguments required to recreate this Requester with Requester.__init__, as well as with MainClass.__init__ and GithubIntegration.__init__. @@ -485,7 +485,7 @@ class Requester: ) elif o.scheme == "https": cnx = self.__httpsConnectionClass( - o.hostname, + o.hostname, # type: ignore o.port, retry=self.__retry, pool_size=self.__pool_size, @@ -561,7 +561,7 @@ class Requester: input: Optional[Any] = None, cnx: Optional[Union[HTTPRequestsConnectionClass, HTTPSRequestsConnectionClass]] = None, ) -> Tuple[int, Dict[str, Any], str]: - def encode(input): + def encode(input: Any) -> Tuple[str, str]: return "application/json", json.dumps(input) return self.__requestEncode(cnx, verb, url, parameters, headers, input, encode) @@ -575,7 +575,7 @@ class Requester: input: Optional[Dict[str, str]] = None, cnx: Optional[Union[HTTPRequestsConnectionClass, HTTPSRequestsConnectionClass]] = None, ) -> Tuple[int, Dict[str, Any], str]: - def encode(input): + def encode(input: Dict[str, Any]) -> Tuple[str, str]: boundary = "----------------------------3c3ba8b523b2" eol = "\r\n" @@ -602,7 +602,7 @@ class Requester: if headers is None: headers = {} - def encode(local_path: str): + def encode(local_path: str) -> Tuple[str, Any]: if "Content-Type" in headers: # type: ignore mime_type = headers["Content-Type"] # type: ignore else: @@ -615,9 +615,17 @@ class Requester: headers["Content-Length"] = str(os.path.getsize(input)) return self.__requestEncode(cnx, verb, url, parameters, headers, input, encode) - def requestMemoryBlobAndCheck(self, verb, url, parameters, headers, file_like, cnx=None): + def requestMemoryBlobAndCheck( + self, + verb: str, + url: str, + parameters: Any, + headers: Dict[str, Any], + file_like: io.TextIOBase, + cnx: Optional[Union[HTTPRequestsConnectionClass, HTTPSRequestsConnectionClass]] = None, + ) -> Tuple[Dict[str, Any], Any]: # The expected signature of encode means that the argument is ignored. - def encode(_): + def encode(_: Any) -> Tuple[str, Any]: return headers["Content-Type"], file_like if not cnx: @@ -784,7 +792,7 @@ class Requester: self, url: str, parameters: Dict[str, Any], - ): + ) -> str: if len(parameters) == 0: return url else: @@ -857,7 +865,7 @@ class WithRequester(Generic[T]): __requester: Requester - def __init__(self): + def __init__(self) -> None: self.__requester: Optional[Requester] = None # type: ignore @property diff --git a/github/RequiredPullRequestReviews.py b/github/RequiredPullRequestReviews.py index 4f897611..252824da 100644 --- a/github/RequiredPullRequestReviews.py +++ b/github/RequiredPullRequestReviews.py @@ -22,7 +22,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any import github.NamedUser import github.Team @@ -45,7 +45,7 @@ class RequiredPullRequestReviews(CompletableGithubObject): self._users: Attribute[list[NamedUser]] = NotSet self._teams: Attribute[list[Team]] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__( { "url": self._url.value, @@ -84,7 +84,7 @@ class RequiredPullRequestReviews(CompletableGithubObject): self._completeIfNotSet(self._teams) return self._teams.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "dismissal_restrictions" in attributes: # pragma no branch if "users" in attributes["dismissal_restrictions"]: self._users = self._makeListOfClassesAttribute( diff --git a/github/RequiredStatusChecks.py b/github/RequiredStatusChecks.py index 99ee158e..cc96b0c4 100644 --- a/github/RequiredStatusChecks.py +++ b/github/RequiredStatusChecks.py @@ -20,6 +20,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject @@ -28,7 +30,7 @@ class RequiredStatusChecks(github.GithubObject.CompletableGithubObject): This class represents Required Status Checks. The reference can be found here https://docs.github.com/en/rest/reference/repos#get-status-checks-protection """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"strict": self._strict.value, "url": self._url.value}) @property @@ -55,12 +57,12 @@ class RequiredStatusChecks(github.GithubObject.CompletableGithubObject): self._completeIfNotSet(self._url) return self._url.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._strict = github.GithubObject.NotSet self._contexts = github.GithubObject.NotSet self._url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "strict" in attributes: # pragma no branch self._strict = self._makeBoolAttribute(attributes["strict"]) if "contexts" in attributes: # pragma no branch diff --git a/github/SelfHostedActionsRunner.py b/github/SelfHostedActionsRunner.py index f7fe2423..42be491a 100644 --- a/github/SelfHostedActionsRunner.py +++ b/github/SelfHostedActionsRunner.py @@ -22,6 +22,8 @@ from __future__ import annotations +from typing import Any + from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -39,7 +41,7 @@ class SelfHostedActionsRunner(NonCompletableGithubObject): self._busy: Attribute[bool] = NotSet self._labels: Attribute[list[dict[str, int | str]]] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"name": self._name.value}) @property @@ -65,7 +67,7 @@ class SelfHostedActionsRunner(NonCompletableGithubObject): def labels(self) -> list[dict[str, int | str]]: return self._labels.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) if "name" in attributes: # pragma no branch diff --git a/github/SourceImport.py b/github/SourceImport.py index 8c26244a..e5a2e433 100644 --- a/github/SourceImport.py +++ b/github/SourceImport.py @@ -20,6 +20,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject from github import Consts @@ -29,7 +31,7 @@ class SourceImport(github.GithubObject.CompletableGithubObject): This class represents SourceImports. The reference can be found here https://docs.github.com/en/rest/reference/migrations#source-imports """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__( { "vcs_url": self._vcs_url.value, @@ -147,7 +149,7 @@ class SourceImport(github.GithubObject.CompletableGithubObject): import_header = {"Accept": Consts.mediaTypeImportPreview} return super().update(additional_headers=import_header) - def _initAttributes(self): + def _initAttributes(self) -> None: self._authors_count = github.GithubObject.NotSet self._authors_url = github.GithubObject.NotSet self._has_large_files = github.GithubObject.NotSet @@ -162,7 +164,7 @@ class SourceImport(github.GithubObject.CompletableGithubObject): self._vcs = github.GithubObject.NotSet self._vcs_url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "authors_count" in attributes: # pragma no branch self._authors_count = self._makeIntAttribute(attributes["authors_count"]) if "authors_url" in attributes: # pragma no branch diff --git a/github/Stargazer.py b/github/Stargazer.py index 63391398..4643d5b2 100644 --- a/github/Stargazer.py +++ b/github/Stargazer.py @@ -26,7 +26,7 @@ from __future__ import annotations from datetime import datetime -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any import github.NamedUser from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -45,7 +45,7 @@ class Stargazer(NonCompletableGithubObject): self._user: Attribute[NamedUser] = NotSet self._url: Attribute[str] = NotSet - def __repr__(self): + def __repr__(self) -> str: # this is not a type error, just we didn't type `NamedUser` yet. # enable type checker here after we typed attribute of `NamedUser` return self.get__repr__({"user": self._user.value._login.value}) # type: ignore @@ -58,7 +58,7 @@ class Stargazer(NonCompletableGithubObject): def user(self) -> NamedUser: return self._user.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "starred_at" in attributes: self._starred_at = self._makeDatetimeAttribute(attributes["starred_at"]) if "user" in attributes: diff --git a/github/StatsCodeFrequency.py b/github/StatsCodeFrequency.py index bdc87928..65555d3e 100755 --- a/github/StatsCodeFrequency.py +++ b/github/StatsCodeFrequency.py @@ -24,6 +24,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject @@ -53,12 +55,12 @@ class StatsCodeFrequency(github.GithubObject.NonCompletableGithubObject): """ return self._deletions.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._week = github.GithubObject.NotSet self._additions = github.GithubObject.NotSet self._deletions = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: self._week = self._makeTimestampAttribute(attributes[0]) self._additions = self._makeIntAttribute(attributes[1]) self._deletions = self._makeIntAttribute(attributes[2]) diff --git a/github/StatsCodeFrequency.pyi b/github/StatsCodeFrequency.pyi index 456bfb4b..670c7307 100644 --- a/github/StatsCodeFrequency.pyi +++ b/github/StatsCodeFrequency.pyi @@ -1,11 +1,8 @@ from datetime import datetime -from typing import List from github.GithubObject import NonCompletableGithubObject class StatsCodeFrequency(NonCompletableGithubObject): - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: List[int]) -> None: ... @property def additions(self) -> int: ... @property diff --git a/github/StatsCommitActivity.py b/github/StatsCommitActivity.py index 21c7765f..d4944ae1 100755 --- a/github/StatsCommitActivity.py +++ b/github/StatsCommitActivity.py @@ -24,6 +24,7 @@ # # ################################################################################ from datetime import datetime +from typing import Any, Dict import github.GithubObject from github.GithubObject import Attribute @@ -51,7 +52,7 @@ class StatsCommitActivity(github.GithubObject.NonCompletableGithubObject): def days(self) -> int: return self._days.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "week" in attributes: # pragma no branch self._week = self._makeTimestampAttribute(attributes["week"]) if "total" in attributes: # pragma no branch diff --git a/github/StatsContributor.py b/github/StatsContributor.py index 4e537335..0b4c2ff5 100755 --- a/github/StatsContributor.py +++ b/github/StatsContributor.py @@ -24,6 +24,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject import github.NamedUser @@ -66,13 +68,13 @@ class StatsContributor(github.GithubObject.NonCompletableGithubObject): """ return self._c.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._w = github.GithubObject.NotSet self._a = github.GithubObject.NotSet self._d = github.GithubObject.NotSet self._c = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "w" in attributes: # pragma no branch self._w = self._makeTimestampAttribute(attributes["w"]) if "a" in attributes: # pragma no branch @@ -103,12 +105,12 @@ class StatsContributor(github.GithubObject.NonCompletableGithubObject): """ return self._weeks.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._author = github.GithubObject.NotSet self._total = github.GithubObject.NotSet self._weeks = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "author" in attributes: # pragma no branch self._author = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["author"]) if "total" in attributes: # pragma no branch diff --git a/github/StatsParticipation.py b/github/StatsParticipation.py index 261ead1a..7f29811e 100755 --- a/github/StatsParticipation.py +++ b/github/StatsParticipation.py @@ -25,6 +25,8 @@ ################################################################################ from __future__ import annotations +from typing import Any + from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -45,7 +47,7 @@ class StatsParticipation(NonCompletableGithubObject): def owner(self) -> list[int]: return self._owner.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "all" in attributes: # pragma no branch self._all = self._makeListOfIntsAttribute(attributes["all"]) if "owner" in attributes: # pragma no branch diff --git a/github/StatsPunchCard.py b/github/StatsPunchCard.py index 71895ae8..81c6e1fc 100755 --- a/github/StatsPunchCard.py +++ b/github/StatsPunchCard.py @@ -23,7 +23,7 @@ # along with PyGithub. If not, see . # # # ################################################################################ -from typing import Dict, Tuple +from typing import Any, Dict, Tuple import github.GithubObject import github.NamedUser # TODO remove unused @@ -43,6 +43,6 @@ class StatsPunchCard(github.GithubObject.NonCompletableGithubObject): def _initAttributes(self) -> None: self._dict = {} - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: Any) -> None: for day, hour, commits in attributes: self._dict[(day, hour)] = commits diff --git a/github/Tag.py b/github/Tag.py index 2750f9a0..7b4f9afb 100644 --- a/github/Tag.py +++ b/github/Tag.py @@ -30,7 +30,7 @@ ################################################################################ from __future__ import annotations -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any import github.Commit from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -44,7 +44,7 @@ class Tag(NonCompletableGithubObject): This class represents Tags. The reference can be found here https://docs.github.com/en/rest/reference/repos#list-repository-tags """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"name": self._name.value, "commit": self._commit.value}) def _initAttributes(self) -> None: @@ -69,7 +69,7 @@ class Tag(NonCompletableGithubObject): def zipball_url(self) -> str: return self._zipball_url.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "commit" in attributes: # pragma no branch self._commit = self._makeClassAttribute(github.Commit.Commit, attributes["commit"]) if "name" in attributes: # pragma no branch diff --git a/github/Team.py b/github/Team.py index af71b63c..18d9f7ee 100644 --- a/github/Team.py +++ b/github/Team.py @@ -39,6 +39,8 @@ # # ################################################################################ +from typing import Any, Dict + from deprecated import deprecated import github.GithubObject @@ -57,7 +59,7 @@ class Team(github.GithubObject.CompletableGithubObject): This class represents Teams. The reference can be found here https://docs.github.com/en/rest/reference/teams """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value, "name": self._name.value}) @property @@ -446,7 +448,7 @@ class Team(github.GithubObject.CompletableGithubObject): def _identity(self): return self.id - def _initAttributes(self): + def _initAttributes(self) -> None: self._id = github.GithubObject.NotSet self._members_count = github.GithubObject.NotSet self._members_url = github.GithubObject.NotSet @@ -462,7 +464,7 @@ class Team(github.GithubObject.CompletableGithubObject): self._parent = github.GithubObject.NotSet self._html_url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) if "members_count" in attributes: # pragma no branch diff --git a/github/TeamDiscussion.py b/github/TeamDiscussion.py index ecf0772e..b7e1da00 100644 --- a/github/TeamDiscussion.py +++ b/github/TeamDiscussion.py @@ -21,6 +21,8 @@ ################################################################################ +from typing import Any, Dict + import github.GithubObject import github.NamedUser @@ -30,7 +32,7 @@ class TeamDiscussion(github.GithubObject.CompletableGithubObject): This class represents TeamDiscussions. The reference can be found here https://docs.github.com/en/rest/reference/teams#discussions """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"number": self._number.value, "title": self._title.value}) @property @@ -169,7 +171,7 @@ class TeamDiscussion(github.GithubObject.CompletableGithubObject): self._completeIfNotSet(self._url) return self._url.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._author = github.GithubObject.NotSet self._body = github.GithubObject.NotSet self._body_html = github.GithubObject.NotSet @@ -188,7 +190,7 @@ class TeamDiscussion(github.GithubObject.CompletableGithubObject): self._updated_at = github.GithubObject.NotSet self._url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "author" in attributes: # pragma no branch self._author = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["author"]) if "body" in attributes: # pragma no branch diff --git a/github/TimelineEvent.py b/github/TimelineEvent.py index 97826884..96dc0ba1 100644 --- a/github/TimelineEvent.py +++ b/github/TimelineEvent.py @@ -20,6 +20,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject import github.NamedUser import github.TimelineEventSource @@ -30,7 +32,7 @@ class TimelineEvent(github.GithubObject.NonCompletableGithubObject): This class represents IssueTimelineEvents. The reference can be found here https://docs.github.com/en/rest/reference/issues#timeline """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value}) @property @@ -117,7 +119,7 @@ class TimelineEvent(github.GithubObject.NonCompletableGithubObject): """ return self._url.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._actor = github.GithubObject.NotSet self._commit_id = github.GithubObject.NotSet self._created_at = github.GithubObject.NotSet @@ -130,7 +132,7 @@ class TimelineEvent(github.GithubObject.NonCompletableGithubObject): self._author_association = github.GithubObject.NotSet self._url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "actor" in attributes: # pragma no branch self._actor = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["actor"]) if "commit_id" in attributes: # pragma no branch diff --git a/github/TimelineEventSource.py b/github/TimelineEventSource.py index db31ead1..d1f5e95b 100644 --- a/github/TimelineEventSource.py +++ b/github/TimelineEventSource.py @@ -22,7 +22,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any import github.Issue from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -40,7 +40,7 @@ class TimelineEventSource(NonCompletableGithubObject): self._type: Attribute[str] = NotSet self._issue: Attribute[Issue] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"type": self._type.value}) @property @@ -51,7 +51,7 @@ class TimelineEventSource(NonCompletableGithubObject): def issue(self) -> Issue: return self._issue.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "type" in attributes: # pragma no branch self._type = self._makeStringAttribute(attributes["type"]) if "issue" in attributes: # pragma no branch diff --git a/github/Topic.py b/github/Topic.py index c85d9d97..2f5482ff 100644 --- a/github/Topic.py +++ b/github/Topic.py @@ -20,6 +20,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject @@ -28,7 +30,7 @@ class Topic(github.GithubObject.NonCompletableGithubObject): This class represents topics as used by https://github.com/topics. The object reference can be found here https://docs.github.com/en/rest/reference/search#search-topics """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"name": self._name.value}) @property @@ -108,7 +110,7 @@ class Topic(github.GithubObject.NonCompletableGithubObject): """ return self._score.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._name = github.GithubObject.NotSet self._display_name = github.GithubObject.NotSet self._short_description = github.GithubObject.NotSet @@ -121,7 +123,7 @@ class Topic(github.GithubObject.NonCompletableGithubObject): self._curated = github.GithubObject.NotSet self._score = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "name" in attributes: # pragma no branch self._name = self._makeStringAttribute(attributes["name"]) if "display_name" in attributes: # pragma no branch diff --git a/github/UserKey.py b/github/UserKey.py index e101a00a..8f98681e 100644 --- a/github/UserKey.py +++ b/github/UserKey.py @@ -29,6 +29,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject from github.GithubObject import Attribute @@ -45,7 +47,7 @@ class UserKey(github.GithubObject.CompletableGithubObject): self._url: Attribute[str] = github.GithubObject.NotSet self._verified: Attribute[bool] = github.GithubObject.NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value, "title": self._title.value}) @property @@ -80,7 +82,7 @@ class UserKey(github.GithubObject.CompletableGithubObject): """ headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) if "key" in attributes: # pragma no branch diff --git a/github/View.py b/github/View.py index dae12829..a79f3d4b 100644 --- a/github/View.py +++ b/github/View.py @@ -23,8 +23,8 @@ # along with PyGithub. If not, see . # # # ################################################################################ - from datetime import datetime +from typing import Any, Dict from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet @@ -40,7 +40,7 @@ class View(NonCompletableGithubObject): self._count: Attribute[int] = NotSet self._uniques: Attribute[int] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__( { "timestamp": self._timestamp.value, @@ -61,7 +61,7 @@ class View(NonCompletableGithubObject): def uniques(self) -> int: return self._uniques.value - def _useAttributes(self, attributes) -> None: + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "timestamp" in attributes: # pragma no branch self._timestamp = self._makeDatetimeAttribute(attributes["timestamp"]) if "count" in attributes: # pragma no branch diff --git a/github/Workflow.py b/github/Workflow.py index 04cfb4cd..4bea6569 100644 --- a/github/Workflow.py +++ b/github/Workflow.py @@ -20,6 +20,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject import github.WorkflowRun @@ -29,7 +31,7 @@ class Workflow(github.GithubObject.CompletableGithubObject): This class represents Workflows. The reference can be found here https://docs.github.com/en/rest/reference/actions#workflows """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"name": self._name.value, "url": self._url.value}) @property @@ -197,7 +199,7 @@ class Workflow(github.GithubObject.CompletableGithubObject): list_item="workflow_runs", ) - def _initAttributes(self): + def _initAttributes(self) -> None: self._id = github.GithubObject.NotSet self._name = github.GithubObject.NotSet self._path = github.GithubObject.NotSet @@ -208,7 +210,7 @@ class Workflow(github.GithubObject.CompletableGithubObject): self._html_url = github.GithubObject.NotSet self._badge_url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) if "name" in attributes: # pragma no branch diff --git a/github/WorkflowJob.py b/github/WorkflowJob.py index 93a8c3e5..d5cc4dad 100644 --- a/github/WorkflowJob.py +++ b/github/WorkflowJob.py @@ -20,6 +20,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject import github.WorkflowStep @@ -29,7 +31,7 @@ class WorkflowJob(github.GithubObject.CompletableGithubObject): This class represents Workflow Jobs. The reference can be found here https://docs.github.com/en/rest/reference/actions#workflow-jobs """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value, "url": self._url.value}) @property @@ -152,7 +154,7 @@ class WorkflowJob(github.GithubObject.CompletableGithubObject): headers, _ = self._requester.requestBlobAndCheck("GET", f"{self.url}/logs") return headers["location"] - def _initAttributes(self): + def _initAttributes(self) -> None: self._check_run_url = github.GithubObject.NotSet self._completed_at = github.GithubObject.NotSet self._conclusion = github.GithubObject.NotSet @@ -168,7 +170,7 @@ class WorkflowJob(github.GithubObject.CompletableGithubObject): self._steps = github.GithubObject.NotSet self._url = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "check_run_url" in attributes: # pragma no branch self._check_run_url = self._makeStringAttribute(attributes["check_run_url"]) if "completed_at" in attributes: # pragma no branch diff --git a/github/WorkflowRun.py b/github/WorkflowRun.py index 5b076ce2..72fe66d2 100644 --- a/github/WorkflowRun.py +++ b/github/WorkflowRun.py @@ -24,7 +24,7 @@ from __future__ import annotations from datetime import datetime -from typing import TYPE_CHECKING, NamedTuple +from typing import TYPE_CHECKING, Any, NamedTuple import github.GitCommit import github.PullRequest @@ -50,7 +50,7 @@ class WorkflowRun(CompletableGithubObject): This class represents Workflow Runs. The reference can be found here https://docs.github.com/en/rest/reference/actions#workflow-runs """ - def _initAttributes(self): + def _initAttributes(self) -> None: self._id: Attribute[int] = NotSet self._url: Attribute[str] = NotSet self._name: Attribute[str] = NotSet @@ -79,7 +79,7 @@ class WorkflowRun(CompletableGithubObject): self._repository: Attribute[Repository] = NotSet self._head_repository: Attribute[Repository] = NotSet - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value, "url": self._url.value}) @property @@ -276,7 +276,7 @@ class WorkflowRun(CompletableGithubObject): list_item="jobs", ) - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: dict[str, Any]) -> None: if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) if "name" in attributes: # pragma no branch diff --git a/github/WorkflowStep.py b/github/WorkflowStep.py index b5ad11c1..52de8a23 100644 --- a/github/WorkflowStep.py +++ b/github/WorkflowStep.py @@ -20,6 +20,8 @@ # # ################################################################################ +from typing import Any, Dict + import github.GithubObject @@ -28,7 +30,7 @@ class WorkflowStep(github.GithubObject.CompletableGithubObject): This class represents steps in a Workflow Job. The reference can be found here https://docs.github.com/en/rest/reference/actions#workflow-jobs """ - def __repr__(self): + def __repr__(self) -> str: return self.get__repr__({"number": self._number.value, "name": self._name.value}) @property @@ -79,7 +81,7 @@ class WorkflowStep(github.GithubObject.CompletableGithubObject): self._completeIfNotSet(self._status) return self._status.value - def _initAttributes(self): + def _initAttributes(self) -> None: self._completed_at = github.GithubObject.NotSet self._conclusion = github.GithubObject.NotSet self._name = github.GithubObject.NotSet @@ -87,7 +89,7 @@ class WorkflowStep(github.GithubObject.CompletableGithubObject): self._started_at = github.GithubObject.NotSet self._status = github.GithubObject.NotSet - def _useAttributes(self, attributes): + def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "completed_at" in attributes: # pragma no branch self._completed_at = self._makeDatetimeAttribute(attributes["completed_at"]) if "conclusion" in attributes: # pragma no branch diff --git a/github/__init__.py b/github/__init__.py index 21ae1fd8..d9d2ad24 100644 --- a/github/__init__.py +++ b/github/__init__.py @@ -34,6 +34,8 @@ like :class:`github.NamedUser.NamedUser` or :class:`github.Repository.Repository All classes inherit from :class:`github.GithubObject.GithubObject`. """ + + __all__ = [ "Auth", "AppAuthentication", diff --git a/pyproject.toml b/pyproject.toml index b4e3163f..25850001 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,8 +6,7 @@ namespace_packages = true [[tool.mypy.overrides]] module = ["github.*"] check_untyped_defs = true -# TODO: enable this later -# disallow_untyped_defs = true +disallow_untyped_defs = true [tool.black] # https://github.com/psf/black diff --git a/scripts/add_attribute.py b/scripts/add_attribute.py index f3b7671c..16920124 100644 --- a/scripts/add_attribute.py +++ b/scripts/add_attribute.py @@ -127,11 +127,11 @@ while not added: added = False -inInit = line.endswith("def _initAttributes(self):") +inInit = line.endswith("def _initAttributes(self) -> None:") while not added: line = lines[i].rstrip() i += 1 - if line == " def _initAttributes(self):": + if line == " def _initAttributes(self) -> None:": inInit = True if inInit: if not line or line.endswith(" = github.GithubObject.NotSet"): @@ -151,7 +151,7 @@ while not added: except IndexError: line = "" i += 1 - if line == " def _useAttributes(self, attributes):": + if line == " def _useAttributes(self, attributes:Dict[str,Any]) -> None:": inUse = True if inUse: if not line or line.endswith(" in attributes: # pragma no branch"):