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
Pick a consistent type for __all__ (for now, list)
This makes all __all__ everywhere in the git package lists. Before,
roughly half were lists and half were tuples. There are reasonable
theoretical arguments for both, and in practice all tools today
support both. Traditionally using a list is far more common, and it
remains at least somewhat more common. Furthermore, git/util.py
uses a list and is currently written to append an element to it
that is conditionally defined on Windows (though it would probably
be fine for that to be the only list, since it reflects an actual
relevant difference about it).

The goal here is just to remove inconsistency that does not signify
anything and is the result of drift over time. If a reason (even
preference) arises to make them all tuples in the future, then that
is also probably fine.
  • Loading branch information
EliahKagan committed Mar 19, 2024
commit 78055a8b8473a25e8f36a3846b920a698e8ba66b
2 changes: 1 addition & 1 deletion git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from __future__ import annotations

__all__ = ("Git",)
__all__ = ["Git"]

import contextlib
import io
Expand Down
2 changes: 1 addition & 1 deletion git/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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

__all__ = ("GitConfigParser", "SectionConstraint")
__all__ = ["GitConfigParser", "SectionConstraint"]

import abc
import configparser as cp
Expand Down
2 changes: 1 addition & 1 deletion git/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

__all__ = ("GitCmdObjectDB", "GitDB")
__all__ = ["GitCmdObjectDB", "GitDB"]

from gitdb.base import OInfo, OStream
from gitdb.db import GitDB, LooseObjectDB
Expand Down
2 changes: 1 addition & 1 deletion git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# 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")
__all__ = ["DiffConstants", "NULL_TREE", "INDEX", "Diffable", "DiffIndex", "Diff"]

import enum
import re
Expand Down
2 changes: 1 addition & 1 deletion git/index/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""Module containing :class:`IndexFile`, an Index implementation facilitating all kinds
of index manipulations such as querying and merging."""

__all__ = ("IndexFile", "CheckoutError", "StageType")
__all__ = ["IndexFile", "CheckoutError", "StageType"]

import contextlib
import datetime
Expand Down
4 changes: 2 additions & 2 deletions git/index/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""Standalone functions to accompany the index implementation and make it more
versatile."""

__all__ = (
__all__ = [
"write_cache",
"read_cache",
"write_tree_from_cache",
Expand All @@ -13,7 +13,7 @@
"S_IFGITLINK",
"run_commit_hook",
"hook_path",
)
]

from io import BytesIO
import os
Expand Down
2 changes: 1 addition & 1 deletion git/index/typ.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"""Additional types used by the index."""

__all__ = ("BlobFilter", "BaseIndexEntry", "IndexEntry", "StageType")
__all__ = ["BlobFilter", "BaseIndexEntry", "IndexEntry", "StageType"]

from binascii import b2a_hex
from pathlib import Path
Expand Down
2 changes: 1 addition & 1 deletion git/index/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"""Index utilities."""

__all__ = ("TemporaryFileSwap", "post_clear_cache", "default_index", "git_working_dir")
__all__ = ["TemporaryFileSwap", "post_clear_cache", "default_index", "git_working_dir"]

import contextlib
from functools import wraps
Expand Down
2 changes: 1 addition & 1 deletion git/objects/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

__all__ = ("Object", "IndexObject")
__all__ = ["Object", "IndexObject"]

import os.path as osp

Expand Down
2 changes: 1 addition & 1 deletion git/objects/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

__all__ = ("Blob",)
__all__ = ["Blob"]

from mimetypes import guess_type
import sys
Expand Down
2 changes: 1 addition & 1 deletion git/objects/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

__all__ = ("Commit",)
__all__ = ["Commit"]

from collections import defaultdict
import datetime
Expand Down
4 changes: 2 additions & 2 deletions git/objects/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

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

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

from stat import S_ISDIR

Expand Down
4 changes: 2 additions & 2 deletions git/objects/submodule/util.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

__all__ = (
__all__ = [
"sm_section",
"sm_name",
"mkhead",
"find_first_remote_branch",
"SubmoduleConfigParser",
)
]

from io import BytesIO
import weakref
Expand Down
2 changes: 1 addition & 1 deletion git/objects/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
For lightweight tags, see the :mod:`git.refs.tag` module.
"""

__all__ = ("TagObject",)
__all__ = ["TagObject"]

import sys

Expand Down
2 changes: 1 addition & 1 deletion git/objects/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# 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")
__all__ = ["TreeModifier", "Tree"]

import sys

Expand Down
4 changes: 2 additions & 2 deletions git/objects/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"""Utility functions for working with git objects."""

__all__ = (
__all__ = [
"get_object_type_by_name",
"parse_date",
"parse_actor_and_date",
Expand All @@ -17,7 +17,7 @@
"Actor",
"tzoffset",
"utc",
)
]

from abc import ABC, abstractmethod
import calendar
Expand Down
2 changes: 1 addition & 1 deletion git/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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

__all__ = ("RemoteProgress", "PushInfo", "FetchInfo", "Remote")
__all__ = ["RemoteProgress", "PushInfo", "FetchInfo", "Remote"]

import contextlib
import logging
Expand Down
2 changes: 1 addition & 1 deletion git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from __future__ import annotations

__all__ = ("Repo",)
__all__ = ["Repo"]

import gc
import logging
Expand Down
4 changes: 2 additions & 2 deletions git/repo/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from __future__ import annotations

__all__ = (
__all__ = [
"rev_parse",
"is_git_dir",
"touch",
Expand All @@ -15,7 +15,7 @@
"deref_tag",
"to_commit",
"find_worktree_git_dir",
)
]

import os
import os.path as osp
Expand Down