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.refs submodules
  • Loading branch information
EliahKagan committed Mar 18, 2024
commit 8b51af36a4943f75fb66d553d55e381859fe3a34
12 changes: 6 additions & 6 deletions git/refs/head.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
Note the distinction between the :class:`HEAD` and :class:`Head` classes.
"""

__all__ = ["HEAD", "Head"]

from git.config import GitConfigParser, SectionConstraint
from git.util import join_path
from git.exc import GitCommandError
from git.util import join_path

from .symbolic import SymbolicReference
from .reference import Reference
from .symbolic import SymbolicReference

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

Expand All @@ -26,8 +28,6 @@

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

__all__ = ["HEAD", "Head"]


def strip_quotes(string: str) -> str:
if string.startswith('"') and string.endswith('"'):
Expand All @@ -36,8 +36,8 @@ def strip_quotes(string: str) -> str:


class HEAD(SymbolicReference):
"""Special case of a SymbolicReference representing the repository's HEAD
reference."""
"""Special case of a :class:`~git.refs.symbolic.SymbolicReference` representing the
repository's HEAD reference."""

_HEAD_NAME = "HEAD"
_ORIG_HEAD_NAME = "ORIG_HEAD"
Expand Down
17 changes: 8 additions & 9 deletions git/refs/log.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

__all__ = ["RefLog", "RefLogEntry"]

from mmap import mmap
import os.path as osp
import re
import time as _time

from git.compat import defenc
from git.objects.util import (
parse_date,
Serializable,
altz_to_utctz_str,
parse_date,
)
from git.util import (
Actor,
LockedFD,
LockFile,
assure_directory_exists,
to_native_path,
bin_to_hex,
file_contents_ro_filepath,
to_native_path,
)

import os.path as osp


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

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

from git.types import PathLike

if TYPE_CHECKING:
from io import BytesIO
from git.refs import SymbolicReference

from git.config import GitConfigParser, SectionConstraint
from git.refs import SymbolicReference

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

__all__ = ["RefLog", "RefLogEntry"]


class RefLogEntry(Tuple[str, str, Actor, Tuple[int, int], str]):
"""Named tuple allowing easy access to the revlog data fields."""
Expand Down
9 changes: 5 additions & 4 deletions git/refs/reference.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

__all__ = ["Reference"]

from git.util import IterableObj, LazyMixin

from .symbolic import SymbolicReference, T_References

# typing ------------------------------------------------------------------
Expand All @@ -15,8 +18,6 @@

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

__all__ = ["Reference"]

# { Utilities


Expand All @@ -34,7 +35,7 @@ def wrapper(self: T_References, *args: Any) -> _T:
return wrapper


# }END utilities
# } END utilities


class Reference(SymbolicReference, LazyMixin, IterableObj):
Expand Down Expand Up @@ -142,7 +143,7 @@ def iter_items(
but will return non-detached references as well."""
return cls._iter_items(repo, common_path)

# }END interface
# } END interface

# { Remote Interface

Expand Down
11 changes: 5 additions & 6 deletions git/refs/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@

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

__all__ = ["RemoteReference"]

import os

from git.util import join_path

from .head import Head


__all__ = ["RemoteReference"]

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

from typing import Any, Iterator, NoReturn, Union, TYPE_CHECKING
from git.types import PathLike
from typing import Any, Iterator, NoReturn, TYPE_CHECKING, Union

from git.types import PathLike

if TYPE_CHECKING:
from git.remote import Remote
from git.repo import Repo
from git import Remote

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

Expand Down
11 changes: 6 additions & 5 deletions git/refs/symbolic.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

__all__ = ["SymbolicReference"]

import os

from gitdb.exc import BadName, BadObject

from git.compat import defenc
from git.objects import Object
from git.objects.base import Object
from git.objects.commit import Commit
from git.refs.log import RefLog
from git.util import (
Expand All @@ -15,7 +19,6 @@
join_path_native,
to_native_path_linux,
)
from gitdb.exc import BadName, BadObject

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

Expand All @@ -30,6 +33,7 @@
Union,
cast,
)

from git.types import AnyGitObject, PathLike

if TYPE_CHECKING:
Expand All @@ -45,9 +49,6 @@
# ------------------------------------------------------------------------------


__all__ = ["SymbolicReference"]


def _git_dir(repo: "Repo", path: Union[PathLike, None]) -> PathLike:
"""Find the git dir that is appropriate for the path."""
name = f"{path}"
Expand Down
8 changes: 3 additions & 5 deletions git/refs/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,21 @@
:mod:`git.objects.tag` module.
"""

from .reference import Reference

__all__ = ["TagReference", "Tag"]

from .reference import Reference

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

from typing import Any, TYPE_CHECKING, Type, Union

from git.types import AnyGitObject, PathLike

if TYPE_CHECKING:
from git.objects import Commit
from git.objects import TagObject
from git.objects import Commit, TagObject
from git.refs import SymbolicReference
from git.repo import Repo


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


Expand Down