@@ -95,15 +95,13 @@ jobs: | |||
| 95 | 95 | continue-on-error: true | |
| 96 | 96 | ||
| 97 | 97 | - name: Check types with mypy | |
| 98 | + if: matrix.python-version != '3.7' && matrix.python-version != '3.8' | ||
| 98 | 99 | run: | | |
| 99 | 100 | mypy --python-version="${PYTHON_VERSION%t}" # Version only, with no "t" for free-threaded. | |
| 100 | 101 | env: | |
| 101 | 102 | MYPY_FORCE_COLOR: "1" | |
| 102 | 103 | TERM: "xterm-256color" # For color: https://github.com/python/mypy/issues/13817 | |
| 103 | 104 | PYTHON_VERSION: ${{ matrix.python-version }} | |
| 104 | - # With new versions of mypy new issues might arise. This is a problem if there is | ||
| 105 | - # nobody able to fix them, so we have to ignore errors until that changes. | ||
| 106 | - continue-on-error: true | ||
| 107 | 105 | ||
| 108 | 106 | - name: Test with pytest | |
| 109 | 107 | run: | | |
@@ -574,7 +574,7 @@ def _included_paths(self) -> List[Tuple[str, str]]: | |||
| 574 | 574 | if keyword.endswith("/i"): | |
| 575 | 575 | value = re.sub( | |
| 576 | 576 | r"[a-zA-Z]", | |
| 577 | - lambda m: "[{}{}]".format(m.group().lower(), m.group().upper()), | ||
| 577 | + lambda m: f"[{m.group().lower()!r}{m.group().upper()!r}]", | ||
| 578 | 578 | value, | |
| 579 | 579 | ) | |
| 580 | 580 | if self._repo.git_dir: | |
@@ -633,8 +633,6 @@ def read(self) -> None: # type: ignore[override] | |||
| 633 | 633 | file_path = cast(IO[bytes], file_path) | |
| 634 | 634 | self._read(file_path, file_path.name) | |
| 635 | 635 | else: | |
| 636 | - # Assume a path if it is not a file-object. | ||
| 637 | - file_path = os.fspath(file_path) | ||
| 638 | 636 | try: | |
| 639 | 637 | with open(file_path, "rb") as fp: | |
| 640 | 638 | file_ok = True | |
@@ -768,7 +766,7 @@ def _assure_writable(self, method_name: str) -> None: | |||
| 768 | 766 | if self.read_only: | |
| 769 | 767 | raise IOError("Cannot execute non-constant method %s.%s" % (self, method_name)) | |
| 770 | 768 | ||
| 771 | - def add_section(self, section: str) -> None: | ||
| 769 | + def add_section(self, section: "cp._SectionName") -> None: | ||
| 772 | 770 | """Assures added options will stay in order.""" | |
| 773 | 771 | return super().add_section(section) | |
| 774 | 772 | ||
@@ -23,13 +23,14 @@ | |||
| 23 | 23 | List, | |
| 24 | 24 | Match, | |
| 25 | 25 | Optional, | |
| 26 | + Sequence, | ||
| 26 | 27 | Tuple, | |
| 27 | 28 | TYPE_CHECKING, | |
| 28 | 29 | TypeVar, | |
| 29 | 30 | Union, | |
| 30 | 31 | cast, | |
| 31 | 32 | ) | |
| 32 | - from git.types import Literal, PathLike | ||
| 33 | + from git.types import PathLike, Literal | ||
| 33 | 34 | ||
| 34 | 35 | if TYPE_CHECKING: | |
| 35 | 36 | from subprocess import Popen | |
@@ -289,7 +290,7 @@ class DiffIndex(List[T_Diff]): | |||
| 289 | 290 | The class improves the diff handling convenience. | |
| 290 | 291 | """ | |
| 291 | 292 | ||
| 292 | - change_type = ("A", "C", "D", "R", "M", "T") | ||
| 293 | + change_type: Sequence[Literal["A", "C", "D", "R", "M", "T"]] = ("A", "C", "D", "R", "M", "T") # noqa: F821 | ||
| 293 | 294 | """Change type invariant identifying possible ways a blob can have changed: | |
| 294 | 295 | ||
| 295 | 296 | * ``A`` = Added | |
@@ -192,7 +192,7 @@ def from_base(cls, base: "BaseIndexEntry") -> "IndexEntry": | |||
| 192 | 192 | Instance of type :class:`BaseIndexEntry`. | |
| 193 | 193 | """ | |
| 194 | 194 | time = pack(">LL", 0, 0) | |
| 195 | - return IndexEntry((base.mode, base.binsha, base.flags, base.path, time, time, 0, 0, 0, 0, 0)) | ||
| 195 | + return IndexEntry((base.mode, base.binsha, base.flags, base.path, time, time, 0, 0, 0, 0, 0)) # type: ignore[arg-type] | ||
| 196 | 196 | ||
| 197 | 197 | @classmethod | |
| 198 | 198 | def from_blob(cls, blob: Blob, stage: int = 0) -> "IndexEntry": | |
@@ -211,5 +211,5 @@ def from_blob(cls, blob: Blob, stage: int = 0) -> "IndexEntry": | |||
| 211 | 211 | 0, | |
| 212 | 212 | 0, | |
| 213 | 213 | blob.size, | |
| 214 | - ) | ||
| 214 | + ) # type: ignore[arg-type] | ||
| 215 | 215 | ) | |
@@ -900,7 +900,7 @@ def co_authors(self) -> List[Actor]: | |||
| 900 | 900 | if self.message: | |
| 901 | 901 | results = re.findall( | |
| 902 | 902 | r"^Co-authored-by: (.*) <(.*?)>$", | |
| 903 | - self.message, | ||
| 903 | + str(self.message), | ||
| 904 | 904 | re.MULTILINE, | |
| 905 | 905 | ) | |
| 906 | 906 | for author in results: | |
@@ -66,7 +66,7 @@ | |||
| 66 | 66 | if TYPE_CHECKING: | |
| 67 | 67 | from git.index import IndexFile | |
| 68 | 68 | from git.objects.commit import Commit | |
| 69 | - from git.refs import Head | ||
| 69 | + from git.refs import Head, RemoteReference | ||
| 70 | 70 | from git.repo import Repo | |
| 71 | 71 | ||
| 72 | 72 | # ----------------------------------------------------------------------------- | |
@@ -355,7 +355,7 @@ def _clone_repo( | |||
| 355 | 355 | module_checkout_path = osp.join(os.fspath(repo.working_tree_dir), path) | |
| 356 | 356 | ||
| 357 | 357 | if url.startswith("../"): | |
| 358 | - remote_name = repo.active_branch.tracking_branch().remote_name | ||
| 358 | + remote_name = cast("RemoteReference", repo.active_branch.tracking_branch()).remote_name | ||
| 359 | 359 | repo_remote_url = repo.remote(remote_name).url | |
| 360 | 360 | url = os.path.join(repo_remote_url, url) | |
| 361 | 361 | ||
@@ -23,7 +23,6 @@ | |||
| 23 | 23 | from git.types import Commit_ish, PathLike | |
| 24 | 24 | ||
| 25 | 25 | if TYPE_CHECKING: | |
| 26 | - from git.objects import Commit | ||
| 27 | 26 | from git.refs import RemoteReference | |
| 28 | 27 | from git.repo import Repo | |
| 29 | 28 | ||
@@ -45,9 +44,6 @@ class HEAD(SymbolicReference): | |||
| 45 | 44 | ||
| 46 | 45 | __slots__ = () | |
| 47 | 46 | ||
| 48 | - # TODO: This can be removed once SymbolicReference.commit has static type hints. | ||
| 49 | - commit: "Commit" | ||
| 50 | - | ||
| 51 | 47 | def __init__(self, repo: "Repo", path: PathLike = _HEAD_NAME) -> None: | |
| 52 | 48 | path = os.fspath(path) | |
| 53 | 49 | if path != self._HEAD_NAME: | |
@@ -151,7 +147,7 @@ class Head(Reference): | |||
| 151 | 147 | k_config_remote_ref = "merge" # Branch to merge from remote. | |
| 152 | 148 | ||
| 153 | 149 | @classmethod | |
| 154 | - def delete(cls, repo: "Repo", *heads: "Union[Head, str]", force: bool = False, **kwargs: Any) -> None: | ||
| 150 | + def delete(cls, repo: "Repo", *heads: "Union[Head, str]", force: bool = False, **kwargs: Any) -> None: # type: ignore[override] | ||
| 155 | 151 | """Delete the given heads. | |
| 156 | 152 | ||
| 157 | 153 | :param force: | |
@@ -146,7 +146,7 @@ def from_line(cls, line: bytes) -> "RefLogEntry": | |||
| 146 | 146 | actor = Actor._from_string(info[82 : email_end + 1]) | |
| 147 | 147 | time, tz_offset = parse_date(info[email_end + 2 :]) # skipcq: PYL-W0621 | |
| 148 | 148 | ||
| 149 | - return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), msg)) | ||
| 149 | + return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), msg)) # type: ignore [arg-type] | ||
| 150 | 150 | ||
| 151 | 151 | ||
| 152 | 152 | class RefLog(List[RefLogEntry], Serializable): | |
@@ -916,8 +916,7 @@ def from_path(cls: Type[T_References], repo: "Repo", path: PathLike) -> T_Refere | |||
| 916 | 916 | SymbolicReference, | |
| 917 | 917 | ): | |
| 918 | 918 | try: | |
| 919 | - instance: T_References | ||
| 920 | - instance = ref_type(repo, path) | ||
| 919 | + instance = cast(T_References, ref_type(repo, path)) | ||
| 921 | 920 | if instance.__class__ is SymbolicReference and instance.is_detached: | |
| 922 | 921 | raise ValueError("SymbolicRef was detached, we drop it") | |
| 923 | 922 | else: | |
@@ -45,8 +45,8 @@ class TagReference(Reference): | |||
| 45 | 45 | _common_default = "tags" | |
| 46 | 46 | _common_path_default = Reference._common_path_default + "/" + _common_default | |
| 47 | 47 | ||
| 48 | - @property | ||
| 49 | - def commit(self) -> "Commit": # type: ignore[override] # LazyMixin has unrelated commit method | ||
| 48 | + @property # type: ignore[misc] | ||
| 49 | + def commit(self) -> "Commit": # LazyMixin has unrelated commit method | ||
| 50 | 50 | """:return: Commit object the tag ref points to | |
| 51 | 51 | ||
| 52 | 52 | :raise ValueError: | |
@@ -80,8 +80,8 @@ def tag(self) -> Union["TagObject", None]: | |||
| 80 | 80 | return None | |
| 81 | 81 | ||
| 82 | 82 | # Make object read-only. It should be reasonably hard to adjust an existing tag. | |
| 83 | - @property | ||
| 84 | - def object(self) -> AnyGitObject: # type: ignore[override] | ||
| 83 | + @property # type: ignore[misc] | ||
| 84 | + def object(self) -> AnyGitObject: | ||
| 85 | 85 | return Reference._get_object(self) | |
| 86 | 86 | ||
| 87 | 87 | @classmethod | |
0 commit comments