Skip to content

Replace all wildcard imports with explicit imports #1880

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

Merged
merged 34 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1e5a944
Add a script to validate refactored imports
EliahKagan Mar 17, 2024
5b2771d
Add regression tests of the git.util aliasing situation
EliahKagan Mar 18, 2024
fc86a23
Incompletely change git.index imports to test modattrs.py
EliahKagan Feb 24, 2024
4badc19
Fix git.index imports
EliahKagan Mar 18, 2024
1c9bda2
Improve relative order of import groups, and __all__, in git.index
EliahKagan Mar 18, 2024
8b51af3
Improve order of imports and __all__ in git.refs submodules
EliahKagan Mar 18, 2024
b25dd7e
Replace wildcard imports in git.refs
EliahKagan Mar 18, 2024
b32ef65
Improve order of imports and __all__ in git.repo submodules
EliahKagan Mar 18, 2024
0ba06e9
Add git.repo.__all__ and make submodules explicit
EliahKagan Mar 18, 2024
c946906
Improve order of imports and __all__ in git.objects.*
EliahKagan Mar 18, 2024
4e9a2f2
Improve order of imports and __all__ in git.object.submodule.*
EliahKagan Mar 18, 2024
c58be4c
Remove a bit of old commented-out code in git.objects.*
EliahKagan Mar 18, 2024
01c95eb
Don't patch IndexObject and Object into git.objects.submodule.util
EliahKagan Mar 18, 2024
f89d065
Fix git.objects.__all__ and make submodules explicit
EliahKagan Mar 18, 2024
3786307
Make git.objects.util module docstring more specific
EliahKagan Mar 18, 2024
de540b7
Add __all__ and imports in git.objects.submodule
EliahKagan Mar 18, 2024
a05597a
Improve how imports and __all__ are written in git.util
EliahKagan Mar 18, 2024
2053a3d
Remove old commented-out change_type assertions in git.diff
EliahKagan Mar 18, 2024
b8bab43
Remove old commented-out flagKeyLiteral assertions in git.remote
EliahKagan Mar 19, 2024
3d4e476
Improve how second-level imports and __all__ are written
EliahKagan Mar 19, 2024
6318eea
Make F401 "unused import" suppressions more specific
EliahKagan Mar 19, 2024
31bc8a4
Remove unneeded F401 "Unused import" suppressions
EliahKagan Mar 19, 2024
abbe74d
Fix a tiny import sorting nit
EliahKagan Mar 19, 2024
7745250
Replace wildcard imports in top-level git module
EliahKagan Mar 19, 2024
64c9efd
Restore relative order to fix circular import error
EliahKagan Mar 19, 2024
31f89a1
Add the nonpublic indirect submodule aliases back for now
EliahKagan Mar 19, 2024
9bbbcb5
Further improve git.objects.util module docstring
EliahKagan Mar 19, 2024
00f4cbc
Add missing submodule imports in git.objects
EliahKagan Mar 19, 2024
fcc7418
Don't explicitly list direct submodules in __all__
EliahKagan Mar 19, 2024
78055a8
Pick a consistent type for __all__ (for now, list)
EliahKagan Mar 19, 2024
ecdb6aa
Save diff of non-__all__ attributes across import changes
EliahKagan Mar 19, 2024
f705fd6
Remove modattrs.py and related
EliahKagan Mar 19, 2024
4a4d880
Improve test suite import grouping/sorting, __all__ placement
EliahKagan Mar 19, 2024
d524c76
Fix slightly unsorted imports in setup.py
EliahKagan Mar 19, 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
Prev Previous commit
Next Next commit
Improve order of imports and __all__ in git.object.submodule.*
  • Loading branch information
EliahKagan committed Mar 18, 2024
commit 4e9a2f2facb0da3adb9c6fe5165dcfb5c6627cb7
12 changes: 6 additions & 6 deletions git/objects/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

import gitdb.typ as dbtyp
__all__ = ("Object", "IndexObject")

import os.path as osp

import gitdb.typ as dbtyp

from git.exc import WorkTreeRepositoryUnsupported
from git.util import LazyMixin, join_path_native, stream_copy, bin_to_hex
from git.util import LazyMixin, bin_to_hex, join_path_native, stream_copy

from .util import get_object_type_by_name


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

from typing import Any, TYPE_CHECKING, Union
Expand All @@ -24,16 +26,14 @@
from git.refs.reference import Reference
from git.repo import Repo

from .tree import Tree
from .blob import Blob
from .submodule.base import Submodule
from .tree import Tree

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

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

__all__ = ("Object", "IndexObject")


class Object(LazyMixin):
"""Base class for classes representing git object types.
Expand Down
6 changes: 3 additions & 3 deletions git/objects/blob.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__ = ("Blob",)

from mimetypes import guess_type
import sys

from . import base

if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal

__all__ = ("Blob",)
from . import base


class Blob(base.IndexObject):
Expand Down
9 changes: 5 additions & 4 deletions git/objects/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

__all__ = ("Commit",)

from collections import defaultdict
import datetime
from io import BytesIO
Expand All @@ -14,10 +16,12 @@
from time import altzone, daylight, localtime, time, timezone

from gitdb import IStream

from git.cmd import Git
from git.diff import Diffable
from git.util import hex_to_bin, Actor, Stats, finalize_process
from git.util import Actor, Stats, finalize_process, hex_to_bin

from . import base
from .tree import Tree
from .util import (
Serializable,
Expand All @@ -27,7 +31,6 @@
parse_actor_and_date,
parse_date,
)
from . import base

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

Expand Down Expand Up @@ -59,8 +62,6 @@

_logger = logging.getLogger(__name__)

__all__ = ("Commit",)


class Commit(base.Object, TraversableIterableObj, Diffable, Serializable):
"""Wraps a git commit object.
Expand Down
19 changes: 9 additions & 10 deletions git/objects/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@

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

from stat import S_ISDIR
__all__ = (
"tree_to_stream",
"tree_entries_from_data",
"traverse_trees_recursive",
"traverse_tree_recursive",
)

from stat import S_ISDIR

from git.compat import safe_decode, defenc

Expand All @@ -23,22 +29,15 @@

if TYPE_CHECKING:
from _typeshed import ReadableBuffer

from git import GitCmdObjectDB

EntryTup = Tuple[bytes, int, str] # same as TreeCacheTup in tree.py
EntryTup = Tuple[bytes, int, str] # Same as TreeCacheTup in tree.py.
EntryTupOrNone = Union[EntryTup, None]

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


__all__ = (
"tree_to_stream",
"tree_entries_from_data",
"traverse_trees_recursive",
"traverse_tree_recursive",
)


def tree_to_stream(entries: Sequence[EntryTup], write: Callable[["ReadableBuffer"], Union[int, None]]) -> None:
"""Write the given list of entries into a stream using its ``write`` method.

Expand Down
9 changes: 5 additions & 4 deletions git/objects/submodule/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
from git.types import PathLike

if TYPE_CHECKING:
from .base import Submodule
from weakref import ReferenceType

from git.refs import Head, RemoteReference
from git.remote import Remote
from git.repo import Repo
from git.refs import Head
from git import Remote
from git.refs import RemoteReference

from .base import Submodule

# { Utilities

Expand Down
14 changes: 10 additions & 4 deletions git/objects/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
For lightweight tags, see the :mod:`git.refs.tag` module.
"""

__all__ = ("TagObject",)

import sys

from git.compat import defenc
from git.util import hex_to_bin

from . import base
from .util import get_object_type_by_name, parse_actor_and_date
from ..util import hex_to_bin
from ..compat import defenc

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

from typing import List, TYPE_CHECKING, Union

Expand All @@ -26,11 +31,12 @@
if TYPE_CHECKING:
from git.repo import Repo
from git.util import Actor
from .commit import Commit

from .blob import Blob
from .commit import Commit
from .tree import Tree

__all__ = ("TagObject",)
# ---------------------------------------------------


class TagObject(base.Object):
Expand Down
9 changes: 4 additions & 5 deletions git/objects/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

__all__ = ("TreeModifier", "Tree")

import sys

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

from . import util
from .base import IndexObjUnion, IndexObject
from .blob import Blob
from .fun import tree_entries_from_data, tree_to_stream
from .submodule.base import Submodule
from . import util

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

Expand All @@ -39,23 +41,20 @@

if TYPE_CHECKING:
from io import BytesIO

from git.repo import Repo

TreeCacheTup = Tuple[bytes, int, str]

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


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

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


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

__all__ = ("TreeModifier", "Tree")


class TreeModifier:
"""A utility class providing methods to alter the underlying cache in a list-like
Expand Down
49 changes: 26 additions & 23 deletions git/objects/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,63 @@

"""General utility functions."""

__all__ = (
"get_object_type_by_name",
"parse_date",
"parse_actor_and_date",
"ProcessStreamAdapter",
"Traversable",
"altz_to_utctz_str",
"utctz_to_altz",
"verify_utctz",
"Actor",
"tzoffset",
"utc",
)

from abc import ABC, abstractmethod
import calendar
from collections import deque
from datetime import datetime, timedelta, tzinfo
from string import digits
import re
from string import digits
import time
import warnings

from git.util import IterableList, IterableObj, Actor
from git.util import Actor, IterableList, IterableObj

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

from typing import (
Any,
Callable,
Deque,
Iterator,
# Generic,
Iterator,
NamedTuple,
overload,
Sequence,
TYPE_CHECKING,
Tuple,
Type,
TypeVar,
Union,
cast,
overload,
)

from git.types import Has_id_attribute, Literal # , _T

if TYPE_CHECKING:
from io import BytesIO, StringIO
from .commit import Commit
from .blob import Blob
from .tag import TagObject
from .tree import Tree, TraversedTreeTup
from subprocess import Popen
from .submodule.base import Submodule

from git.types import Protocol, runtime_checkable

from .blob import Blob
from .commit import Commit
from .submodule.base import Submodule
from .tag import TagObject
from .tree import TraversedTreeTup, Tree
else:
# Protocol = Generic[_T] # Needed for typing bug #572?
Protocol = ABC
Expand All @@ -68,20 +85,6 @@ class TraverseNT(NamedTuple):

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

__all__ = (
"get_object_type_by_name",
"parse_date",
"parse_actor_and_date",
"ProcessStreamAdapter",
"Traversable",
"altz_to_utctz_str",
"utctz_to_altz",
"verify_utctz",
"Actor",
"tzoffset",
"utc",
)

ZERO = timedelta(0)

# { Functions
Expand Down