Skip to content

Commit bcea9a8

Browse files
authored
Merge pull request gitpython-developers#1859 from EliahKagan/doc-types
Improve static typing and docstrings related to git object types
2 parents 883b03a + 5778b7a commit bcea9a8

38 files changed

+916
-549
lines changed

.github/workflows/pythonpackage.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,12 @@ jobs:
8888

8989
- name: Check types with mypy
9090
run: |
91-
mypy -p git
92-
# With new versions of mypy new issues might arise. This is a problem if there is nobody able to fix them,
93-
# so we have to ignore errors until that changes.
91+
mypy --python-version=${{ matrix.python-version }} -p git
92+
env:
93+
MYPY_FORCE_COLOR: "1"
94+
TERM: "xterm-256color" # For color: https://github.com/python/mypy/issues/13817
95+
# With new versions of mypy new issues might arise. This is a problem if there is
96+
# nobody able to fix them, so we have to ignore errors until that changes.
9497
continue-on-error: true
9598

9699
- name: Test with pytest

git/__init__.py

+40-39
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,6 @@
55

66
# @PydevCodeAnalysisIgnore
77

8-
__version__ = "git"
9-
10-
from typing import List, Optional, Sequence, Tuple, Union, TYPE_CHECKING
11-
12-
from gitdb.util import to_hex_sha
13-
from git.exc import * # noqa: F403 # @NoMove @IgnorePep8
14-
from git.types import PathLike
15-
16-
try:
17-
from git.compat import safe_decode # @NoMove @IgnorePep8
18-
from git.config import GitConfigParser # @NoMove @IgnorePep8
19-
from git.objects import * # noqa: F403 # @NoMove @IgnorePep8
20-
from git.refs import * # noqa: F403 # @NoMove @IgnorePep8
21-
from git.diff import * # noqa: F403 # @NoMove @IgnorePep8
22-
from git.db import * # noqa: F403 # @NoMove @IgnorePep8
23-
from git.cmd import Git # @NoMove @IgnorePep8
24-
from git.repo import Repo # @NoMove @IgnorePep8
25-
from git.remote import * # noqa: F403 # @NoMove @IgnorePep8
26-
from git.index import * # noqa: F403 # @NoMove @IgnorePep8
27-
from git.util import ( # @NoMove @IgnorePep8
28-
LockFile,
29-
BlockingLockFile,
30-
Stats,
31-
Actor,
32-
remove_password_if_present,
33-
rmtree,
34-
)
35-
except GitError as _exc: # noqa: F405
36-
raise ImportError("%s: %s" % (_exc.__class__.__name__, _exc)) from _exc
37-
38-
# __all__ must be statically defined by py.typed support
39-
# __all__ = [name for name, obj in locals().items() if not (name.startswith("_") or inspect.ismodule(obj))]
408
__all__ = [ # noqa: F405
419
"Actor",
4210
"AmbiguousObjectName",
@@ -52,6 +20,7 @@
5220
"CommandError",
5321
"Commit",
5422
"Diff",
23+
"DiffConstants",
5524
"DiffIndex",
5625
"Diffable",
5726
"FetchInfo",
@@ -65,18 +34,19 @@
6534
"HEAD",
6635
"Head",
6736
"HookExecutionError",
37+
"INDEX",
6838
"IndexEntry",
6939
"IndexFile",
7040
"IndexObject",
7141
"InvalidDBRoot",
7242
"InvalidGitRepositoryError",
73-
"List",
43+
"List", # Deprecated - import this from `typing` instead.
7444
"LockFile",
7545
"NULL_TREE",
7646
"NoSuchPathError",
7747
"ODBError",
7848
"Object",
79-
"Optional",
49+
"Optional", # Deprecated - import this from `typing` instead.
8050
"ParseError",
8151
"PathLike",
8252
"PushInfo",
@@ -90,31 +60,62 @@
9060
"RepositoryDirtyError",
9161
"RootModule",
9262
"RootUpdateProgress",
93-
"Sequence",
63+
"Sequence", # Deprecated - import from `typing`, or `collections.abc` in 3.9+.
9464
"StageType",
9565
"Stats",
9666
"Submodule",
9767
"SymbolicReference",
98-
"TYPE_CHECKING",
68+
"TYPE_CHECKING", # Deprecated - import this from `typing` instead.
9969
"Tag",
10070
"TagObject",
10171
"TagReference",
10272
"Tree",
10373
"TreeModifier",
104-
"Tuple",
105-
"Union",
74+
"Tuple", # Deprecated - import this from `typing` instead.
75+
"Union", # Deprecated - import this from `typing` instead.
10676
"UnmergedEntriesError",
10777
"UnsafeOptionError",
10878
"UnsafeProtocolError",
10979
"UnsupportedOperation",
11080
"UpdateProgress",
11181
"WorkTreeRepositoryUnsupported",
82+
"refresh",
11283
"remove_password_if_present",
11384
"rmtree",
11485
"safe_decode",
11586
"to_hex_sha",
11687
]
11788

89+
__version__ = "git"
90+
91+
from typing import List, Optional, Sequence, Tuple, Union, TYPE_CHECKING
92+
93+
from gitdb.util import to_hex_sha
94+
from git.exc import * # noqa: F403 # @NoMove @IgnorePep8
95+
from git.types import PathLike
96+
97+
try:
98+
from git.compat import safe_decode # @NoMove @IgnorePep8
99+
from git.config import GitConfigParser # @NoMove @IgnorePep8
100+
from git.objects import * # noqa: F403 # @NoMove @IgnorePep8
101+
from git.refs import * # noqa: F403 # @NoMove @IgnorePep8
102+
from git.diff import * # noqa: F403 # @NoMove @IgnorePep8
103+
from git.db import * # noqa: F403 # @NoMove @IgnorePep8
104+
from git.cmd import Git # @NoMove @IgnorePep8
105+
from git.repo import Repo # @NoMove @IgnorePep8
106+
from git.remote import * # noqa: F403 # @NoMove @IgnorePep8
107+
from git.index import * # noqa: F403 # @NoMove @IgnorePep8
108+
from git.util import ( # @NoMove @IgnorePep8
109+
LockFile,
110+
BlockingLockFile,
111+
Stats,
112+
Actor,
113+
remove_password_if_present,
114+
rmtree,
115+
)
116+
except GitError as _exc: # noqa: F405
117+
raise ImportError("%s: %s" % (_exc.__class__.__name__, _exc)) from _exc
118+
118119
# { Initialize git executable path
119120
GIT_OK = None
120121

@@ -146,7 +147,7 @@ def refresh(path: Optional[PathLike] = None) -> None:
146147
if not Git.refresh(path=path):
147148
return
148149
if not FetchInfo.refresh(): # noqa: F405
149-
return # type: ignore [unreachable]
150+
return # type: ignore[unreachable]
150151

151152
GIT_OK = True
152153

0 commit comments

Comments
 (0)