diff --git a/github/ContentFile.py b/github/ContentFile.py index 72a3cf37..b20e9f63 100644 --- a/github/ContentFile.py +++ b/github/ContentFile.py @@ -28,163 +28,125 @@ # along with PyGithub. If not, see . # # # ################################################################################ +from __future__ import annotations import base64 -from typing import Any, Dict +from typing import TYPE_CHECKING, Any import github.GithubObject import github.Repository +from github.GithubObject import Attribute, CompletableGithubObject, NotSet, _ValuedAttribute + +if TYPE_CHECKING: + from github.License import License + from github.Repository import Repository -class ContentFile(github.GithubObject.CompletableGithubObject): +class ContentFile(CompletableGithubObject): """ This class represents ContentFiles. The reference can be found here https://docs.github.com/en/rest/reference/repos#contents """ + def _initAttributes(self) -> None: + self._content: Attribute[str] = NotSet + self._download_url: Attribute[str] = NotSet + self._encoding: Attribute[str] = NotSet + self._git_url: Attribute[str] = NotSet + self._html_url: Attribute[str] = NotSet + self._license: Attribute[License] = NotSet + self._name: Attribute[str] = NotSet + self._path: Attribute[str] = NotSet + self._repository: Attribute[Repository] = NotSet + self._sha: Attribute[str] = NotSet + self._size: Attribute[int] = NotSet + self._type: Attribute[str] = NotSet + self._url: Attribute[str] = NotSet + self._text_matches: Attribute[str] = NotSet + def __repr__(self) -> str: return self.get__repr__({"path": self._path.value}) @property - def content(self): - """ - :type: string - """ + def content(self) -> str: self._completeIfNotSet(self._content) return self._content.value @property - def decoded_content(self): - """ - :type: bytes - """ + def decoded_content(self) -> bytes: assert self.encoding == "base64", f"unsupported encoding: {self.encoding}" return base64.b64decode(bytearray(self.content, "utf-8")) @property - def download_url(self): - """ - :type: string - """ + def download_url(self) -> str: self._completeIfNotSet(self._download_url) return self._download_url.value @property - def encoding(self): - """ - :type: string - """ + def encoding(self) -> str: self._completeIfNotSet(self._encoding) return self._encoding.value @property - def git_url(self): - """ - :type: string - """ + def git_url(self) -> str: self._completeIfNotSet(self._git_url) return self._git_url.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 license(self): - """ - :type: :class:`github.License.License` - """ + def license(self) -> License: self._completeIfNotSet(self._license) return self._license.value @property - def name(self): - """ - :type: string - """ + def name(self) -> str: self._completeIfNotSet(self._name) return self._name.value @property - def path(self): - """ - :type: string - """ + def path(self) -> str: self._completeIfNotSet(self._path) return self._path.value @property - def repository(self): - """ - :type: :class:`github.Repository.Repository` - """ - if self._repository is github.GithubObject.NotSet: + def repository(self) -> Repository: + if self._repository is NotSet: # The repository was not set automatically, so it must be looked up by url. repo_url = "/".join(self.url.split("/")[:6]) # pragma no cover (Should be covered) - self._repository = github.GithubObject._ValuedAttribute( + self._repository = _ValuedAttribute( github.Repository.Repository(self._requester, self._headers, {"url": repo_url}, completed=False) ) # pragma no cover (Should be covered) return self._repository.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 type(self): - """ - :type: string - """ + def type(self) -> str: self._completeIfNotSet(self._type) return self._type.value @property - def url(self): - """ - :type: string - """ + def url(self) -> str: self._completeIfNotSet(self._url) return self._url.value @property - def text_matches(self): - """ - :type: string - """ + def text_matches(self) -> str: self._completeIfNotSet(self._text_matches) return self._text_matches.value - def _initAttributes(self) -> None: - self._content = github.GithubObject.NotSet - self._text_matches = github.GithubObject.NotSet - self._encoding = github.GithubObject.NotSet - self._download_url = github.GithubObject.NotSet - self._git_url = github.GithubObject.NotSet - self._html_url = github.GithubObject.NotSet - self._license = github.GithubObject.NotSet - self._name = github.GithubObject.NotSet - self._path = github.GithubObject.NotSet - self._repository = github.GithubObject.NotSet - self._sha = github.GithubObject.NotSet - self._size = github.GithubObject.NotSet - self._type = github.GithubObject.NotSet - - def _useAttributes(self, attributes: Dict[str, Any]) -> None: + 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/ContentFile.pyi b/github/ContentFile.pyi deleted file mode 100644 index 7f2f6c08..00000000 --- a/github/ContentFile.pyi +++ /dev/null @@ -1,40 +0,0 @@ -from typing import Any, Dict, List, Optional - -from github.GithubObject import CompletableGithubObject -from github.License import License -from github.Repository import Repository - -class ContentFile(CompletableGithubObject): - def __repr__(self) -> str: ... - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: Dict[str, Any]) -> None: ... - @property - def content(self) -> Optional[str]: ... - @property - def decoded_content(self) -> bytes: ... - @property - def download_url(self) -> str: ... - @property - def encoding(self) -> str: ... - @property - def git_url(self) -> str: ... - @property - def html_url(self) -> str: ... - @property - def name(self) -> str: ... - @property - def path(self) -> str: ... - @property - def repository(self) -> Repository: ... - @property - def sha(self) -> str: ... - @property - def size(self) -> int: ... - @property - def text_matches(self) -> List[Dict[str, Any]]: ... - @property - def type(self) -> str: ... - @property - def url(self) -> str: ... - @property - def license(self) -> License: ...