Skip to content

Commit 4fb6d24

Browse files
authored
Merge pull request #1880 from EliahKagan/imports
Replace all wildcard imports with explicit imports
2 parents 0a609b9 + d524c76 commit 4fb6d24

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+540
-419
lines changed

git/__init__.py

+97-17
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# @PydevCodeAnalysisIgnore
77

8-
__all__ = [ # noqa: F405
8+
__all__ = [
99
"Actor",
1010
"AmbiguousObjectName",
1111
"BadName",
@@ -88,32 +88,112 @@
8888

8989
__version__ = "git"
9090

91-
from typing import List, Optional, Sequence, Tuple, Union, TYPE_CHECKING
91+
from typing import List, Optional, Sequence, TYPE_CHECKING, Tuple, Union
9292

9393
from gitdb.util import to_hex_sha
94-
from git.exc import * # noqa: F403 # @NoMove @IgnorePep8
94+
95+
from git.exc import (
96+
AmbiguousObjectName,
97+
BadName,
98+
BadObject,
99+
BadObjectType,
100+
CacheError,
101+
CheckoutError,
102+
CommandError,
103+
GitCommandError,
104+
GitCommandNotFound,
105+
GitError,
106+
HookExecutionError,
107+
InvalidDBRoot,
108+
InvalidGitRepositoryError,
109+
NoSuchPathError,
110+
ODBError,
111+
ParseError,
112+
RepositoryDirtyError,
113+
UnmergedEntriesError,
114+
UnsafeOptionError,
115+
UnsafeProtocolError,
116+
UnsupportedOperation,
117+
WorkTreeRepositoryUnsupported,
118+
)
95119
from git.types import PathLike
96120

97121
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,
122+
from git.compat import safe_decode # @NoMove
123+
from git.config import GitConfigParser # @NoMove
124+
from git.objects import ( # @NoMove
125+
Blob,
126+
Commit,
127+
IndexObject,
128+
Object,
129+
RootModule,
130+
RootUpdateProgress,
131+
Submodule,
132+
TagObject,
133+
Tree,
134+
TreeModifier,
135+
UpdateProgress,
136+
)
137+
from git.refs import ( # @NoMove
138+
HEAD,
139+
Head,
140+
RefLog,
141+
RefLogEntry,
142+
Reference,
143+
RemoteReference,
144+
SymbolicReference,
145+
Tag,
146+
TagReference,
147+
head, # noqa: F401 # Nonpublic. May disappear! Use git.refs.head.
148+
log, # noqa: F401 # Nonpublic. May disappear! Use git.refs.log.
149+
reference, # noqa: F401 # Nonpublic. May disappear! Use git.refs.reference.
150+
symbolic, # noqa: F401 # Nonpublic. May disappear! Use git.refs.symbolic.
151+
tag, # noqa: F401 # Nonpublic. May disappear! Use git.refs.tag.
152+
)
153+
from git.diff import ( # @NoMove
154+
INDEX,
155+
NULL_TREE,
156+
Diff,
157+
DiffConstants,
158+
DiffIndex,
159+
Diffable,
160+
)
161+
from git.db import GitCmdObjectDB, GitDB # @NoMove
162+
from git.cmd import Git # @NoMove
163+
from git.repo import Repo # @NoMove
164+
from git.remote import FetchInfo, PushInfo, Remote, RemoteProgress # @NoMove
165+
from git.index import ( # @NoMove
166+
BaseIndexEntry,
167+
BlobFilter,
168+
CheckoutError,
169+
IndexEntry,
170+
IndexFile,
171+
StageType,
172+
base, # noqa: F401 # Nonpublic. May disappear! Use git.index.base.
173+
fun, # noqa: F401 # Nonpublic. May disappear! Use git.index.fun.
174+
typ, # noqa: F401 # Nonpublic. May disappear! Use git.index.typ.
175+
#
176+
# NOTE: The expression `git.util` evaluates to git.index.util, and the import
177+
# `from git import util` imports git.index.util, NOT git.util. It may not be
178+
# feasible to change this until the next major version, to avoid breaking code
179+
# inadvertently relying on it. If git.index.util really is what you want, use or
180+
# import from that name, to avoid confusion. To use the "real" git.util module,
181+
# write `from git.util import ...`, or access it as `sys.modules["git.util"]`.
182+
# (This differs from other historical indirect-submodule imports that are
183+
# unambiguously nonpublic and are subject to immediate removal. Here, the public
184+
# git.util module, even though different, makes it less discoverable that the
185+
# expression `git.util` refers to a non-public attribute of the git module.)
186+
util, # noqa: F401
187+
)
188+
from git.util import ( # @NoMove
189+
Actor,
110190
BlockingLockFile,
191+
LockFile,
111192
Stats,
112-
Actor,
113193
remove_password_if_present,
114194
rmtree,
115195
)
116-
except GitError as _exc: # noqa: F405
196+
except GitError as _exc:
117197
raise ImportError("%s: %s" % (_exc.__class__.__name__, _exc)) from _exc
118198

119199
# { Initialize git executable path

git/cmd.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55

66
from __future__ import annotations
77

8-
import re
8+
__all__ = ["Git"]
9+
910
import contextlib
1011
import io
1112
import itertools
1213
import logging
1314
import os
15+
import re
1416
import signal
15-
from subprocess import Popen, PIPE, DEVNULL
1617
import subprocess
18+
from subprocess import DEVNULL, PIPE, Popen
1719
import sys
18-
import threading
1920
from textwrap import dedent
21+
import threading
2022

2123
from git.compat import defenc, force_bytes, safe_decode
2224
from git.exc import (
@@ -57,12 +59,11 @@
5759
overload,
5860
)
5961

60-
from git.types import PathLike, Literal, TBD
62+
from git.types import Literal, PathLike, TBD
6163

6264
if TYPE_CHECKING:
63-
from git.repo.base import Repo
6465
from git.diff import DiffIndex
65-
66+
from git.repo.base import Repo
6667

6768
# ---------------------------------------------------------------------------------
6869

@@ -84,8 +85,6 @@
8485

8586
_logger = logging.getLogger(__name__)
8687

87-
__all__ = ("Git",)
88-
8988

9089
# ==============================================================================
9190
## @name Utilities

git/compat.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414
import os
1515
import sys
1616

17-
from gitdb.utils.encoding import force_bytes, force_text # noqa: F401 # @UnusedImport
17+
from gitdb.utils.encoding import force_bytes, force_text # noqa: F401
1818

1919
# typing --------------------------------------------------------------------
2020

21-
from typing import ( # noqa: F401
22-
Any,
21+
from typing import (
22+
Any, # noqa: F401
2323
AnyStr,
24-
Dict,
25-
IO,
24+
Dict, # noqa: F401
25+
IO, # noqa: F401
2626
Optional,
27-
Tuple,
28-
Type,
27+
Tuple, # noqa: F401
28+
Type, # noqa: F401
2929
Union,
3030
overload,
3131
)

git/config.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
"""Parser for reading and writing configuration files."""
77

8+
__all__ = ["GitConfigParser", "SectionConstraint"]
9+
810
import abc
911
import configparser as cp
1012
import fnmatch
@@ -40,9 +42,10 @@
4042
from git.types import Lit_config_levels, ConfigLevels_Tup, PathLike, assert_never, _T
4143

4244
if TYPE_CHECKING:
43-
from git.repo.base import Repo
4445
from io import BytesIO
4546

47+
from git.repo.base import Repo
48+
4649
T_ConfigParser = TypeVar("T_ConfigParser", bound="GitConfigParser")
4750
T_OMD_value = TypeVar("T_OMD_value", str, bytes, int, float, bool)
4851

@@ -58,8 +61,6 @@
5861

5962
# -------------------------------------------------------------
6063

61-
__all__ = ("GitConfigParser", "SectionConstraint")
62-
6364
_logger = logging.getLogger(__name__)
6465

6566
CONFIG_LEVELS: ConfigLevels_Tup = ("system", "user", "global", "repository")

git/db.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,26 @@
33

44
"""Module with our own gitdb implementation - it uses the git command."""
55

6-
from git.util import bin_to_hex, hex_to_bin
7-
from gitdb.base import OInfo, OStream
8-
from gitdb.db import GitDB
9-
from gitdb.db import LooseObjectDB
6+
__all__ = ["GitCmdObjectDB", "GitDB"]
107

8+
from gitdb.base import OInfo, OStream
9+
from gitdb.db import GitDB, LooseObjectDB
1110
from gitdb.exc import BadObject
11+
12+
from git.util import bin_to_hex, hex_to_bin
1213
from git.exc import GitCommandError
1314

1415
# typing-------------------------------------------------
1516

1617
from typing import TYPE_CHECKING
18+
1719
from git.types import PathLike
1820

1921
if TYPE_CHECKING:
2022
from git.cmd import Git
2123

22-
2324
# --------------------------------------------------------
2425

25-
__all__ = ("GitCmdObjectDB", "GitDB")
26-
2726

2827
class GitCmdObjectDB(LooseObjectDB):
2928
"""A database representing the default git object store, which includes loose

git/diff.py

+11-19
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
# This module is part of GitPython and is released under the
44
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
55

6+
__all__ = ["DiffConstants", "NULL_TREE", "INDEX", "Diffable", "DiffIndex", "Diff"]
7+
68
import enum
79
import re
810

911
from git.cmd import handle_process_output
1012
from git.compat import defenc
13+
from git.objects.blob import Blob
14+
from git.objects.util import mode_str_to_int
1115
from git.util import finalize_process, hex_to_bin
1216

13-
from .objects.blob import Blob
14-
from .objects.util import mode_str_to_int
15-
16-
1717
# typing ------------------------------------------------------------------
1818

1919
from typing import (
@@ -23,34 +23,27 @@
2323
Match,
2424
Optional,
2525
Tuple,
26+
TYPE_CHECKING,
2627
TypeVar,
2728
Union,
28-
TYPE_CHECKING,
2929
cast,
3030
)
3131
from git.types import Literal, PathLike
3232

3333
if TYPE_CHECKING:
34-
from .objects.tree import Tree
35-
from .objects import Commit
36-
from git.repo.base import Repo
37-
from git.objects.base import IndexObject
3834
from subprocess import Popen
39-
from git import Git
40-
41-
Lit_change_type = Literal["A", "D", "C", "M", "R", "T", "U"]
4235

36+
from git.cmd import Git
37+
from git.objects.base import IndexObject
38+
from git.objects.commit import Commit
39+
from git.objects.tree import Tree
40+
from git.repo.base import Repo
4341

44-
# def is_change_type(inp: str) -> TypeGuard[Lit_change_type]:
45-
# # return True
46-
# return inp in ['A', 'D', 'C', 'M', 'R', 'T', 'U']
42+
Lit_change_type = Literal["A", "D", "C", "M", "R", "T", "U"]
4743

4844
# ------------------------------------------------------------------------
4945

5046

51-
__all__ = ("DiffConstants", "NULL_TREE", "INDEX", "Diffable", "DiffIndex", "Diff")
52-
53-
5447
@enum.unique
5548
class DiffConstants(enum.Enum):
5649
"""Special objects for :meth:`Diffable.diff`.
@@ -693,7 +686,6 @@ def _handle_diff_line(lines_bytes: bytes, repo: "Repo", index: DiffIndex) -> Non
693686
# Change type can be R100
694687
# R: status letter
695688
# 100: score (in case of copy and rename)
696-
# assert is_change_type(_change_type[0]), f"Unexpected value for change_type received: {_change_type[0]}"
697689
change_type: Lit_change_type = cast(Lit_change_type, _change_type[0])
698690
score_str = "".join(_change_type[1:])
699691
score = int(score_str) if score_str.isdigit() else None

git/exc.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@
4242
ParseError,
4343
UnsupportedOperation,
4444
)
45+
4546
from git.compat import safe_decode
4647
from git.util import remove_password_if_present
4748

4849
# typing ----------------------------------------------------
4950

50-
from typing import List, Sequence, Tuple, Union, TYPE_CHECKING
51+
from typing import List, Sequence, Tuple, TYPE_CHECKING, Union
52+
5153
from git.types import PathLike
5254

5355
if TYPE_CHECKING:

git/index/__init__.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,14 @@
33

44
"""Initialize the index package."""
55

6-
from .base import * # noqa: F401 F403
7-
from .typ import * # noqa: F401 F403
6+
__all__ = [
7+
"BaseIndexEntry",
8+
"BlobFilter",
9+
"CheckoutError",
10+
"IndexEntry",
11+
"IndexFile",
12+
"StageType",
13+
]
14+
15+
from .base import CheckoutError, IndexFile
16+
from .typ import BaseIndexEntry, BlobFilter, IndexEntry, StageType

0 commit comments

Comments
 (0)