-
-
Notifications
You must be signed in to change notification settings - Fork 939
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
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 5b2771d
Add regression tests of the git.util aliasing situation
EliahKagan fc86a23
Incompletely change git.index imports to test modattrs.py
EliahKagan 4badc19
Fix git.index imports
EliahKagan 1c9bda2
Improve relative order of import groups, and __all__, in git.index
EliahKagan 8b51af3
Improve order of imports and __all__ in git.refs submodules
EliahKagan b25dd7e
Replace wildcard imports in git.refs
EliahKagan b32ef65
Improve order of imports and __all__ in git.repo submodules
EliahKagan 0ba06e9
Add git.repo.__all__ and make submodules explicit
EliahKagan c946906
Improve order of imports and __all__ in git.objects.*
EliahKagan 4e9a2f2
Improve order of imports and __all__ in git.object.submodule.*
EliahKagan c58be4c
Remove a bit of old commented-out code in git.objects.*
EliahKagan 01c95eb
Don't patch IndexObject and Object into git.objects.submodule.util
EliahKagan f89d065
Fix git.objects.__all__ and make submodules explicit
EliahKagan 3786307
Make git.objects.util module docstring more specific
EliahKagan de540b7
Add __all__ and imports in git.objects.submodule
EliahKagan a05597a
Improve how imports and __all__ are written in git.util
EliahKagan 2053a3d
Remove old commented-out change_type assertions in git.diff
EliahKagan b8bab43
Remove old commented-out flagKeyLiteral assertions in git.remote
EliahKagan 3d4e476
Improve how second-level imports and __all__ are written
EliahKagan 6318eea
Make F401 "unused import" suppressions more specific
EliahKagan 31bc8a4
Remove unneeded F401 "Unused import" suppressions
EliahKagan abbe74d
Fix a tiny import sorting nit
EliahKagan 7745250
Replace wildcard imports in top-level git module
EliahKagan 64c9efd
Restore relative order to fix circular import error
EliahKagan 31f89a1
Add the nonpublic indirect submodule aliases back for now
EliahKagan 9bbbcb5
Further improve git.objects.util module docstring
EliahKagan 00f4cbc
Add missing submodule imports in git.objects
EliahKagan fcc7418
Don't explicitly list direct submodules in __all__
EliahKagan 78055a8
Pick a consistent type for __all__ (for now, list)
EliahKagan ecdb6aa
Save diff of non-__all__ attributes across import changes
EliahKagan f705fd6
Remove modattrs.py and related
EliahKagan 4a4d880
Improve test suite import grouping/sorting, __all__ placement
EliahKagan d524c76
Fix slightly unsorted imports in setup.py
EliahKagan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add regression tests of the git.util aliasing situation
Although this situation is not inherently desirable, for backward compatibility it cannot change at this time. It may be possible to change it in the next major version of GitPython, but even then it should not be changed accidentally, which can easily happen while refactoring imports. This tests the highest-risk accidental change (of those that are currently known) of the kind that the temporary modattrs.py script exists to help safeguard against. That script will be removed when the immediately forthcoming import refactoring is complete, whereas these test cases can be kept. For information about the specific situation this helps ensure isn't changed accidentally, see the new test cases' docstrings, as well as the next commit (which will test modattrs.py and these test cases by performing an incomplete change that would be a bug until completed). This commit adds three test cases. The first tests the unintuitive aspect of the current situation: - test_git_util_attribute_is_git_index_util The other two test the intuitive aspects of it, i.e., they test that changes (perhaps in an attempt to preserve the aspect needed for backward compatibility) do not make `git.util` unusual in new (and themselves incompatible) ways: - test_git_index_util_attribute_is_git_index_util - test_separate_git_util_module_exists The latter tests should also clarify, for readers of the tests, the limited nature of the condition the first test asserts.
- Loading branch information
commit 5b2771d23af2156fb7e12ee6406bffbabcb9e95d
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# This module is part of GitPython and is released under the | ||
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/ | ||
|
||
import sys | ||
|
||
import git | ||
|
||
|
||
def test_git_util_attribute_is_git_index_util(): | ||
"""The top-level module's ``util`` attribute is really :mod:`git.index.util`. | ||
|
||
Although this situation is unintuitive and not a design goal, this has historically | ||
been the case, and it should not be changed without considering the effect on | ||
backward compatibility. In practice, it cannot be changed at least until the next | ||
major version of GitPython. This test checks that it is not accidentally changed, | ||
which could happen when refactoring imports. | ||
""" | ||
assert git.util is git.index.util | ||
|
||
|
||
def test_git_index_util_attribute_is_git_index_util(): | ||
"""Nothing unusual is happening with git.index.util itself.""" | ||
assert git.index.util is sys.modules["git.index.util"] | ||
|
||
|
||
def test_separate_git_util_module_exists(): | ||
"""The real git.util and git.index.util modules really are separate. | ||
|
||
The real git.util module can be accessed to import a name ``...` by writing | ||
``from git.util import ...``, and the module object can be accessed in sys.modules. | ||
""" | ||
assert sys.modules["git.util"] is not sys.modules["git.index.util"] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.