Skip to content

Commit 4e9a2f2

Browse files
committed
Improve order of imports and __all__ in git.object.submodule.*
1 parent c946906 commit 4e9a2f2

File tree

8 files changed

+68
-59
lines changed

8 files changed

+68
-59
lines changed

Diff for: git/objects/base.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,15 +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-
import gitdb.typ as dbtyp
6+
__all__ = ("Object", "IndexObject")
7+
78
import os.path as osp
89

10+
import gitdb.typ as dbtyp
11+
912
from git.exc import WorkTreeRepositoryUnsupported
10-
from git.util import LazyMixin, join_path_native, stream_copy, bin_to_hex
13+
from git.util import LazyMixin, bin_to_hex, join_path_native, stream_copy
1114

1215
from .util import get_object_type_by_name
1316

14-
1517
# typing ------------------------------------------------------------------
1618

1719
from typing import Any, TYPE_CHECKING, Union
@@ -24,16 +26,14 @@
2426
from git.refs.reference import Reference
2527
from git.repo import Repo
2628

27-
from .tree import Tree
2829
from .blob import Blob
2930
from .submodule.base import Submodule
31+
from .tree import Tree
3032

3133
IndexObjUnion = Union["Tree", "Blob", "Submodule"]
3234

3335
# --------------------------------------------------------------------------
3436

35-
__all__ = ("Object", "IndexObject")
36-
3737

3838
class Object(LazyMixin):
3939
"""Base class for classes representing git object types.

Diff for: git/objects/blob.py

+3-3
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__ = ("Blob",)
7+
68
from mimetypes import guess_type
79
import sys
810

9-
from . import base
10-
1111
if sys.version_info >= (3, 8):
1212
from typing import Literal
1313
else:
1414
from typing_extensions import Literal
1515

16-
__all__ = ("Blob",)
16+
from . import base
1717

1818

1919
class Blob(base.IndexObject):

Diff for: git/objects/commit.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
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__ = ("Commit",)
7+
68
from collections import defaultdict
79
import datetime
810
from io import BytesIO
@@ -14,10 +16,12 @@
1416
from time import altzone, daylight, localtime, time, timezone
1517

1618
from gitdb import IStream
19+
1720
from git.cmd import Git
1821
from git.diff import Diffable
19-
from git.util import hex_to_bin, Actor, Stats, finalize_process
22+
from git.util import Actor, Stats, finalize_process, hex_to_bin
2023

24+
from . import base
2125
from .tree import Tree
2226
from .util import (
2327
Serializable,
@@ -27,7 +31,6 @@
2731
parse_actor_and_date,
2832
parse_date,
2933
)
30-
from . import base
3134

3235
# typing ------------------------------------------------------------------
3336

@@ -59,8 +62,6 @@
5962

6063
_logger = logging.getLogger(__name__)
6164

62-
__all__ = ("Commit",)
63-
6465

6566
class Commit(base.Object, TraversableIterableObj, Diffable, Serializable):
6667
"""Wraps a git commit object.

Diff for: git/objects/fun.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33

44
"""Functions that are supposed to be as fast as possible."""
55

6-
from stat import S_ISDIR
6+
__all__ = (
7+
"tree_to_stream",
8+
"tree_entries_from_data",
9+
"traverse_trees_recursive",
10+
"traverse_tree_recursive",
11+
)
712

13+
from stat import S_ISDIR
814

915
from git.compat import safe_decode, defenc
1016

@@ -23,22 +29,15 @@
2329

2430
if TYPE_CHECKING:
2531
from _typeshed import ReadableBuffer
32+
2633
from git import GitCmdObjectDB
2734

28-
EntryTup = Tuple[bytes, int, str] # same as TreeCacheTup in tree.py
35+
EntryTup = Tuple[bytes, int, str] # Same as TreeCacheTup in tree.py.
2936
EntryTupOrNone = Union[EntryTup, None]
3037

3138
# ---------------------------------------------------
3239

3340

34-
__all__ = (
35-
"tree_to_stream",
36-
"tree_entries_from_data",
37-
"traverse_trees_recursive",
38-
"traverse_tree_recursive",
39-
)
40-
41-
4241
def tree_to_stream(entries: Sequence[EntryTup], write: Callable[["ReadableBuffer"], Union[int, None]]) -> None:
4342
"""Write the given list of entries into a stream using its ``write`` method.
4443

Diff for: git/objects/submodule/util.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
from git.types import PathLike
2424

2525
if TYPE_CHECKING:
26-
from .base import Submodule
2726
from weakref import ReferenceType
27+
28+
from git.refs import Head, RemoteReference
29+
from git.remote import Remote
2830
from git.repo import Repo
29-
from git.refs import Head
30-
from git import Remote
31-
from git.refs import RemoteReference
31+
32+
from .base import Submodule
3233

3334
# { Utilities
3435

Diff for: git/objects/tag.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99
For lightweight tags, see the :mod:`git.refs.tag` module.
1010
"""
1111

12+
__all__ = ("TagObject",)
13+
1214
import sys
1315

16+
from git.compat import defenc
17+
from git.util import hex_to_bin
18+
1419
from . import base
1520
from .util import get_object_type_by_name, parse_actor_and_date
16-
from ..util import hex_to_bin
17-
from ..compat import defenc
21+
22+
# typing ----------------------------------------------
1823

1924
from typing import List, TYPE_CHECKING, Union
2025

@@ -26,11 +31,12 @@
2631
if TYPE_CHECKING:
2732
from git.repo import Repo
2833
from git.util import Actor
29-
from .commit import Commit
34+
3035
from .blob import Blob
36+
from .commit import Commit
3137
from .tree import Tree
3238

33-
__all__ = ("TagObject",)
39+
# ---------------------------------------------------
3440

3541

3642
class TagObject(base.Object):

Diff for: git/objects/tree.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
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__ = ("TreeModifier", "Tree")
7+
68
import sys
79

810
import git.diff as git_diff
911
from git.util import IterableList, join_path, to_bin_sha
1012

13+
from . import util
1114
from .base import IndexObjUnion, IndexObject
1215
from .blob import Blob
1316
from .fun import tree_entries_from_data, tree_to_stream
1417
from .submodule.base import Submodule
15-
from . import util
1618

1719
# typing -------------------------------------------------
1820

@@ -39,23 +41,20 @@
3941

4042
if TYPE_CHECKING:
4143
from io import BytesIO
44+
4245
from git.repo import Repo
4346

4447
TreeCacheTup = Tuple[bytes, int, str]
4548

4649
TraversedTreeTup = Union[Tuple[Union["Tree", None], IndexObjUnion, Tuple["Submodule", "Submodule"]]]
4750

48-
4951
# def is_tree_cache(inp: Tuple[bytes, int, str]) -> TypeGuard[TreeCacheTup]:
5052
# return isinstance(inp[0], bytes) and isinstance(inp[1], int) and isinstance([inp], str)
5153

5254
# --------------------------------------------------------
5355

54-
5556
cmp: Callable[[str, str], int] = lambda a, b: (a > b) - (a < b)
5657

57-
__all__ = ("TreeModifier", "Tree")
58-
5958

6059
class TreeModifier:
6160
"""A utility class providing methods to alter the underlying cache in a list-like

Diff for: git/objects/util.py

+26-23
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,63 @@
55

66
"""General utility functions."""
77

8+
__all__ = (
9+
"get_object_type_by_name",
10+
"parse_date",
11+
"parse_actor_and_date",
12+
"ProcessStreamAdapter",
13+
"Traversable",
14+
"altz_to_utctz_str",
15+
"utctz_to_altz",
16+
"verify_utctz",
17+
"Actor",
18+
"tzoffset",
19+
"utc",
20+
)
21+
822
from abc import ABC, abstractmethod
923
import calendar
1024
from collections import deque
1125
from datetime import datetime, timedelta, tzinfo
12-
from string import digits
1326
import re
27+
from string import digits
1428
import time
1529
import warnings
1630

17-
from git.util import IterableList, IterableObj, Actor
31+
from git.util import Actor, IterableList, IterableObj
1832

1933
# typing ------------------------------------------------------------
34+
2035
from typing import (
2136
Any,
2237
Callable,
2338
Deque,
24-
Iterator,
2539
# Generic,
40+
Iterator,
2641
NamedTuple,
27-
overload,
2842
Sequence,
2943
TYPE_CHECKING,
3044
Tuple,
3145
Type,
3246
TypeVar,
3347
Union,
3448
cast,
49+
overload,
3550
)
3651

3752
from git.types import Has_id_attribute, Literal # , _T
3853

3954
if TYPE_CHECKING:
4055
from io import BytesIO, StringIO
41-
from .commit import Commit
42-
from .blob import Blob
43-
from .tag import TagObject
44-
from .tree import Tree, TraversedTreeTup
4556
from subprocess import Popen
46-
from .submodule.base import Submodule
57+
4758
from git.types import Protocol, runtime_checkable
59+
60+
from .blob import Blob
61+
from .commit import Commit
62+
from .submodule.base import Submodule
63+
from .tag import TagObject
64+
from .tree import TraversedTreeTup, Tree
4865
else:
4966
# Protocol = Generic[_T] # Needed for typing bug #572?
5067
Protocol = ABC
@@ -68,20 +85,6 @@ class TraverseNT(NamedTuple):
6885

6986
# --------------------------------------------------------------------
7087

71-
__all__ = (
72-
"get_object_type_by_name",
73-
"parse_date",
74-
"parse_actor_and_date",
75-
"ProcessStreamAdapter",
76-
"Traversable",
77-
"altz_to_utctz_str",
78-
"utctz_to_altz",
79-
"verify_utctz",
80-
"Actor",
81-
"tzoffset",
82-
"utc",
83-
)
84-
8588
ZERO = timedelta(0)
8689

8790
# { Functions

0 commit comments

Comments
 (0)