← 返回首页
Merge branch 'main' into true-pathlike · gitpython-developers/GitPython@b5abe0f · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

Commit b5abe0f

Browse files
committed
Merge branch 'main' into true-pathlike
2 parents 921ca8a + 0fcf291 commit b5abe0f

20 files changed

Lines changed: 38 additions & 47 deletions

File tree

‎.github/workflows/pythonpackage.yml‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,13 @@ jobs:
9595
continue-on-error: true
9696

9797
- name: Check types with mypy
98+
if: matrix.python-version != '3.7' && matrix.python-version != '3.8'
9899
run: |
99100
mypy --python-version="${PYTHON_VERSION%t}" # Version only, with no "t" for free-threaded.
100101
env:
101102
MYPY_FORCE_COLOR: "1"
102103
TERM: "xterm-256color" # For color: https://github.com/python/mypy/issues/13817
103104
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
107105

108106
- name: Test with pytest
109107
run: |

‎git/config.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ def _included_paths(self) -> List[Tuple[str, str]]:
574574
if keyword.endswith("/i"):
575575
value = re.sub(
576576
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}]",
578578
value,
579579
)
580580
if self._repo.git_dir:
@@ -633,8 +633,6 @@ def read(self) -> None: # type: ignore[override]
633633
file_path = cast(IO[bytes], file_path)
634634
self._read(file_path, file_path.name)
635635
else:
636-
# Assume a path if it is not a file-object.
637-
file_path = os.fspath(file_path)
638636
try:
639637
with open(file_path, "rb") as fp:
640638
file_ok = True
@@ -768,7 +766,7 @@ def _assure_writable(self, method_name: str) -> None:
768766
if self.read_only:
769767
raise IOError("Cannot execute non-constant method %s.%s" % (self, method_name))
770768

771-
def add_section(self, section: str) -> None:
769+
def add_section(self, section: "cp._SectionName") -> None:
772770
"""Assures added options will stay in order."""
773771
return super().add_section(section)
774772

‎git/diff.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
List,
2424
Match,
2525
Optional,
26+
Sequence,
2627
Tuple,
2728
TYPE_CHECKING,
2829
TypeVar,
2930
Union,
3031
cast,
3132
)
32-
from git.types import Literal, PathLike
33+
from git.types import PathLike, Literal
3334

3435
if TYPE_CHECKING:
3536
from subprocess import Popen
@@ -289,7 +290,7 @@ class DiffIndex(List[T_Diff]):
289290
The class improves the diff handling convenience.
290291
"""
291292

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
293294
"""Change type invariant identifying possible ways a blob can have changed:
294295
295296
* ``A`` = Added

‎git/index/typ.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def from_base(cls, base: "BaseIndexEntry") -> "IndexEntry":
192192
Instance of type :class:`BaseIndexEntry`.
193193
"""
194194
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]
196196

197197
@classmethod
198198
def from_blob(cls, blob: Blob, stage: int = 0) -> "IndexEntry":
@@ -211,5 +211,5 @@ def from_blob(cls, blob: Blob, stage: int = 0) -> "IndexEntry":
211211
0,
212212
0,
213213
blob.size,
214-
)
214+
) # type: ignore[arg-type]
215215
)

‎git/objects/commit.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ def co_authors(self) -> List[Actor]:
900900
if self.message:
901901
results = re.findall(
902902
r"^Co-authored-by: (.*) <(.*?)>$",
903-
self.message,
903+
str(self.message),
904904
re.MULTILINE,
905905
)
906906
for author in results:

‎git/objects/submodule/base.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
if TYPE_CHECKING:
6767
from git.index import IndexFile
6868
from git.objects.commit import Commit
69-
from git.refs import Head
69+
from git.refs import Head, RemoteReference
7070
from git.repo import Repo
7171

7272
# -----------------------------------------------------------------------------
@@ -355,7 +355,7 @@ def _clone_repo(
355355
module_checkout_path = osp.join(os.fspath(repo.working_tree_dir), path)
356356

357357
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
359359
repo_remote_url = repo.remote(remote_name).url
360360
url = os.path.join(repo_remote_url, url)
361361

‎git/refs/head.py‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from git.types import Commit_ish, PathLike
2424

2525
if TYPE_CHECKING:
26-
from git.objects import Commit
2726
from git.refs import RemoteReference
2827
from git.repo import Repo
2928

@@ -45,9 +44,6 @@ class HEAD(SymbolicReference):
4544

4645
__slots__ = ()
4746

48-
# TODO: This can be removed once SymbolicReference.commit has static type hints.
49-
commit: "Commit"
50-
5147
def __init__(self, repo: "Repo", path: PathLike = _HEAD_NAME) -> None:
5248
path = os.fspath(path)
5349
if path != self._HEAD_NAME:
@@ -151,7 +147,7 @@ class Head(Reference):
151147
k_config_remote_ref = "merge" # Branch to merge from remote.
152148

153149
@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]
155151
"""Delete the given heads.
156152
157153
:param force:

‎git/refs/log.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def from_line(cls, line: bytes) -> "RefLogEntry":
146146
actor = Actor._from_string(info[82 : email_end + 1])
147147
time, tz_offset = parse_date(info[email_end + 2 :]) # skipcq: PYL-W0621
148148

149-
return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), msg))
149+
return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), msg)) # type: ignore [arg-type]
150150

151151

152152
class RefLog(List[RefLogEntry], Serializable):

‎git/refs/symbolic.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,8 +916,7 @@ def from_path(cls: Type[T_References], repo: "Repo", path: PathLike) -> T_Refere
916916
SymbolicReference,
917917
):
918918
try:
919-
instance: T_References
920-
instance = ref_type(repo, path)
919+
instance = cast(T_References, ref_type(repo, path))
921920
if instance.__class__ is SymbolicReference and instance.is_detached:
922921
raise ValueError("SymbolicRef was detached, we drop it")
923922
else:

‎git/refs/tag.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class TagReference(Reference):
4545
_common_default = "tags"
4646
_common_path_default = Reference._common_path_default + "/" + _common_default
4747

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
5050
""":return: Commit object the tag ref points to
5151
5252
:raise ValueError:
@@ -80,8 +80,8 @@ def tag(self) -> Union["TagObject", None]:
8080
return None
8181

8282
# 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:
8585
return Reference._get_object(self)
8686

8787
@classmethod

0 commit comments

Comments
 (0)

Footer

© 2026 GitHub, Inc.