Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve static typing and docstrings related to git object types #1859

Merged
merged 82 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
f83b056
Revise assert_never
EliahKagan Mar 2, 2024
01cc8e2
Fix unnecessarily long reference in Tree docstrings
EliahKagan Mar 3, 2024
6f3a20f
Change how tree[subscript] is introduced
EliahKagan Mar 3, 2024
85889cd
Refine how tree[subscript] is introduced
EliahKagan Mar 3, 2024
9e47083
Start adding docstrings to types in git.types
EliahKagan Mar 3, 2024
3bd8177
Document Tree_ish, Commit_ish, and related types
EliahKagan Mar 3, 2024
f3b9a69
Expand docs of classes representing Git objects
EliahKagan Mar 3, 2024
2af7640
Do a bit of tidying related to unused names
EliahKagan Mar 3, 2024
2aa053e
Add docstrings to TypedDicts in git.types
EliahKagan Mar 3, 2024
15d50de
Revise a couple new docstrings for clarity
EliahKagan Mar 4, 2024
7166703
Fix possible inaccuracy in Lit_config_levels docstring
EliahKagan Mar 4, 2024
1530fd2
Use phrases like "git object type" where applicable
EliahKagan Mar 4, 2024
2e02b09
Add docstrings to protocols in git.types
EliahKagan Mar 4, 2024
012d710
Move our PathLike below even TYPE_CHECKING imports
EliahKagan Mar 4, 2024
a06f1fc
Remove commented-out is_config_level function
EliahKagan Mar 4, 2024
c93e431
Expand git.compat docstring
EliahKagan Mar 4, 2024
29443ce
Add a cationary note about Object vs. object
EliahKagan Mar 4, 2024
b6e3ad2
Don't bind unused _assertion_msg_format
EliahKagan Mar 4, 2024
b5d9198
Remove commented-out code
EliahKagan Mar 6, 2024
2212ac9
Fix Sphinx reference that rendered overly long
EliahKagan Mar 7, 2024
3c5ca52
Simplify _safer_popen_windows "if shell" logic
EliahKagan Mar 7, 2024
43b7f8a
Annotate safer_popen broad enough for all platforms
EliahKagan Mar 7, 2024
dc95a76
Fix mypy error with creationflags in subprocess module
EliahKagan Mar 7, 2024
4191f7d
Refactor kill_after_timeout logic so mypy can check it
EliahKagan Mar 7, 2024
1ef3365
Factor communicate and watchdog logic to helper
EliahKagan Mar 7, 2024
4083dd8
Fix new mypy confusion about kill_after_timeout type
EliahKagan Mar 7, 2024
3aeef46
Fix how Diffable annotates expected repo attribute
EliahKagan Mar 7, 2024
f1cc1fe
Fix how HEAD annotates inherited commit property
EliahKagan Mar 8, 2024
e133018
Broaden cygpath parameter annotation
EliahKagan Mar 8, 2024
c34a466
Have Repo.__init__ convert epath to str first instead
EliahKagan Mar 8, 2024
4dfd480
Fix how Remote annotates dynamic config-backed url attribute
EliahKagan Mar 8, 2024
e4fd2e3
Drop wrong variable annotations in BlobFilter.__call__
EliahKagan Mar 8, 2024
94344b4
Clarify CallableProgress vs. CallableRemoteProgress
EliahKagan Mar 8, 2024
8e8b87a
Fix RootModule.update `ignore[override]` suppression
EliahKagan Mar 8, 2024
1cdec7a
Fix wrong class name in git.objects.tag docstring
EliahKagan Mar 8, 2024
ed6ead9
Correct and clarify Diffable.diff docstring
EliahKagan Mar 8, 2024
0e1df29
Start fixing diff and _process_diff_args type annotations
EliahKagan Mar 9, 2024
62c0823
Consolidate str and os.PathLike[str] (use GitPython's PathLike)
EliahKagan Mar 9, 2024
7204cc1
Further clarify Diffable.diff docstring
EliahKagan Mar 9, 2024
2f5e258
Annotate _process_diff_args without Diffable.Index
EliahKagan Mar 9, 2024
65863a2
Make NULL_TREE and Index precisely annotatable
EliahKagan Mar 9, 2024
c9952e1
Fix Sphinx references; give Diffable.Index a docstring
EliahKagan Mar 9, 2024
b8a25df
Modify annotations to accommodate NULL_TREE
EliahKagan Mar 9, 2024
e49327d
Add refresh to top-level __all__
EliahKagan Feb 24, 2024
c8ad3a3
Deprecate public access to typing imports in git
EliahKagan Feb 24, 2024
3c8cbe9
Mention collections.abc for Sequence
EliahKagan Mar 5, 2024
87b314e
Add INDEX and DiffConstants to git.__all__
EliahKagan Mar 9, 2024
9ed904c
Adjust mypy options to work well with mypy 1.9.0
EliahKagan Mar 9, 2024
aeacb00
Colorize mypy output on CI for easier reading
EliahKagan Mar 9, 2024
84fc806
Remove some unneeded mypy suppressions
EliahKagan Mar 10, 2024
96ecc2e
Drop deprecated mypy option
EliahKagan Mar 10, 2024
97d9b65
Apply intended suppression in Tree.traverse
EliahKagan Mar 10, 2024
ad00c77
Spell self.Index as self.INDEX in IndexFile.diff
EliahKagan Mar 10, 2024
2decbe4
Test that redefined Diffable.Index should be compatible
EliahKagan Mar 10, 2024
88557bc
Have git module use sys.platform to check for Windows
EliahKagan Mar 10, 2024
7204c13
Fix new mypy error in _read_win_env_flag
EliahKagan Mar 10, 2024
42e10c0
Fix new mypy error in is_cygwin_git
EliahKagan Mar 10, 2024
465ab56
Have test suite use sys.platform to check for Windows
EliahKagan Mar 10, 2024
ad8190b
Wrap docstrings and comments in _safer_popen_windows
EliahKagan Mar 10, 2024
b9d9e56
Further improve _safer_popen_windows doc
EliahKagan Mar 10, 2024
04a2753
Temporarily rename Commit_ish to Old_commit_ish
EliahKagan Mar 10, 2024
787f65c
Define and document AnyGitObject and (new) Commit_ish
EliahKagan Mar 10, 2024
1fe4dc8
Define GitObjectTypeString and update Object to use it
EliahKagan Mar 10, 2024
7328a00
Start fixing annotations that used the old Commit_ish
EliahKagan Mar 10, 2024
191f4cf
Fix some annotations in git.repo.fun
EliahKagan Mar 10, 2024
d1ce940
Remove extra `parents` param in Commit.__init__ docstring
EliahKagan Mar 10, 2024
fe42ca7
Help tools know the type of a Commit's `parents`
EliahKagan Mar 11, 2024
e66297a
Keep the type of a Commit's `parents` from being too narrow
EliahKagan Mar 11, 2024
fe7f9f2
Fix remaining old Commit_ish annotations in git.repo.fun
EliahKagan Mar 11, 2024
ab27827
Fix remaining old Commit_ish annotations in git.refs
EliahKagan Mar 11, 2024
b4b6e1e
Fix IndexFile.commit `parent_commits` annotation
EliahKagan Mar 11, 2024
5b2869f
Fix old Commit_ish annotations in git.remote
EliahKagan Mar 11, 2024
1541c62
Start on fixing Submodule parent_commit annotations
EliahKagan Mar 11, 2024
1f03e7f
Fix other submodule.base parent_commit annotations
EliahKagan Mar 14, 2024
e66b8f1
Fix old Commit_ish annotation in RootModule
EliahKagan Mar 14, 2024
93d19dc
Remove the temporary Old_commit_ish type
EliahKagan Mar 14, 2024
ebcfced
Fix and deprecate Lit_commit_ish
EliahKagan Mar 14, 2024
b070e93
Make some broad mypy suppressions more specific
EliahKagan Mar 14, 2024
0b99041
Merge branch 'main' into doc-types
EliahKagan Mar 14, 2024
011cb0a
Apply Ruff auto-fixes not included in merge
EliahKagan Mar 14, 2024
74f3c2e
Help Ruff avoid a very long line
EliahKagan Mar 14, 2024
5778b7a
Use LBYL for imports where EAFP is a mypy type error
EliahKagan Mar 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,12 @@ jobs:

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

- name: Test with pytest
Expand Down
79 changes: 40 additions & 39 deletions git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,6 @@

# @PydevCodeAnalysisIgnore

__version__ = "git"

from typing import List, Optional, Sequence, Tuple, Union, TYPE_CHECKING

from gitdb.util import to_hex_sha
from git.exc import * # noqa: F403 # @NoMove @IgnorePep8
from git.types import PathLike

try:
from git.compat import safe_decode # @NoMove @IgnorePep8
from git.config import GitConfigParser # @NoMove @IgnorePep8
from git.objects import * # noqa: F403 # @NoMove @IgnorePep8
from git.refs import * # noqa: F403 # @NoMove @IgnorePep8
from git.diff import * # noqa: F403 # @NoMove @IgnorePep8
from git.db import * # noqa: F403 # @NoMove @IgnorePep8
from git.cmd import Git # @NoMove @IgnorePep8
from git.repo import Repo # @NoMove @IgnorePep8
from git.remote import * # noqa: F403 # @NoMove @IgnorePep8
from git.index import * # noqa: F403 # @NoMove @IgnorePep8
from git.util import ( # @NoMove @IgnorePep8
LockFile,
BlockingLockFile,
Stats,
Actor,
remove_password_if_present,
rmtree,
)
except GitError as _exc: # noqa: F405
raise ImportError("%s: %s" % (_exc.__class__.__name__, _exc)) from _exc

# __all__ must be statically defined by py.typed support
# __all__ = [name for name, obj in locals().items() if not (name.startswith("_") or inspect.ismodule(obj))]
__all__ = [ # noqa: F405
"Actor",
"AmbiguousObjectName",
Expand All @@ -52,6 +20,7 @@
"CommandError",
"Commit",
"Diff",
"DiffConstants",
"DiffIndex",
"Diffable",
"FetchInfo",
Expand All @@ -65,18 +34,19 @@
"HEAD",
"Head",
"HookExecutionError",
"INDEX",
"IndexEntry",
"IndexFile",
"IndexObject",
"InvalidDBRoot",
"InvalidGitRepositoryError",
"List",
"List", # Deprecated - import this from `typing` instead.
"LockFile",
"NULL_TREE",
"NoSuchPathError",
"ODBError",
"Object",
"Optional",
"Optional", # Deprecated - import this from `typing` instead.
"ParseError",
"PathLike",
"PushInfo",
Expand All @@ -90,31 +60,62 @@
"RepositoryDirtyError",
"RootModule",
"RootUpdateProgress",
"Sequence",
"Sequence", # Deprecated - import from `typing`, or `collections.abc` in 3.9+.
"StageType",
"Stats",
"Submodule",
"SymbolicReference",
"TYPE_CHECKING",
"TYPE_CHECKING", # Deprecated - import this from `typing` instead.
"Tag",
"TagObject",
"TagReference",
"Tree",
"TreeModifier",
"Tuple",
"Union",
"Tuple", # Deprecated - import this from `typing` instead.
"Union", # Deprecated - import this from `typing` instead.
"UnmergedEntriesError",
"UnsafeOptionError",
"UnsafeProtocolError",
"UnsupportedOperation",
"UpdateProgress",
"WorkTreeRepositoryUnsupported",
"refresh",
"remove_password_if_present",
"rmtree",
"safe_decode",
"to_hex_sha",
]

__version__ = "git"

from typing import List, Optional, Sequence, Tuple, Union, TYPE_CHECKING

from gitdb.util import to_hex_sha
from git.exc import * # noqa: F403 # @NoMove @IgnorePep8
from git.types import PathLike

try:
from git.compat import safe_decode # @NoMove @IgnorePep8
from git.config import GitConfigParser # @NoMove @IgnorePep8
from git.objects import * # noqa: F403 # @NoMove @IgnorePep8
from git.refs import * # noqa: F403 # @NoMove @IgnorePep8
from git.diff import * # noqa: F403 # @NoMove @IgnorePep8
from git.db import * # noqa: F403 # @NoMove @IgnorePep8
from git.cmd import Git # @NoMove @IgnorePep8
from git.repo import Repo # @NoMove @IgnorePep8
from git.remote import * # noqa: F403 # @NoMove @IgnorePep8
from git.index import * # noqa: F403 # @NoMove @IgnorePep8
from git.util import ( # @NoMove @IgnorePep8
LockFile,
BlockingLockFile,
Stats,
Actor,
remove_password_if_present,
rmtree,
)
except GitError as _exc: # noqa: F405
raise ImportError("%s: %s" % (_exc.__class__.__name__, _exc)) from _exc

# { Initialize git executable path
GIT_OK = None

Expand Down Expand Up @@ -146,7 +147,7 @@ def refresh(path: Optional[PathLike] = None) -> None:
if not Git.refresh(path=path):
return
if not FetchInfo.refresh(): # noqa: F405
return # type: ignore [unreachable]
return # type: ignore[unreachable]

GIT_OK = True

Expand Down
Loading
Loading