diff --git a/github/AccessToken.py b/github/AccessToken.py index 7cea4e86..e5c23fc9 100644 --- a/github/AccessToken.py +++ b/github/AccessToken.py @@ -23,23 +23,23 @@ from datetime import datetime, timedelta, timezone from typing import Optional -import github.GithubObject - -from .GithubObject import Attribute +from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet -class AccessToken(github.GithubObject.NonCompletableGithubObject): +class AccessToken(NonCompletableGithubObject): """ This class represents access tokens. """ _created: datetime - _token: Attribute[str] - _type: Attribute[str] - _scope: Attribute[str] - _expires_in: Attribute[Optional[int]] - _refresh_token: Attribute[str] - _refresh_expires_in: Attribute[Optional[int]] + + def _initAttributes(self): + self._token: Attribute[str] = NotSet + self._type: Attribute[str] = NotSet + self._scope: Attribute[str] = NotSet + self._expires_in: Attribute[Optional[int]] = NotSet + self._refresh_token: Attribute[str] = NotSet + self._refresh_expires_in: Attribute[Optional[int]] = NotSet def __repr__(self) -> str: return self.get__repr__( @@ -124,14 +124,6 @@ class AccessToken(github.GithubObject.NonCompletableGithubObject): return self._created + timedelta(seconds=seconds) return None - def _initAttributes(self): - self._token = github.GithubObject.NotSet - self._type = github.GithubObject.NotSet - self._scope = github.GithubObject.NotSet - self._expires_in = github.GithubObject.NotSet - self._refresh_token = github.GithubObject.NotSet - self._refresh_expires_in = github.GithubObject.NotSet - def _useAttributes(self, attributes): self._created = datetime.now(timezone.utc) if "access_token" in attributes: # pragma no branch diff --git a/github/ApplicationOAuth.py b/github/ApplicationOAuth.py index 31d05b21..64ed7a83 100644 --- a/github/ApplicationOAuth.py +++ b/github/ApplicationOAuth.py @@ -41,8 +41,9 @@ class ApplicationOAuth(NonCompletableGithubObject): The reference can be found at https://docs.github.com/en/developers/apps/building-github-apps/identifying-and-authorizing-users-for-github-apps """ - _client_id: Attribute[str] - _client_secret: Attribute[str] + def _initAttributes(self) -> None: + self._client_id: Attribute[str] = NotSet + self._client_secret: Attribute[str] = NotSet def __init__(self, requester, headers, attributes, completed): # this object requires a request without authentication @@ -60,10 +61,6 @@ class ApplicationOAuth(NonCompletableGithubObject): def client_secret(self) -> str: return self._client_secret.value - def _initAttributes(self) -> None: - self._client_id = NotSet - self._client_secret = NotSet - def _useAttributes(self, attributes): if "client_id" in attributes: # pragma no branch self._client_id = self._makeStringAttribute(attributes["client_id"]) diff --git a/github/Artifact.py b/github/Artifact.py index eadbe090..286978b9 100644 --- a/github/Artifact.py +++ b/github/Artifact.py @@ -36,18 +36,19 @@ class Artifact(NonCompletableGithubObject): This class represents an Artifact of Github Run """ - _archive_download_url: Attribute[str] - _created_at: Attribute[datetime] - _expired: Attribute[bool] - _expires_at: Attribute[datetime] - _head_sha: Attribute[str] - _id: Attribute[int] - _name: Attribute[str] - _node_id: Attribute[str] - _size_in_bytes: Attribute[int] - _updated_at: Attribute[datetime] - _url: Attribute[str] - _workflow_run: Attribute[WorkflowRun] + def _initAttributes(self): + self._archive_download_url: Attribute[str] = NotSet + self._created_at: Attribute[datetime] = NotSet + self._expired: Attribute[bool] = NotSet + self._expires_at: Attribute[datetime] = NotSet + self._head_sha: Attribute[str] = NotSet + self._id: Attribute[int] = NotSet + self._name: Attribute[str] = NotSet + self._node_id: Attribute[str] = NotSet + self._size_in_bytes: Attribute[int] = NotSet + self._updated_at: Attribute[datetime] = NotSet + self._url: Attribute[str] = NotSet + self._workflow_run: Attribute[WorkflowRun] = NotSet def __repr__(self): return self.get__repr__({"name": self._name.value, "id": self._id.value}) @@ -107,20 +108,6 @@ class Artifact(NonCompletableGithubObject): status, headers, data = self._requester.requestBlob("DELETE", self.url) return status == 204 - def _initAttributes(self): - self._archive_download_url = NotSet - self._created_at = NotSet - self._expired = NotSet - self._expires_at = NotSet - self._head_sha = NotSet - self._id = NotSet - self._name = NotSet - self._node_id = NotSet - self._size_in_bytes = NotSet - self._updated_at = NotSet - self._url = NotSet - self._workflow_run = NotSet - def _useAttributes(self, attributes): if "archive_download_url" in attributes: # pragma no branch self._archive_download_url = self._makeStringAttribute( diff --git a/github/AuthorizationApplication.py b/github/AuthorizationApplication.py index 38dd6509..d0f8da50 100644 --- a/github/AuthorizationApplication.py +++ b/github/AuthorizationApplication.py @@ -28,38 +28,32 @@ # # ################################################################################ -import github.GithubObject +from github.GithubObject import Attribute, CompletableGithubObject, NotSet -class AuthorizationApplication(github.GithubObject.CompletableGithubObject): +class AuthorizationApplication(CompletableGithubObject): """ This class represents AuthorizationApplications """ + def _initAttributes(self) -> None: + self._name: Attribute[str] = NotSet + self._url: Attribute[str] = NotSet + def __repr__(self): return self.get__repr__({"name": self._name.value}) @property - def name(self): - """ - :type: string - """ + def name(self) -> str: self._completeIfNotSet(self._name) return self._name.value @property - def url(self): - """ - :type: string - """ + def url(self) -> str: self._completeIfNotSet(self._url) return self._url.value - def _initAttributes(self): - self._name = github.GithubObject.NotSet - self._url = github.GithubObject.NotSet - - def _useAttributes(self, attributes): + def _useAttributes(self, attributes) -> 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/AuthorizationApplication.pyi b/github/AuthorizationApplication.pyi deleted file mode 100644 index f4537902..00000000 --- a/github/AuthorizationApplication.pyi +++ /dev/null @@ -1,11 +0,0 @@ -from typing import Dict - -from github.GithubObject import CompletableGithubObject - -class AuthorizationApplication(CompletableGithubObject): - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: Dict[str, str]) -> None: ... - @property - def name(self) -> str: ... - @property - def url(self) -> str: ... diff --git a/github/Autolink.py b/github/Autolink.py index 3188128c..8f0f5d37 100644 --- a/github/Autolink.py +++ b/github/Autolink.py @@ -20,40 +20,31 @@ # # ################################################################################ -import github.GithubObject +from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet -class Autolink(github.GithubObject.NonCompletableGithubObject): +class Autolink(NonCompletableGithubObject): + def _initAttributes(self) -> None: + self._id: Attribute[int] = NotSet + self._key_prefix: Attribute[str] = NotSet + self._url_template: Attribute[str] = NotSet + def __repr__(self): return self.get__repr__({"id": self._id.value}) @property - def id(self): - """ - :type: integer - """ + def id(self) -> int: return self._id.value @property - def key_prefix(self): - """ - :type: string - """ + def key_prefix(self) -> str: return self._key_prefix.value @property - def url_template(self): - """ - :type: string - """ + def url_template(self) -> str: return self._url_template.value - def _initAttributes(self): - self._id = github.GithubObject.NotSet - self._key_prefix = github.GithubObject.NotSet - self._url_template = github.GithubObject.NotSet - - def _useAttributes(self, attributes): + def _useAttributes(self, attributes) -> 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/Autolink.pyi b/github/Autolink.pyi deleted file mode 100644 index 3541da98..00000000 --- a/github/Autolink.pyi +++ /dev/null @@ -1,13 +0,0 @@ -from typing import Any, Dict, List - -from github.GithubObject import NonCompletableGithubObject - -class Autolink(NonCompletableGithubObject): - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: Dict[str, Any]) -> None: ... - @property - def id(self) -> int: ... - @property - def key_prefix(self) -> str: ... - @property - def url_template(self) -> str: ... diff --git a/github/BranchProtection.py b/github/BranchProtection.py index 03cc3984..6aeabdc2 100644 --- a/github/BranchProtection.py +++ b/github/BranchProtection.py @@ -20,11 +20,23 @@ # # ################################################################################ +from __future__ import annotations + +from typing import TYPE_CHECKING, Any + import github.GithubObject import github.NamedUser import github.RequiredPullRequestReviews import github.RequiredStatusChecks import github.Team +from github.GithubObject import Attribute, NotSet, Opt, is_defined +from github.PaginatedList import PaginatedList + +if TYPE_CHECKING: + from github.NamedUser import NamedUser + from github.RequiredPullRequestReviews import RequiredPullRequestReviews + from github.RequiredStatusChecks import RequiredStatusChecks + from github.Team import Team class BranchProtection(github.GithubObject.CompletableGithubObject): @@ -35,70 +47,54 @@ class BranchProtection(github.GithubObject.CompletableGithubObject): def __repr__(self): return self.get__repr__({"url": self._url.value}) + def _initAttributes(self) -> None: + self._url: Attribute[str] = NotSet + self._required_status_checks: Attribute[RequiredStatusChecks] = NotSet + self._enforce_admins: Attribute[bool] = NotSet + self._required_pull_request_reviews: Attribute[ + RequiredPullRequestReviews + ] = NotSet + self._user_push_restrictions: Opt[str] = NotSet + self._team_push_restrictions: Opt[str] = NotSet + @property - def url(self): - """ - :type: string - """ + def url(self) -> str: self._completeIfNotSet(self._url) return self._url.value @property - def required_status_checks(self): - """ - :type: :class:`github.RequiredStatusChecks.RequiredStatusChecks` - """ + def required_status_checks(self) -> RequiredStatusChecks: self._completeIfNotSet(self._required_status_checks) return self._required_status_checks.value @property - def enforce_admins(self): - """ - :type: bool - """ + def enforce_admins(self) -> bool: self._completeIfNotSet(self._enforce_admins) return self._enforce_admins.value @property - def required_pull_request_reviews(self): - """ - :type: :class:`github.RequiredPullRequestReviews.RequiredPullRequestReviews` - """ + def required_pull_request_reviews(self) -> RequiredPullRequestReviews: self._completeIfNotSet(self._required_pull_request_reviews) return self._required_pull_request_reviews.value - def get_user_push_restrictions(self): - """ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` - """ - if self._user_push_restrictions is github.GithubObject.NotSet: + def get_user_push_restrictions(self) -> PaginatedList[NamedUser] | None: + if not is_defined(self._user_push_restrictions): return None - return github.PaginatedList.PaginatedList( + return PaginatedList( github.NamedUser.NamedUser, self._requester, self._user_push_restrictions, None, ) - def get_team_push_restrictions(self): - """ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Team.Team` - """ - if self._team_push_restrictions is github.GithubObject.NotSet: + def get_team_push_restrictions(self) -> PaginatedList[Team] | None: + if not is_defined(self._team_push_restrictions): return None return github.PaginatedList.PaginatedList( github.Team.Team, self._requester, self._team_push_restrictions, None ) - def _initAttributes(self): - self._url = github.GithubObject.NotSet - self._required_status_checks = github.GithubObject.NotSet - self._enforce_admins = github.GithubObject.NotSet - self._required_pull_request_reviews = github.GithubObject.NotSet - self._user_push_restrictions = github.GithubObject.NotSet - self._team_push_restrictions = 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 "required_status_checks" in attributes: # pragma no branch diff --git a/github/BranchProtection.pyi b/github/BranchProtection.pyi deleted file mode 100644 index 5563554c..00000000 --- a/github/BranchProtection.pyi +++ /dev/null @@ -1,23 +0,0 @@ -from typing import Any, Dict - -from github.GithubObject import CompletableGithubObject -from github.NamedUser import NamedUser -from github.PaginatedList import PaginatedList -from github.RequiredPullRequestReviews import RequiredPullRequestReviews -from github.RequiredStatusChecks import RequiredStatusChecks -from github.Team import Team - -class BranchProtection(CompletableGithubObject): - def __repr__(self) -> str: ... - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: Dict[str, Any]) -> None: ... - @property - def enforce_admins(self) -> bool: ... - def get_team_push_restrictions(self) -> PaginatedList[NamedUser]: ... - def get_user_push_restrictions(self) -> PaginatedList[Team]: ... - @property - def required_pull_request_reviews(self) -> RequiredPullRequestReviews: ... - @property - def required_status_checks(self) -> RequiredStatusChecks: ... - @property - def url(self) -> str: ... diff --git a/github/CheckRunAnnotation.py b/github/CheckRunAnnotation.py index 5c7033cd..07391f98 100644 --- a/github/CheckRunAnnotation.py +++ b/github/CheckRunAnnotation.py @@ -20,93 +20,66 @@ # # ################################################################################ -import github.GithubObject +from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet -class CheckRunAnnotation(github.GithubObject.NonCompletableGithubObject): +class CheckRunAnnotation(NonCompletableGithubObject): """ This class represents check run annotations. The reference can be found here: https://docs.github.com/en/rest/reference/checks#list-check-run-annotations """ + def _initAttributes(self) -> None: + self._annotation_level: Attribute[str] = NotSet + self._end_column: Attribute[int] = NotSet + self._end_line: Attribute[int] = NotSet + self._message: Attribute[str] = NotSet + self._path: Attribute[str] = NotSet + self._raw_details: Attribute[str] = NotSet + self._start_column: Attribute[int] = NotSet + self._start_line: Attribute[int] = NotSet + self._title: Attribute[str] = NotSet + def __repr__(self): return self.get__repr__({"title": self._title.value}) @property - def annotation_level(self): - """ - :type: string - """ + def annotation_level(self) -> str: return self._annotation_level.value @property - def end_column(self): - """ - :type: integer - """ + def end_column(self) -> int: return self._end_column.value @property - def end_line(self): - """ - :type: integer - """ + def end_line(self) -> int: return self._end_line.value @property - def message(self): - """ - :type: string - """ + def message(self) -> str: return self._message.value @property - def path(self): - """ - :type: string - """ + def path(self) -> str: return self._path.value @property - def raw_details(self): - """ - :type: string - """ + def raw_details(self) -> str: return self._raw_details.value @property - def start_column(self): - """ - :type: integer - """ + def start_column(self) -> int: return self._start_column.value @property - def start_line(self): - """ - :type: integer - """ + def start_line(self) -> int: return self._start_line.value @property - def title(self): - """ - :type: string - """ + def title(self) -> str: return self._title.value - def _initAttributes(self): - self._annotation_level = github.GithubObject.NotSet - self._end_column = github.GithubObject.NotSet - self._end_line = github.GithubObject.NotSet - self._message = github.GithubObject.NotSet - self._path = github.GithubObject.NotSet - self._raw_details = github.GithubObject.NotSet - self._start_column = github.GithubObject.NotSet - self._start_line = github.GithubObject.NotSet - self._title = github.GithubObject.NotSet - - def _useAttributes(self, attributes): + def _useAttributes(self, attributes) -> None: if "annotation_level" in attributes: # pragma no branch self._annotation_level = self._makeStringAttribute( attributes["annotation_level"] diff --git a/github/CheckRunAnnotation.pyi b/github/CheckRunAnnotation.pyi deleted file mode 100644 index 263f5abb..00000000 --- a/github/CheckRunAnnotation.pyi +++ /dev/null @@ -1,26 +0,0 @@ -from typing import Any, Dict - -from github.GithubObject import NonCompletableGithubObject - -class CheckRunAnnotation(NonCompletableGithubObject): - def __repr__(self) -> str: ... - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: Dict[str, Any]) -> None: ... - @property - def annotation_level(self) -> str: ... - @property - def end_column(self) -> int: ... - @property - def end_line(self) -> int: ... - @property - def message(self) -> str: ... - @property - def path(self) -> str: ... - @property - def raw_details(self) -> str: ... - @property - def start_column(self) -> int: ... - @property - def start_line(self) -> int: ... - @property - def title(self) -> str: ... diff --git a/github/CheckRunOutput.py b/github/CheckRunOutput.py index 3dfc0238..33a96587 100644 --- a/github/CheckRunOutput.py +++ b/github/CheckRunOutput.py @@ -20,58 +20,43 @@ # # ################################################################################ -import github.GithubObject +from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet -class CheckRunOutput(github.GithubObject.NonCompletableGithubObject): +class CheckRunOutput(NonCompletableGithubObject): """This class represents the output of check run.""" + def _initAttributes(self) -> None: + self._annotations_count: Attribute[int] = NotSet + self._annotations_url: Attribute[str] = NotSet + self._summary: Attribute[str] = NotSet + self._text: Attribute[str] = NotSet + self._title: Attribute[str] = NotSet + def __repr__(self): return self.get__repr__({"title": self._title.value}) @property - def annotations_count(self): - """ - :type: integer - """ + def annotations_count(self) -> int: return self._annotations_count.value @property - def annotations_url(self): - """ - :type: string - """ + def annotations_url(self) -> str: return self._annotations_url.value @property - def summary(self): - """ - :type: string - """ + def summary(self) -> str: return self._summary.value @property - def text(self): - """ - :type: string - """ + def text(self) -> str: return self._text.value @property - def title(self): - """ - :type: string - """ + def title(self) -> str: return self._title.value - def _initAttributes(self): - self._annotations_count = github.GithubObject.NotSet - self._annotations_url = github.GithubObject.NotSet - self._summary = github.GithubObject.NotSet - self._text = github.GithubObject.NotSet - self._title = github.GithubObject.NotSet - - def _useAttributes(self, attributes): + def _useAttributes(self, attributes) -> None: if "annotations_count" in attributes: # pragma no branch self._annotations_count = self._makeIntAttribute( attributes["annotations_count"] diff --git a/github/CheckRunOutput.pyi b/github/CheckRunOutput.pyi deleted file mode 100644 index 1ab8763e..00000000 --- a/github/CheckRunOutput.pyi +++ /dev/null @@ -1,18 +0,0 @@ -from typing import Any, Dict - -from github.GithubObject import NonCompletableGithubObject - -class CheckRunOutput(NonCompletableGithubObject): - def __repr__(self) -> str: ... - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: Dict[str, Any]) -> None: ... - @property - def annotations_count(self) -> int: ... - @property - def annotations_url(self) -> str: ... - @property - def summary(self) -> str: ... - @property - def text(self) -> str: ... - @property - def title(self) -> str: ... diff --git a/github/Clones.py b/github/Clones.py index e3970e31..d45a48ad 100644 --- a/github/Clones.py +++ b/github/Clones.py @@ -23,16 +23,22 @@ # along with PyGithub. If not, see . # # # ################################################################################ +from datetime import datetime -import github.GithubObject +from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet -class Clones(github.GithubObject.NonCompletableGithubObject): +class Clones(NonCompletableGithubObject): """ This class represents a popular Path for a GitHub repository. The reference can be found here https://docs.github.com/en/rest/reference/repos#get-repository-clones """ + def _initAttributes(self) -> None: + self._timestamp: Attribute[datetime] = NotSet + self._count: Attribute[int] = NotSet + self._uniques: Attribute[int] = NotSet + def __repr__(self): return self.get__repr__( { @@ -43,32 +49,18 @@ class Clones(github.GithubObject.NonCompletableGithubObject): ) @property - def timestamp(self): - """ - :type: datetime.datetime - """ + def timestamp(self) -> datetime: return self._timestamp.value @property - def count(self): - """ - :type: integer - """ + def count(self) -> int: return self._count.value @property - def uniques(self): - """ - :type: integer - """ + def uniques(self) -> int: return self._uniques.value - def _initAttributes(self): - self._timestamp = github.GithubObject.NotSet - self._count = github.GithubObject.NotSet - self._uniques = github.GithubObject.NotSet - - def _useAttributes(self, attributes): + def _useAttributes(self, attributes) -> 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/Clones.pyi b/github/Clones.pyi deleted file mode 100644 index 4e53c125..00000000 --- a/github/Clones.pyi +++ /dev/null @@ -1,15 +0,0 @@ -from datetime import datetime -from typing import Any, Dict - -from github.GithubObject import NonCompletableGithubObject - -class Clones(NonCompletableGithubObject): - def __repr__(self) -> str: ... - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: Dict[str, Any]) -> None: ... - @property - def count(self) -> int: ... - @property - def timestamp(self) -> datetime: ... - @property - def uniques(self) -> int: ... diff --git a/github/CommitStats.py b/github/CommitStats.py index 2a511c8a..ad63c858 100644 --- a/github/CommitStats.py +++ b/github/CommitStats.py @@ -27,41 +27,32 @@ # # ################################################################################ -import github.GithubObject +from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet -class CommitStats(github.GithubObject.NonCompletableGithubObject): +class CommitStats(NonCompletableGithubObject): """ - This class represents CommitStatses. + This class represents CommitStats. """ + def _initAttributes(self) -> None: + self._total: Attribute[int] = NotSet + self._deletions: Attribute[int] = NotSet + self._additions: Attribute[int] = NotSet + @property - def additions(self): - """ - :type: integer - """ + def additions(self) -> int: return self._additions.value @property - def deletions(self): - """ - :type: integer - """ + def deletions(self) -> int: return self._deletions.value @property - def total(self): - """ - :type: integer - """ + def total(self) -> int: return self._total.value - def _initAttributes(self): - self._additions = github.GithubObject.NotSet - self._deletions = github.GithubObject.NotSet - self._total = github.GithubObject.NotSet - - def _useAttributes(self, attributes): + def _useAttributes(self, attributes) -> 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/CommitStats.pyi b/github/CommitStats.pyi deleted file mode 100644 index c6695932..00000000 --- a/github/CommitStats.pyi +++ /dev/null @@ -1,13 +0,0 @@ -from typing import Dict - -from github.GithubObject import NonCompletableGithubObject - -class CommitStats(NonCompletableGithubObject): - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: Dict[str, int]) -> None: ... - @property - def additions(self) -> int: ... - @property - def deletions(self) -> int: ... - @property - def total(self) -> int: ... diff --git a/github/GitAuthor.py b/github/GitAuthor.py index 56f7a322..7324f863 100644 --- a/github/GitAuthor.py +++ b/github/GitAuthor.py @@ -27,45 +27,37 @@ # along with PyGithub. If not, see . # # # ################################################################################ +from datetime import datetime -import github.GithubObject +from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet -class GitAuthor(github.GithubObject.NonCompletableGithubObject): +class GitAuthor(NonCompletableGithubObject): """ This class represents GitAuthors """ + def _initAttributes(self) -> None: + self._name: Attribute[str] = NotSet + self._email: Attribute[str] = NotSet + self._date: Attribute[datetime] = NotSet + def __repr__(self): return self.get__repr__({"name": self._name.value}) @property - def date(self): - """ - :type: datetime.datetime - """ + def date(self) -> datetime: return self._date.value @property - def email(self): - """ - :type: string - """ + def email(self) -> str: return self._email.value @property - def name(self): - """ - :type: string - """ + def name(self) -> str: return self._name.value - def _initAttributes(self): - self._date = github.GithubObject.NotSet - self._email = github.GithubObject.NotSet - self._name = github.GithubObject.NotSet - - def _useAttributes(self, attributes): + def _useAttributes(self, attributes) -> 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/GitAuthor.pyi b/github/GitAuthor.pyi deleted file mode 100644 index f677afeb..00000000 --- a/github/GitAuthor.pyi +++ /dev/null @@ -1,15 +0,0 @@ -from datetime import datetime -from typing import Dict - -from github.GithubObject import NonCompletableGithubObject - -class GitAuthor(NonCompletableGithubObject): - def __repr__(self) -> str: ... - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: Dict[str, str]) -> None: ... - @property - def date(self) -> datetime: ... - @property - def email(self) -> str: ... - @property - def name(self) -> str: ... diff --git a/github/GitBlob.py b/github/GitBlob.py index 01e0a3f7..64f61d22 100644 --- a/github/GitBlob.py +++ b/github/GitBlob.py @@ -28,65 +28,50 @@ # # ################################################################################ -import github.GithubObject +from github.GithubObject import Attribute, CompletableGithubObject, NotSet -class GitBlob(github.GithubObject.CompletableGithubObject): +class GitBlob(CompletableGithubObject): """ This class represents GitBlobs. The reference can be found here https://docs.github.com/en/rest/reference/git#blobs """ + def _initAttributes(self) -> None: + self._content: Attribute[str] = NotSet + self._encoding: Attribute[str] = NotSet + self._sha: Attribute[str] = NotSet + self._size: Attribute[int] = NotSet + self._url: Attribute[str] = NotSet + def __repr__(self): return self.get__repr__({"sha": self._sha.value}) @property - def content(self): - """ - :type: string - """ + def content(self) -> str: self._completeIfNotSet(self._content) return self._content.value @property - def encoding(self): - """ - :type: string - """ + def encoding(self) -> str: self._completeIfNotSet(self._encoding) return self._encoding.value @property - def sha(self): - """ - :type: string - """ + def sha(self) -> str: self._completeIfNotSet(self._sha) return self._sha.value @property - def size(self): - """ - :type: integer - """ + def size(self) -> int: self._completeIfNotSet(self._size) return self._size.value @property - def url(self): - """ - :type: string - """ + def url(self) -> str: self._completeIfNotSet(self._url) return self._url.value - def _initAttributes(self): - self._content = github.GithubObject.NotSet - self._encoding = github.GithubObject.NotSet - self._sha = github.GithubObject.NotSet - self._size = github.GithubObject.NotSet - self._url = github.GithubObject.NotSet - - def _useAttributes(self, attributes): + def _useAttributes(self, attributes) -> 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/GitBlob.pyi b/github/GitBlob.pyi deleted file mode 100644 index b3cc89c6..00000000 --- a/github/GitBlob.pyi +++ /dev/null @@ -1,18 +0,0 @@ -from typing import Any, Dict - -from github.GithubObject import CompletableGithubObject - -class GitBlob(CompletableGithubObject): - def __repr__(self) -> str: ... - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: Dict[str, Any]) -> None: ... - @property - def content(self) -> str: ... - @property - def encoding(self) -> str: ... - @property - def sha(self) -> str: ... - @property - def size(self) -> int: ... - @property - def url(self) -> str: ... diff --git a/github/GitObject.py b/github/GitObject.py index 02eb49af..90d489b6 100644 --- a/github/GitObject.py +++ b/github/GitObject.py @@ -28,44 +28,35 @@ # # ################################################################################ -import github.GithubObject +from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet -class GitObject(github.GithubObject.NonCompletableGithubObject): +class GitObject(NonCompletableGithubObject): """ This class represents GitObjects """ + def _initAttributes(self) -> None: + self._sha: Attribute[str] = NotSet + self._type: Attribute[str] = NotSet + self._url: Attribute[str] = NotSet + def __repr__(self): return self.get__repr__({"sha": self._sha.value}) @property - def sha(self): - """ - :type: string - """ + def sha(self) -> str: return self._sha.value @property - def type(self): - """ - :type: string - """ + def type(self) -> str: return self._type.value @property - def url(self): - """ - :type: string - """ + def url(self) -> str: return self._url.value - def _initAttributes(self): - self._sha = github.GithubObject.NotSet - self._type = github.GithubObject.NotSet - self._url = github.GithubObject.NotSet - - def _useAttributes(self, attributes): + def _useAttributes(self, attributes) -> 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/GitObject.pyi b/github/GitObject.pyi deleted file mode 100644 index a94b6bdb..00000000 --- a/github/GitObject.pyi +++ /dev/null @@ -1,13 +0,0 @@ -from typing import Dict - -from github.GithubObject import NonCompletableGithubObject - -class GitObject(NonCompletableGithubObject): - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: Dict[str, str]) -> None: ... - @property - def sha(self) -> str: ... - @property - def type(self) -> str: ... - @property - def url(self) -> str: ... diff --git a/github/GitRef.py b/github/GitRef.py index 96dbd35f..5b46d1bb 100644 --- a/github/GitRef.py +++ b/github/GitRef.py @@ -28,74 +28,71 @@ # # ################################################################################ +from __future__ import annotations + +from typing import TYPE_CHECKING + import github.GithubObject import github.GitObject +from github.GithubObject import ( + Attribute, + CompletableGithubObject, + NotSet, + Opt, + is_optional, +) + +if TYPE_CHECKING: + from github.GitObject import GitObject -class GitRef(github.GithubObject.CompletableGithubObject): +class GitRef(CompletableGithubObject): """ This class represents GitRefs. The reference can be found here https://docs.github.com/en/rest/reference/git#references """ + def _initAttributes(self) -> None: + self._object: Attribute[GitObject] = NotSet + self._ref: Attribute[str] = NotSet + self._url: Attribute[str] = NotSet + def __repr__(self): return self.get__repr__({"ref": self._ref.value}) @property - def object(self): - """ - :type: :class:`github.GitObject.GitObject` - """ + def object(self) -> GitObject: self._completeIfNotSet(self._object) return self._object.value @property - def ref(self): - """ - :type: string - """ + def ref(self) -> str: self._completeIfNotSet(self._ref) return self._ref.value @property - def url(self): - """ - :type: string - """ + def url(self) -> str: self._completeIfNotSet(self._url) return self._url.value - def delete(self): + def delete(self) -> None: """ :calls: `DELETE /repos/{owner}/{repo}/git/refs/{ref} `_ - :rtype: None """ headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) - def edit(self, sha, force=github.GithubObject.NotSet): + def edit(self, sha: str, force: Opt[bool] = NotSet) -> None: """ :calls: `PATCH /repos/{owner}/{repo}/git/refs/{ref} `_ - :param sha: string - :param force: bool - :rtype: None """ assert isinstance(sha, str), sha - assert force is github.GithubObject.NotSet or isinstance(force, bool), force - post_parameters = { - "sha": sha, - } - if force is not github.GithubObject.NotSet: - post_parameters["force"] = force + assert is_optional(force, bool), force + post_parameters = NotSet.remove_unset_items({"sha": sha, "force": force}) headers, data = self._requester.requestJsonAndCheck( "PATCH", self.url, input=post_parameters ) self._useAttributes(data) - def _initAttributes(self): - self._object = github.GithubObject.NotSet - self._ref = github.GithubObject.NotSet - self._url = github.GithubObject.NotSet - - def _useAttributes(self, attributes): + def _useAttributes(self, attributes) -> None: if "object" in attributes: # pragma no branch self._object = self._makeClassAttribute( github.GitObject.GitObject, attributes["object"] diff --git a/github/GitRef.pyi b/github/GitRef.pyi deleted file mode 100644 index bb4fd103..00000000 --- a/github/GitRef.pyi +++ /dev/null @@ -1,17 +0,0 @@ -from typing import Any, Dict, Union - -from github.GithubObject import CompletableGithubObject, _NotSetType -from github.GitObject import GitObject - -class GitRef(CompletableGithubObject): - def __repr__(self) -> str: ... - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: Dict[str, Any]) -> None: ... - def delete(self) -> None: ... - def edit(self, sha: str, force: Union[bool, _NotSetType] = ...) -> None: ... - @property - def object(self) -> GitObject: ... - @property - def ref(self) -> str: ... - @property - def url(self) -> str: ... diff --git a/github/GitTag.py b/github/GitTag.py index a3d0a160..9c7250f1 100644 --- a/github/GitTag.py +++ b/github/GitTag.py @@ -28,76 +28,68 @@ # # ################################################################################ +from __future__ import annotations + +from typing import TYPE_CHECKING + import github.GitAuthor import github.GithubObject import github.GitObject +import github.GitTreeElement +from github.GithubObject import Attribute, CompletableGithubObject, NotSet + +if TYPE_CHECKING: + from github.GitAuthor import GitAuthor + from github.GitObject import GitObject -class GitTag(github.GithubObject.CompletableGithubObject): +class GitTag(CompletableGithubObject): """ This class represents GitTags. The reference can be found here https://docs.github.com/en/rest/reference/git#tags """ + def _initAttributes(self) -> None: + self._message: Attribute[str] = NotSet + self._object: Attribute[GitObject] = NotSet + self._sha: Attribute[str] = NotSet + self._tag: Attribute[str] = NotSet + self._tagger: Attribute[GitAuthor] = NotSet + self._url: Attribute[str] = NotSet + def __repr__(self): return self.get__repr__({"sha": self._sha.value, "tag": self._tag.value}) @property - def message(self): - """ - :type: string - """ + def message(self) -> str: self._completeIfNotSet(self._message) return self._message.value @property - def object(self): - """ - :type: :class:`github.GitObject.GitObject` - """ + def object(self) -> GitObject: self._completeIfNotSet(self._object) return self._object.value @property - def sha(self): - """ - :type: string - """ + def sha(self) -> str: self._completeIfNotSet(self._sha) return self._sha.value @property - def tag(self): - """ - :type: string - """ + def tag(self) -> str: self._completeIfNotSet(self._tag) return self._tag.value @property - def tagger(self): - """ - :type: :class:`github.GitAuthor.GitAuthor` - """ + def tagger(self) -> GitAuthor: self._completeIfNotSet(self._tagger) return self._tagger.value @property - def url(self): - """ - :type: string - """ + def url(self) -> str: self._completeIfNotSet(self._url) return self._url.value - def _initAttributes(self): - self._message = github.GithubObject.NotSet - self._object = github.GithubObject.NotSet - self._sha = github.GithubObject.NotSet - self._tag = github.GithubObject.NotSet - self._tagger = github.GithubObject.NotSet - self._url = github.GithubObject.NotSet - - def _useAttributes(self, attributes): + def _useAttributes(self, attributes) -> 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/GitTag.pyi b/github/GitTag.pyi deleted file mode 100644 index c3ef12fd..00000000 --- a/github/GitTag.pyi +++ /dev/null @@ -1,22 +0,0 @@ -from typing import Any, Dict, Union - -from github.GitAuthor import GitAuthor -from github.GithubObject import CompletableGithubObject -from github.GitObject import GitObject - -class GitTag(CompletableGithubObject): - def __repr__(self) -> str: ... - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: Dict[str, Any]) -> None: ... - @property - def message(self) -> str: ... - @property - def object(self) -> GitObject: ... - @property - def sha(self) -> str: ... - @property - def tag(self) -> str: ... - @property - def tagger(self) -> GitAuthor: ... - @property - def url(self) -> str: ... diff --git a/github/GitTree.py b/github/GitTree.py index 60c25373..09caacfe 100644 --- a/github/GitTree.py +++ b/github/GitTree.py @@ -28,52 +28,50 @@ # # ################################################################################ -import github.GithubObject +from __future__ import annotations + +from typing import TYPE_CHECKING + import github.GitTreeElement +from github.GithubObject import Attribute, CompletableGithubObject, NotSet + +if TYPE_CHECKING: + from github.GitTreeElement import GitTreeElement -class GitTree(github.GithubObject.CompletableGithubObject): +class GitTree(CompletableGithubObject): """ This class represents GitTrees. The reference can be found here https://docs.github.com/en/rest/reference/git#trees """ + def _initAttributes(self) -> None: + self._sha: Attribute[str] = NotSet + self._tree: Attribute[list[GitTreeElement]] = NotSet + self._url: Attribute[str] = NotSet + def __repr__(self): return self.get__repr__({"sha": self._sha.value}) @property - def sha(self): - """ - :type: string - """ + def sha(self) -> str: self._completeIfNotSet(self._sha) return self._sha.value @property - def tree(self): - """ - :type: list of :class:`github.GitTreeElement.GitTreeElement` - """ + def tree(self) -> list[GitTreeElement]: self._completeIfNotSet(self._tree) return self._tree.value @property - def url(self): - """ - :type: string - """ + def url(self) -> str: self._completeIfNotSet(self._url) return self._url.value @property - def _identity(self): + def _identity(self) -> str: return self.sha - def _initAttributes(self): - self._sha = github.GithubObject.NotSet - self._tree = github.GithubObject.NotSet - self._url = github.GithubObject.NotSet - - def _useAttributes(self, attributes): + def _useAttributes(self, attributes) -> 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/GitTree.pyi b/github/GitTree.pyi deleted file mode 100644 index 520f9232..00000000 --- a/github/GitTree.pyi +++ /dev/null @@ -1,17 +0,0 @@ -from typing import Any, Dict, List - -from github.GithubObject import CompletableGithubObject -from github.GitTreeElement import GitTreeElement - -class GitTree(CompletableGithubObject): - def __repr__(self) -> str: ... - @property - def _identity(self) -> str: ... - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: Dict[str, Any]) -> None: ... - @property - def sha(self) -> str: ... - @property - def tree(self) -> List[GitTreeElement]: ... - @property - def url(self) -> str: ... diff --git a/github/GitTreeElement.py b/github/GitTreeElement.py index 9da5e033..3185b314 100644 --- a/github/GitTreeElement.py +++ b/github/GitTreeElement.py @@ -28,68 +28,50 @@ # # ################################################################################ -import github.GithubObject +from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet -class GitTreeElement(github.GithubObject.NonCompletableGithubObject): +class GitTreeElement(NonCompletableGithubObject): """ This class represents GitTreeElements """ + def _initAttributes(self) -> None: + self._mode: Attribute[str] = NotSet + self._path: Attribute[str] = NotSet + self._sha: Attribute[str] = NotSet + self._size: Attribute[int] = NotSet + self._type: Attribute[str] = NotSet + self._url: Attribute[str] = NotSet + def __repr__(self): return self.get__repr__({"sha": self._sha.value, "path": self._path.value}) @property - def mode(self): - """ - :type: string - """ + def mode(self) -> str: return self._mode.value @property - def path(self): - """ - :type: string - """ + def path(self) -> str: return self._path.value @property - def sha(self): - """ - :type: string - """ + def sha(self) -> str: return self._sha.value @property - def size(self): - """ - :type: integer - """ + def size(self) -> int: return self._size.value @property - def type(self): - """ - :type: string - """ + def type(self) -> str: return self._type.value @property - def url(self): - """ - :type: string - """ + def url(self) -> str: return self._url.value - def _initAttributes(self): - self._mode = github.GithubObject.NotSet - self._path = github.GithubObject.NotSet - self._sha = github.GithubObject.NotSet - self._size = github.GithubObject.NotSet - self._type = github.GithubObject.NotSet - self._url = github.GithubObject.NotSet - - def _useAttributes(self, attributes): + def _useAttributes(self, attributes) -> 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/GitTreeElement.pyi b/github/GitTreeElement.pyi deleted file mode 100644 index 52221a76..00000000 --- a/github/GitTreeElement.pyi +++ /dev/null @@ -1,20 +0,0 @@ -from typing import Any, Dict, Optional - -from github.GithubObject import NonCompletableGithubObject - -class GitTreeElement(NonCompletableGithubObject): - def __repr__(self) -> str: ... - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: Dict[str, Any]) -> None: ... - @property - def mode(self) -> str: ... - @property - def path(self) -> str: ... - @property - def sha(self) -> str: ... - @property - def size(self) -> Optional[int]: ... - @property - def type(self) -> str: ... - @property - def url(self) -> str: ... diff --git a/github/GithubObject.py b/github/GithubObject.py index 2717cde2..6233e591 100644 --- a/github/GithubObject.py +++ b/github/GithubObject.py @@ -63,6 +63,7 @@ if TYPE_CHECKING: from .Requester import Requester T = typing.TypeVar("T") +K = typing.TypeVar("K") T_co = typing.TypeVar("T_co", covariant=True) @@ -216,8 +217,8 @@ class GithubObject: @staticmethod def __makeTransformedAttribute( - value: T, type: Type[T], transform: Callable[[T], Any] - ) -> Attribute[T]: + value: T, type: Type[T], transform: Callable[[T], K] + ) -> Attribute[K]: if value is None: return _ValuedAttribute(None) # type: ignore elif isinstance(value, type): @@ -249,7 +250,7 @@ class GithubObject: return GithubObject.__makeSimpleAttribute(value, dict) @staticmethod - def _makeTimestampAttribute(value: int) -> Attribute[int]: + def _makeTimestampAttribute(value: int) -> Attribute[datetime]: return GithubObject.__makeTransformedAttribute( value, int, @@ -257,8 +258,8 @@ class GithubObject: ) @staticmethod - def _makeDatetimeAttribute(value: Optional[Union[int, str]]) -> Attribute: - return GithubObject.__makeTransformedAttribute(value, str, parser.parse) + def _makeDatetimeAttribute(value: Optional[str]) -> Attribute[datetime]: + return GithubObject.__makeTransformedAttribute(value, str, parser.parse) # type: ignore def _makeClassAttribute(self, klass: Any, value: Any) -> Attribute: return GithubObject.__makeTransformedAttribute( @@ -358,10 +359,10 @@ class GithubObject: params=", ".join(list(format_params(params))), ) - def _initAttributes(self): + def _initAttributes(self) -> None: raise NotImplementedError("BUG: Not Implemented _initAttributes") - def _useAttributes(self, attributes): + def _useAttributes(self, attributes) -> None: raise NotImplementedError("BUG: Not Implemented _useAttributes") def _completeIfNeeded(self): diff --git a/github/GitignoreTemplate.py b/github/GitignoreTemplate.py index 2f6cc237..951f611c 100644 --- a/github/GitignoreTemplate.py +++ b/github/GitignoreTemplate.py @@ -27,36 +27,30 @@ # # ################################################################################ -import github.GithubObject +from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet -class GitignoreTemplate(github.GithubObject.NonCompletableGithubObject): +class GitignoreTemplate(NonCompletableGithubObject): """ This class represents GitignoreTemplates. The reference can be found here https://docs.github.com/en/rest/reference/gitignore """ + def _initAttributes(self) -> None: + self._source: Attribute[str] = NotSet + self._name: Attribute[str] = NotSet + def __repr__(self): return self.get__repr__({"name": self._name.value}) @property - def source(self): - """ - :type: string - """ + def source(self) -> str: return self._source.value @property - def name(self): - """ - :type: string - """ + def name(self) -> str: return self._name.value - def _initAttributes(self): - self._source = github.GithubObject.NotSet - self._name = github.GithubObject.NotSet - - def _useAttributes(self, attributes): + def _useAttributes(self, attributes) -> 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/GitignoreTemplate.pyi b/github/GitignoreTemplate.pyi deleted file mode 100644 index f7f8a748..00000000 --- a/github/GitignoreTemplate.pyi +++ /dev/null @@ -1,12 +0,0 @@ -from typing import Any, Dict - -from github.GithubObject import NonCompletableGithubObject - -class GitignoreTemplate(NonCompletableGithubObject): - def __repr__(self) -> str: ... - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: Dict[str, Any]) -> None: ... - @property - def name(self) -> str: ... - @property - def source(self) -> str: ... diff --git a/github/HookDelivery.py b/github/HookDelivery.py index da1d028b..b3625e64 100644 --- a/github/HookDelivery.py +++ b/github/HookDelivery.py @@ -39,93 +39,6 @@ class HookDeliverySummary(github.GithubObject.NonCompletableGithubObject): This class represents a Summary of HookDeliveries """ - def __repr__(self) -> str: - return self.get__repr__({"id": self._id.value}) - - @property - def id(self) -> Optional[int]: - """ - :type: integer - """ - return self._id.value - - @property - def guid(self) -> Optional[str]: - """ - :type: string - """ - return self._guid.value - - @property - def delivered_at(self) -> Optional[datetime]: - """ - :type: datetime - """ - return self._delivered_at.value - - @property - def redelivery(self) -> Optional[bool]: - """ - :type: boolean - """ - return self._redelivery.value - - @property - def duration(self) -> Optional[float]: - """ - :type: float - """ - return self._duration.value - - @property - def status(self) -> Optional[str]: - """ - :type: string - """ - return self._status.value - - @property - def status_code(self) -> Optional[int]: - """ - :type: integer - """ - return self._status_code.value - - @property - def event(self) -> Optional[str]: - """ - :type: string - """ - return self._event.value - - @property - def action(self) -> Optional[str]: - """ - :type: string - """ - return self._action.value - - @property - def installation_id(self) -> Optional[int]: - """ - :type: integer - """ - return self._installation_id.value - - @property - def repository_id(self) -> Optional[int]: - """ - :type: integer - """ - return self._repository_id.value - - @property - def url(self) -> Optional[str]: - """ - :type: string - """ - return self._url.value - def _initAttributes(self) -> None: self._id: Attribute[int] = NotSet self._guid: Attribute[str] = NotSet @@ -140,6 +53,57 @@ class HookDeliverySummary(github.GithubObject.NonCompletableGithubObject): self._repository_id: Attribute[int] = NotSet self._url: Attribute[str] = NotSet + def __repr__(self) -> str: + return self.get__repr__({"id": self._id.value}) + + @property + def id(self) -> Optional[int]: + return self._id.value + + @property + def guid(self) -> Optional[str]: + return self._guid.value + + @property + def delivered_at(self) -> Optional[datetime]: + return self._delivered_at.value + + @property + def redelivery(self) -> Optional[bool]: + return self._redelivery.value + + @property + def duration(self) -> Optional[float]: + return self._duration.value + + @property + def status(self) -> Optional[str]: + return self._status.value + + @property + def status_code(self) -> Optional[int]: + return self._status_code.value + + @property + def event(self) -> Optional[str]: + return self._event.value + + @property + def action(self) -> Optional[str]: + return self._action.value + + @property + def installation_id(self) -> Optional[int]: + return self._installation_id.value + + @property + def repository_id(self) -> Optional[int]: + return self._repository_id.value + + @property + def url(self) -> Optional[str]: + return self._url.value + def _useAttributes(self, attributes: Dict[str, Any]): if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) @@ -174,27 +138,21 @@ class HookDeliveryRequest(github.GithubObject.NonCompletableGithubObject): This class represents a HookDeliveryRequest """ + def _initAttributes(self) -> None: + self._request_headers: Attribute[Dict] = NotSet + self._payload: Attribute[Dict] = NotSet + def __repr__(self) -> str: return self.get__repr__({"payload": self._payload.value}) @property def headers(self) -> Optional[dict]: - """ - :type: dict - """ return self._request_headers.value @property def payload(self) -> Optional[dict]: - """ - :type: dict - """ return self._payload.value - def _initAttributes(self) -> None: - self._request_headers: Attribute[Dict] = NotSet - self._payload: Attribute[Dict] = NotSet - def _useAttributes(self, attributes: Dict[str, Any]) -> None: if "headers" in attributes: # pragma no branch self._request_headers = self._makeDictAttribute(attributes["headers"]) @@ -212,16 +170,10 @@ class HookDeliveryResponse(github.GithubObject.NonCompletableGithubObject): @property def headers(self) -> Optional[dict]: - """ - :type: dict - """ return self._response_headers.value @property def payload(self) -> Optional[str]: - """ - :type: str - """ return self._payload.value def _initAttributes(self) -> None: @@ -240,28 +192,22 @@ class HookDelivery(HookDeliverySummary): This class represents a HookDelivery """ + def _initAttributes(self) -> None: + super()._initAttributes() + self._request: Attribute[HookDeliveryRequest] = NotSet + self._response: Attribute[HookDeliveryResponse] = NotSet + def __repr__(self) -> str: return self.get__repr__({"id": self._id.value}) @property def request(self) -> Optional[HookDeliveryRequest]: - """ - :type: :class:`HookDeliveryRequest` - """ return self._request.value @property def response(self) -> Optional[HookDeliveryResponse]: - """ - :type: :class:`HookDeliveryResponse` - """ return self._response.value - def _initAttributes(self) -> None: - super()._initAttributes() - self._request: Attribute[HookDeliveryRequest] = NotSet - self._response: Attribute[HookDeliveryResponse] = NotSet - def _useAttributes(self, attributes: Dict[str, Any]) -> None: super()._useAttributes(attributes) if "request" in attributes: # pragma no branch diff --git a/github/HookDescription.py b/github/HookDescription.py index 44ec8af4..f3da40cb 100644 --- a/github/HookDescription.py +++ b/github/HookDescription.py @@ -27,53 +27,42 @@ # along with PyGithub. If not, see . # # # ################################################################################ +from __future__ import annotations -import github.GithubObject +from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet -class HookDescription(github.GithubObject.NonCompletableGithubObject): +class HookDescription(NonCompletableGithubObject): """ This class represents HookDescriptions """ + def _initAttributes(self) -> None: + self._events: Attribute[list[str]] = NotSet + self._name: Attribute[str] = NotSet + self._schema: Attribute[list[list[str]]] = NotSet + self._supported_events: Attribute[list[str]] = NotSet + def __repr__(self): return self.get__repr__({"name": self._name.value}) @property - def events(self): - """ - :type: list of string - """ + def events(self) -> list[str]: return self._events.value @property - def name(self): - """ - :type: string - """ + def name(self) -> str: return self._name.value @property - def schema(self): - """ - :type: list of list of string - """ + def schema(self) -> list[list[str]]: return self._schema.value @property - def supported_events(self): - """ - :type: list of string - """ + def supported_events(self) -> list[str]: return self._supported_events.value - def _initAttributes(self): - self._events = github.GithubObject.NotSet - self._name = github.GithubObject.NotSet - self._schema = github.GithubObject.NotSet - self._supported_events = github.GithubObject.NotSet - - def _useAttributes(self, attributes): + def _useAttributes(self, attributes) -> 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/HookDescription.pyi b/github/HookDescription.pyi deleted file mode 100644 index 4cd559f0..00000000 --- a/github/HookDescription.pyi +++ /dev/null @@ -1,16 +0,0 @@ -from typing import Any, Dict, List - -from github.GithubObject import NonCompletableGithubObject - -class HookDescription(NonCompletableGithubObject): - def __repr__(self) -> str: ... - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: Dict[str, Any]) -> None: ... - @property - def events(self) -> List[str]: ... - @property - def name(self) -> str: ... - @property - def schema(self) -> List[List[str]]: ... - @property - def supported_events(self) -> List[str]: ... diff --git a/github/HookResponse.py b/github/HookResponse.py index a491ef30..27eb449a 100644 --- a/github/HookResponse.py +++ b/github/HookResponse.py @@ -28,44 +28,35 @@ # # ################################################################################ -import github.GithubObject +from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet -class HookResponse(github.GithubObject.NonCompletableGithubObject): +class HookResponse(NonCompletableGithubObject): """ This class represents HookResponses """ + def _initAttributes(self) -> None: + self._code: Attribute[int] = NotSet + self._message: Attribute[str] = NotSet + self._status: Attribute[str] = NotSet + def __repr__(self): return self.get__repr__({"status": self._status.value}) @property - def code(self): - """ - :type: integer - """ + def code(self) -> int: return self._code.value @property - def message(self): - """ - :type: string - """ + def message(self) -> str: return self._message.value @property - def status(self): - """ - :type: string - """ + def status(self) -> str: return self._status.value - def _initAttributes(self): - self._code = github.GithubObject.NotSet - self._message = github.GithubObject.NotSet - self._status = github.GithubObject.NotSet - - def _useAttributes(self, attributes): + def _useAttributes(self, attributes) -> 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/HookResponse.pyi b/github/HookResponse.pyi deleted file mode 100644 index fe04da17..00000000 --- a/github/HookResponse.pyi +++ /dev/null @@ -1,14 +0,0 @@ -from typing import Any, Dict - -from github.GithubObject import NonCompletableGithubObject - -class HookResponse(NonCompletableGithubObject): - def __repr__(self) -> str: ... - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: Dict[str, Any]) -> None: ... - @property - def code(self) -> int: ... - @property - def message(self) -> str: ... - @property - def status(self) -> str: ... diff --git a/github/InputFileContent.py b/github/InputFileContent.py index 3289d187..1fd8e97b 100644 --- a/github/InputFileContent.py +++ b/github/InputFileContent.py @@ -26,7 +26,12 @@ # # ################################################################################ -import github.GithubObject + +from __future__ import annotations + +from typing import Any + +from github.GithubObject import NotSet, Opt, is_defined, is_optional class InputFileContent: @@ -34,24 +39,17 @@ class InputFileContent: This class represents InputFileContents """ - def __init__(self, content, new_name=github.GithubObject.NotSet): - """ - :param content: string - :param new_name: string - """ - + def __init__(self, content: str, new_name: Opt[str] = NotSet): assert isinstance(content, str), content - assert new_name is github.GithubObject.NotSet or isinstance( - new_name, str - ), new_name - self.__newName = new_name - self.__content = content + assert is_optional(new_name, str), new_name + self.__newName: Opt[str] = new_name + self.__content: str = content @property - def _identity(self): - identity = { + def _identity(self) -> dict[str, str]: + identity: dict[str, Any] = { "content": self.__content, } - if self.__newName is not github.GithubObject.NotSet: + if is_defined(self.__newName): identity["filename"] = self.__newName return identity diff --git a/github/InputFileContent.pyi b/github/InputFileContent.pyi deleted file mode 100644 index 8a71faff..00000000 --- a/github/InputFileContent.pyi +++ /dev/null @@ -1,10 +0,0 @@ -from typing import Dict, Union - -from github.GithubObject import _NotSetType - -class InputFileContent: - def __init__( - self, content: str, new_name: Union[str, _NotSetType] = ... - ) -> None: ... - @property - def _identity(self) -> Dict[str, str]: ... diff --git a/github/InputGitAuthor.py b/github/InputGitAuthor.py index b53fd46d..355f7153 100644 --- a/github/InputGitAuthor.py +++ b/github/InputGitAuthor.py @@ -28,7 +28,11 @@ # # ################################################################################ -import github.GithubObject +from __future__ import annotations + +from typing import Any + +from github.GithubObject import NotSet, Opt, is_defined, is_optional class InputGitAuthor: @@ -36,32 +40,24 @@ class InputGitAuthor: This class represents InputGitAuthors """ - def __init__(self, name, email, date=github.GithubObject.NotSet): - """ - :param name: string - :param email: string - :param date: string - """ - + def __init__(self, name: str, email: str, date: Opt[str] = NotSet): assert isinstance(name, str), name assert isinstance(email, str), email - assert date is github.GithubObject.NotSet or isinstance( - date, str - ), date # @todo Datetime? + assert is_optional(date, str), date # @todo Datetime? - self.__name = name - self.__email = email - self.__date = date + self.__name: str = name + self.__email: str = email + self.__date: Opt[str] = date def __repr__(self): return f'InputGitAuthor(name="{self.__name}")' @property - def _identity(self): - identity = { + def _identity(self) -> dict[str, str]: + identity: dict[str, Any] = { "name": self.__name, "email": self.__email, } - if self.__date is not github.GithubObject.NotSet: + if is_defined(self.__date): identity["date"] = self.__date return identity diff --git a/github/InputGitAuthor.pyi b/github/InputGitAuthor.pyi deleted file mode 100644 index ab812fa0..00000000 --- a/github/InputGitAuthor.pyi +++ /dev/null @@ -1,10 +0,0 @@ -from typing import Dict, Union - -from github.GithubObject import _NotSetType - -class InputGitAuthor: - def __init__( - self, name: str, email: str, date: Union[str, _NotSetType] = ... - ) -> None: ... - @property - def _identity(self) -> Dict[str, str]: ... diff --git a/github/InputGitTreeElement.py b/github/InputGitTreeElement.py index 909250c5..a9561943 100644 --- a/github/InputGitTreeElement.py +++ b/github/InputGitTreeElement.py @@ -25,8 +25,11 @@ # along with PyGithub. If not, see . # # # ################################################################################ +from __future__ import annotations -import github.GithubObject +from typing import Any + +from github.GithubObject import NotSet, Opt, is_defined, is_optional class InputGitTreeElement: @@ -36,44 +39,32 @@ class InputGitTreeElement: def __init__( self, - path, - mode, - type, - content=github.GithubObject.NotSet, - sha=github.GithubObject.NotSet, + path: str, + mode: str, + type: str, + content: Opt[str] = NotSet, + sha: Opt[str | None] = NotSet, ): - """ - :param path: string - :param mode: string - :param type: string - :param content: string - :param sha: string or None - """ - assert isinstance(path, str), path assert isinstance(mode, str), mode assert isinstance(type, str), type - assert content is github.GithubObject.NotSet or isinstance( - content, str - ), content - assert ( - sha is github.GithubObject.NotSet or sha is None or isinstance(sha, str) - ), sha + assert is_optional(content, str), content + assert sha is None or is_optional(sha, str), sha self.__path = path self.__mode = mode self.__type = type self.__content = content - self.__sha = sha + self.__sha: Opt[str] | None = sha @property - def _identity(self): - identity = { + def _identity(self) -> dict[str, Any]: + identity: dict[str, Any] = { "path": self.__path, "mode": self.__mode, "type": self.__type, } - if self.__sha is not github.GithubObject.NotSet: + if is_defined(self.__sha): identity["sha"] = self.__sha - if self.__content is not github.GithubObject.NotSet: + if is_defined(self.__content): identity["content"] = self.__content return identity diff --git a/github/InputGitTreeElement.pyi b/github/InputGitTreeElement.pyi deleted file mode 100644 index ad621e23..00000000 --- a/github/InputGitTreeElement.pyi +++ /dev/null @@ -1,15 +0,0 @@ -from typing import Dict, Union - -from github.GithubObject import _NotSetType - -class InputGitTreeElement: - def __init__( - self, - path: str, - mode: str, - type: str, - content: Union[str, _NotSetType] = ..., - sha: Union[str, _NotSetType, None] = ..., - ) -> None: ... - @property - def _identity(self) -> Dict[str, str]: ...