Skip to content

Commit 3d4e476

Browse files
committed
Improve how second-level imports and __all__ are written
These are in the modules that are directly under the top-level git module (and are not themselves subpackages, with their own submodules in the Python sense), except for: - git.util, where this change was very recently made. - git.compat, where no improvements of this kind were needed. - git.types, which currently has no __all__ and will only benefit from it if what should go in it is carefully considered (and where the imports themselves are grouped, sorted, and formatted already).
1 parent b8bab43 commit 3d4e476

File tree

6 files changed

+33
-34
lines changed

6 files changed

+33
-34
lines changed

Diff for: 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

Diff for: 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")

Diff for: 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

Diff for: git/diff.py

+11-13
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,29 +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
35+
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
4041

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

4344
# ------------------------------------------------------------------------
4445

4546

46-
__all__ = ("DiffConstants", "NULL_TREE", "INDEX", "Diffable", "DiffIndex", "Diff")
47-
48-
4947
@enum.unique
5048
class DiffConstants(enum.Enum):
5149
"""Special objects for :meth:`Diffable.diff`.

Diff for: 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:

Diff for: git/remote.py

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

66
"""Module implementing a remote object allowing easy access to git remotes."""
77

8+
__all__ = ("RemoteProgress", "PushInfo", "FetchInfo", "Remote")
9+
810
import contextlib
911
import logging
1012
import re
@@ -54,8 +56,6 @@
5456

5557
_logger = logging.getLogger(__name__)
5658

57-
__all__ = ("RemoteProgress", "PushInfo", "FetchInfo", "Remote")
58-
5959
# { Utilities
6060

6161

0 commit comments

Comments
 (0)