diff --git a/github/CommitComment.py b/github/CommitComment.py index d03b7843..403e9e06 100644 --- a/github/CommitComment.py +++ b/github/CommitComment.py @@ -30,123 +30,107 @@ # along with PyGithub. If not, see . # # # ################################################################################ +from __future__ import annotations -from typing import Any, Dict +from datetime import datetime +from typing import TYPE_CHECKING, Any import github.GithubObject import github.NamedUser +from github import Consts +from github.GithubObject import Attribute, CompletableGithubObject, NotSet +from github.PaginatedList import PaginatedList -from . import Consts +if TYPE_CHECKING: + from github.Reaction import Reaction -class CommitComment(github.GithubObject.CompletableGithubObject): +class CommitComment(CompletableGithubObject): """ This class represents CommitComments. The reference can be found here https://docs.github.com/en/rest/reference/repos#comments """ + def _initAttributes(self) -> None: + self._body: Attribute[str] = NotSet + self._commit_id: Attribute[str] = NotSet + self._created_at: Attribute[datetime] = NotSet + self._html_url: Attribute[str] = NotSet + self._id: Attribute[int] = NotSet + self._line: Attribute[int] = NotSet + self._path: Attribute[str] = NotSet + self._position: Attribute[int] = NotSet + self._updated_at: Attribute[datetime] = NotSet + self._url: Attribute[str] = NotSet + self._user: Attribute[github.NamedUser.NamedUser] = NotSet + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value, "user": self.user}) @property - def body(self): - """ - :type: string - """ + def body(self) -> str: self._completeIfNotSet(self._body) return self._body.value @property - def commit_id(self): - """ - :type: string - """ + def commit_id(self) -> str: self._completeIfNotSet(self._commit_id) return self._commit_id.value @property - def created_at(self): - """ - :type: datetime.datetime - """ + def created_at(self) -> datetime: self._completeIfNotSet(self._created_at) return self._created_at.value @property - def html_url(self): - """ - :type: string - """ + def html_url(self) -> str: self._completeIfNotSet(self._html_url) return self._html_url.value @property - def id(self): - """ - :type: integer - """ + def id(self) -> int: self._completeIfNotSet(self._id) return self._id.value @property - def line(self): - """ - :type: integer - """ + def line(self) -> int: self._completeIfNotSet(self._line) return self._line.value @property - def path(self): - """ - :type: string - """ + def path(self) -> str: self._completeIfNotSet(self._path) return self._path.value @property - def position(self): - """ - :type: integer - """ + def position(self) -> int: self._completeIfNotSet(self._position) return self._position.value @property - def updated_at(self): - """ - :type: datetime.datetime - """ + def updated_at(self) -> datetime: self._completeIfNotSet(self._updated_at) return self._updated_at.value @property - def url(self): - """ - :type: string - """ + def url(self) -> str: self._completeIfNotSet(self._url) return self._url.value @property - def user(self): - """ - :type: :class:`github.NamedUser.NamedUser` - """ + def user(self) -> github.NamedUser.NamedUser: self._completeIfNotSet(self._user) return self._user.value - def delete(self): + def delete(self) -> None: """ :calls: `DELETE /repos/{owner}/{repo}/comments/{id} `_ :rtype: None """ headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) - def edit(self, body): + def edit(self, body: str) -> None: """ :calls: `PATCH /repos/{owner}/{repo}/comments/{id} `_ - :param body: string - :rtype: None """ assert isinstance(body, str), body post_parameters = { @@ -155,13 +139,13 @@ class CommitComment(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters) self._useAttributes(data) - def get_reactions(self): + def get_reactions(self) -> PaginatedList[Reaction]: """ :calls: `GET /repos/{owner}/{repo}/comments/{id}/reactions `_ :return: :class: :class:`github.PaginatedList.PaginatedList` of :class:`github.Reaction.Reaction` """ - return github.PaginatedList.PaginatedList( + return PaginatedList( github.Reaction.Reaction, self._requester, f"{self.url}/reactions", @@ -169,12 +153,10 @@ class CommitComment(github.GithubObject.CompletableGithubObject): headers={"Accept": Consts.mediaTypeReactionsPreview}, ) - def create_reaction(self, reaction_type): + def create_reaction(self, reaction_type: str) -> Reaction: """ :calls: `POST /repos/{owner}/{repo}/comments/{id}/reactions `_ - :param reaction_type: string - :rtype: :class:`github.Reaction.Reaction` """ assert isinstance(reaction_type, str), reaction_type post_parameters = { @@ -188,7 +170,7 @@ class CommitComment(github.GithubObject.CompletableGithubObject): ) return github.Reaction.Reaction(self._requester, headers, data, completed=True) - def delete_reaction(self, reaction_id): + def delete_reaction(self, reaction_id: int) -> bool: """ :calls: `DELETE /repos/{owner}/{repo}/comments/{comment_id}/reactions/{reaction_id} `_ @@ -203,20 +185,7 @@ class CommitComment(github.GithubObject.CompletableGithubObject): ) return status == 204 - def _initAttributes(self) -> None: - self._body = github.GithubObject.NotSet - self._commit_id = github.GithubObject.NotSet - self._created_at = github.GithubObject.NotSet - self._html_url = github.GithubObject.NotSet - self._id = github.GithubObject.NotSet - self._line = github.GithubObject.NotSet - self._path = github.GithubObject.NotSet - self._position = github.GithubObject.NotSet - self._updated_at = github.GithubObject.NotSet - self._url = github.GithubObject.NotSet - self._user = github.GithubObject.NotSet - - def _useAttributes(self, attributes: Dict[str, Any]) -> None: + 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/CommitComment.pyi b/github/CommitComment.pyi deleted file mode 100644 index 3aeedcbc..00000000 --- a/github/CommitComment.pyi +++ /dev/null @@ -1,39 +0,0 @@ -from datetime import datetime -from typing import Any, Dict, Optional - -from github.GithubObject import CompletableGithubObject -from github.NamedUser import NamedUser -from github.PaginatedList import PaginatedList -from github.Reaction import Reaction - -class CommitComment(CompletableGithubObject): - def __repr__(self) -> str: ... - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: Dict[str, Any]) -> None: ... - @property - def body(self) -> str: ... - @property - def commit_id(self) -> str: ... - def create_reaction(self, reaction_type: str) -> Reaction: ... - @property - def created_at(self) -> datetime: ... - def delete(self) -> None: ... - def delete_reaction(self, reaction_id: int) -> bool: ... - def edit(self, body: str) -> None: ... - def get_reactions(self) -> PaginatedList[Reaction]: ... - @property - def html_url(self) -> str: ... - @property - def id(self) -> int: ... - @property - def line(self) -> Optional[int]: ... - @property - def path(self) -> Optional[str]: ... - @property - def position(self) -> Optional[int]: ... - @property - def updated_at(self) -> datetime: ... - @property - def url(self) -> str: ... - @property - def user(self) -> NamedUser: ...