Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita05597a

Browse files
committed
Improve how imports and __all__ are written in git.util
+ Update the detailed comment about the unused import situation.
1 parentde540b7 commita05597a

File tree

1 file changed

+53
-49
lines changed

1 file changed

+53
-49
lines changed

‎git/util.py

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,32 @@
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+
importsys
7+
8+
__all__= [
9+
"stream_copy",
10+
"join_path",
11+
"to_native_path_linux",
12+
"join_path_native",
13+
"Stats",
14+
"IndexFileSHA1Writer",
15+
"IterableObj",
16+
"IterableList",
17+
"BlockingLockFile",
18+
"LockFile",
19+
"Actor",
20+
"get_user_id",
21+
"assure_directory_exists",
22+
"RemoteProgress",
23+
"CallableRemoteProgress",
24+
"rmtree",
25+
"unbare_repo",
26+
"HIDE_WINDOWS_KNOWN_ERRORS",
27+
]
28+
29+
ifsys.platform=="win32":
30+
__all__.append("to_native_path_windows")
31+
632
fromabcimportabstractmethod
733
importcontextlib
834
fromfunctoolsimportwraps
@@ -16,11 +42,27 @@
1642
importshutil
1743
importstat
1844
importsubprocess
19-
importsys
2045
importtime
2146
fromurllib.parseimporturlsplit,urlunsplit
2247
importwarnings
2348

49+
# NOTE: Unused imports can be improved now that CI testing has fully resumed. Some of
50+
# these be used indirectly through other GitPython modules, which avoids having to write
51+
# gitdb all the time in their imports. They are not in __all__, at least currently,
52+
# because they could be removed or changed at any time, and so should not be considered
53+
# conceptually public to code outside GitPython. Linters of course do not like it.
54+
fromgitdb.utilimport (# noqa: F401 # @IgnorePep8
55+
LazyMixin,# @UnusedImport
56+
LockedFD,# @UnusedImport
57+
bin_to_hex,# @UnusedImport
58+
file_contents_ro_filepath,# @UnusedImport
59+
file_contents_ro,# @UnusedImport
60+
hex_to_bin,# @UnusedImport
61+
make_sha,
62+
to_bin_sha,# @UnusedImport
63+
to_hex_sha,# @UnusedImport
64+
)
65+
2466
# typing ---------------------------------------------------------
2567

2668
fromtypingimport (
@@ -37,73 +79,36 @@
3779
Pattern,
3880
Sequence,
3981
Tuple,
82+
TYPE_CHECKING,
4083
TypeVar,
4184
Union,
42-
TYPE_CHECKING,
4385
cast,
4486
overload,
4587
)
4688

4789
ifTYPE_CHECKING:
90+
fromgit.cmdimportGit
91+
fromgit.configimportGitConfigParser,SectionConstraint
4892
fromgit.remoteimportRemote
4993
fromgit.repo.baseimportRepo
50-
fromgit.configimportGitConfigParser,SectionConstraint
51-
fromgitimportGit
5294

53-
from .typesimport (
95+
fromgit.typesimport (
96+
Files_TD,
97+
Has_id_attribute,
98+
HSH_TD,
5499
Literal,
55-
SupportsIndex,
56-
Protocol,
57-
runtime_checkable,# because behind py version guards
58100
PathLike,
59-
HSH_TD,
101+
Protocol,
102+
SupportsIndex,
60103
Total_TD,
61-
Files_TD,# aliases
62-
Has_id_attribute,
104+
runtime_checkable,
63105
)
64106

65107
# ---------------------------------------------------------------------
66108

67-
fromgitdb.utilimport (# noqa: F401 # @IgnorePep8
68-
make_sha,
69-
LockedFD,# @UnusedImport
70-
file_contents_ro,# @UnusedImport
71-
file_contents_ro_filepath,# @UnusedImport
72-
LazyMixin,# @UnusedImport
73-
to_hex_sha,# @UnusedImport
74-
to_bin_sha,# @UnusedImport
75-
bin_to_hex,# @UnusedImport
76-
hex_to_bin,# @UnusedImport
77-
)
78-
79109
T_IterableObj=TypeVar("T_IterableObj",bound=Union["IterableObj","Has_id_attribute"],covariant=True)
80110
# So IterableList[Head] is subtype of IterableList[IterableObj].
81111

82-
# NOTE: Some of the unused imports might be used/imported by others.
83-
# Handle once test-cases are back up and running.
84-
# Most of these are unused here, but are for use by git-python modules so these
85-
# don't see gitdb all the time. Flake of course doesn't like it.
86-
__all__= [
87-
"stream_copy",
88-
"join_path",
89-
"to_native_path_linux",
90-
"join_path_native",
91-
"Stats",
92-
"IndexFileSHA1Writer",
93-
"IterableObj",
94-
"IterableList",
95-
"BlockingLockFile",
96-
"LockFile",
97-
"Actor",
98-
"get_user_id",
99-
"assure_directory_exists",
100-
"RemoteProgress",
101-
"CallableRemoteProgress",
102-
"rmtree",
103-
"unbare_repo",
104-
"HIDE_WINDOWS_KNOWN_ERRORS",
105-
]
106-
107112
_logger=logging.getLogger(__name__)
108113

109114

@@ -292,7 +297,6 @@ def to_native_path_linux(path: PathLike) -> str:
292297
path=str(path)
293298
returnpath.replace("\\","/")
294299

295-
__all__.append("to_native_path_windows")
296300
to_native_path=to_native_path_windows
297301
else:
298302
# No need for any work on Linux.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp