Skip to content

Commit

Permalink
Merge pull request #1880 from EliahKagan/imports
Browse files Browse the repository at this point in the history
Replace all wildcard imports with explicit imports
  • Loading branch information
Byron committed Mar 19, 2024
2 parents 0a609b9 + d524c76 commit 4fb6d24
Show file tree
Hide file tree
Showing 66 changed files with 540 additions and 419 deletions.
114 changes: 97 additions & 17 deletions git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# @PydevCodeAnalysisIgnore

__all__ = [ # noqa: F405
__all__ = [
"Actor",
"AmbiguousObjectName",
"BadName",
Expand Down Expand Up @@ -88,32 +88,112 @@

__version__ = "git"

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

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

from git.exc import (
AmbiguousObjectName,
BadName,
BadObject,
BadObjectType,
CacheError,
CheckoutError,
CommandError,
GitCommandError,
GitCommandNotFound,
GitError,
HookExecutionError,
InvalidDBRoot,
InvalidGitRepositoryError,
NoSuchPathError,
ODBError,
ParseError,
RepositoryDirtyError,
UnmergedEntriesError,
UnsafeOptionError,
UnsafeProtocolError,
UnsupportedOperation,
WorkTreeRepositoryUnsupported,
)
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,
from git.compat import safe_decode # @NoMove
from git.config import GitConfigParser # @NoMove
from git.objects import ( # @NoMove
Blob,
Commit,
IndexObject,
Object,
RootModule,
RootUpdateProgress,
Submodule,
TagObject,
Tree,
TreeModifier,
UpdateProgress,
)
from git.refs import ( # @NoMove
HEAD,
Head,
RefLog,
RefLogEntry,
Reference,
RemoteReference,
SymbolicReference,
Tag,
TagReference,
head, # noqa: F401 # Nonpublic. May disappear! Use git.refs.head.
log, # noqa: F401 # Nonpublic. May disappear! Use git.refs.log.
reference, # noqa: F401 # Nonpublic. May disappear! Use git.refs.reference.
symbolic, # noqa: F401 # Nonpublic. May disappear! Use git.refs.symbolic.
tag, # noqa: F401 # Nonpublic. May disappear! Use git.refs.tag.
)
from git.diff import ( # @NoMove
INDEX,
NULL_TREE,
Diff,
DiffConstants,
DiffIndex,
Diffable,
)
from git.db import GitCmdObjectDB, GitDB # @NoMove
from git.cmd import Git # @NoMove
from git.repo import Repo # @NoMove
from git.remote import FetchInfo, PushInfo, Remote, RemoteProgress # @NoMove
from git.index import ( # @NoMove
BaseIndexEntry,
BlobFilter,
CheckoutError,
IndexEntry,
IndexFile,
StageType,
base, # noqa: F401 # Nonpublic. May disappear! Use git.index.base.
fun, # noqa: F401 # Nonpublic. May disappear! Use git.index.fun.
typ, # noqa: F401 # Nonpublic. May disappear! Use git.index.typ.
#
# NOTE: The expression `git.util` evaluates to git.index.util, and the import
# `from git import util` imports git.index.util, NOT git.util. It may not be
# feasible to change this until the next major version, to avoid breaking code
# inadvertently relying on it. If git.index.util really is what you want, use or
# import from that name, to avoid confusion. To use the "real" git.util module,
# write `from git.util import ...`, or access it as `sys.modules["git.util"]`.
# (This differs from other historical indirect-submodule imports that are
# unambiguously nonpublic and are subject to immediate removal. Here, the public
# git.util module, even though different, makes it less discoverable that the
# expression `git.util` refers to a non-public attribute of the git module.)
util, # noqa: F401
)
from git.util import ( # @NoMove
Actor,
BlockingLockFile,
LockFile,
Stats,
Actor,
remove_password_if_present,
rmtree,
)
except GitError as _exc: # noqa: F405
except GitError as _exc:
raise ImportError("%s: %s" % (_exc.__class__.__name__, _exc)) from _exc

# { Initialize git executable path
Expand Down
15 changes: 7 additions & 8 deletions git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@

from __future__ import annotations

import re
__all__ = ["Git"]

import contextlib
import io
import itertools
import logging
import os
import re
import signal
from subprocess import Popen, PIPE, DEVNULL
import subprocess
from subprocess import DEVNULL, PIPE, Popen
import sys
import threading
from textwrap import dedent
import threading

from git.compat import defenc, force_bytes, safe_decode
from git.exc import (
Expand Down Expand Up @@ -57,12 +59,11 @@
overload,
)

from git.types import PathLike, Literal, TBD
from git.types import Literal, PathLike, TBD

if TYPE_CHECKING:
from git.repo.base import Repo
from git.diff import DiffIndex

from git.repo.base import Repo

# ---------------------------------------------------------------------------------

Expand All @@ -84,8 +85,6 @@

_logger = logging.getLogger(__name__)

__all__ = ("Git",)


# ==============================================================================
## @name Utilities
Expand Down
14 changes: 7 additions & 7 deletions git/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
import os
import sys

from gitdb.utils.encoding import force_bytes, force_text # noqa: F401 # @UnusedImport
from gitdb.utils.encoding import force_bytes, force_text # noqa: F401

# typing --------------------------------------------------------------------

from typing import ( # noqa: F401
Any,
from typing import (
Any, # noqa: F401
AnyStr,
Dict,
IO,
Dict, # noqa: F401
IO, # noqa: F401
Optional,
Tuple,
Type,
Tuple, # noqa: F401
Type, # noqa: F401
Union,
overload,
)
Expand Down
7 changes: 4 additions & 3 deletions git/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

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

__all__ = ["GitConfigParser", "SectionConstraint"]

import abc
import configparser as cp
import fnmatch
Expand Down Expand Up @@ -40,9 +42,10 @@
from git.types import Lit_config_levels, ConfigLevels_Tup, PathLike, assert_never, _T

if TYPE_CHECKING:
from git.repo.base import Repo
from io import BytesIO

from git.repo.base import Repo

T_ConfigParser = TypeVar("T_ConfigParser", bound="GitConfigParser")
T_OMD_value = TypeVar("T_OMD_value", str, bytes, int, float, bool)

Expand All @@ -58,8 +61,6 @@

# -------------------------------------------------------------

__all__ = ("GitConfigParser", "SectionConstraint")

_logger = logging.getLogger(__name__)

CONFIG_LEVELS: ConfigLevels_Tup = ("system", "user", "global", "repository")
Expand Down
13 changes: 6 additions & 7 deletions git/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,26 @@

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

from git.util import bin_to_hex, hex_to_bin
from gitdb.base import OInfo, OStream
from gitdb.db import GitDB
from gitdb.db import LooseObjectDB
__all__ = ["GitCmdObjectDB", "GitDB"]

from gitdb.base import OInfo, OStream
from gitdb.db import GitDB, LooseObjectDB
from gitdb.exc import BadObject

from git.util import bin_to_hex, hex_to_bin
from git.exc import GitCommandError

# typing-------------------------------------------------

from typing import TYPE_CHECKING

from git.types import PathLike

if TYPE_CHECKING:
from git.cmd import Git


# --------------------------------------------------------

__all__ = ("GitCmdObjectDB", "GitDB")


class GitCmdObjectDB(LooseObjectDB):
"""A database representing the default git object store, which includes loose
Expand Down
30 changes: 11 additions & 19 deletions git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

__all__ = ["DiffConstants", "NULL_TREE", "INDEX", "Diffable", "DiffIndex", "Diff"]

import enum
import re

from git.cmd import handle_process_output
from git.compat import defenc
from git.objects.blob import Blob
from git.objects.util import mode_str_to_int
from git.util import finalize_process, hex_to_bin

from .objects.blob import Blob
from .objects.util import mode_str_to_int


# typing ------------------------------------------------------------------

from typing import (
Expand All @@ -23,34 +23,27 @@
Match,
Optional,
Tuple,
TYPE_CHECKING,
TypeVar,
Union,
TYPE_CHECKING,
cast,
)
from git.types import Literal, PathLike

if TYPE_CHECKING:
from .objects.tree import Tree
from .objects import Commit
from git.repo.base import Repo
from git.objects.base import IndexObject
from subprocess import Popen
from git import Git

Lit_change_type = Literal["A", "D", "C", "M", "R", "T", "U"]

from git.cmd import Git
from git.objects.base import IndexObject
from git.objects.commit import Commit
from git.objects.tree import Tree
from git.repo.base import Repo

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

# ------------------------------------------------------------------------


__all__ = ("DiffConstants", "NULL_TREE", "INDEX", "Diffable", "DiffIndex", "Diff")


@enum.unique
class DiffConstants(enum.Enum):
"""Special objects for :meth:`Diffable.diff`.
Expand Down Expand Up @@ -693,7 +686,6 @@ def _handle_diff_line(lines_bytes: bytes, repo: "Repo", index: DiffIndex) -> Non
# Change type can be R100
# R: status letter
# 100: score (in case of copy and rename)
# assert is_change_type(_change_type[0]), f"Unexpected value for change_type received: {_change_type[0]}"
change_type: Lit_change_type = cast(Lit_change_type, _change_type[0])
score_str = "".join(_change_type[1:])
score = int(score_str) if score_str.isdigit() else None
Expand Down
4 changes: 3 additions & 1 deletion git/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@
ParseError,
UnsupportedOperation,
)

from git.compat import safe_decode
from git.util import remove_password_if_present

# typing ----------------------------------------------------

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

from git.types import PathLike

if TYPE_CHECKING:
Expand Down
13 changes: 11 additions & 2 deletions git/index/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@

"""Initialize the index package."""

from .base import * # noqa: F401 F403
from .typ import * # noqa: F401 F403
__all__ = [
"BaseIndexEntry",
"BlobFilter",
"CheckoutError",
"IndexEntry",
"IndexFile",
"StageType",
]

from .base import CheckoutError, IndexFile
from .typ import BaseIndexEntry, BlobFilter, IndexEntry, StageType
Loading

0 comments on commit 4fb6d24

Please sign in to comment.