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

Commit7545b80

Browse files
committed
Add __all__ in git.exc, adjust __init__.py imports
The git.exc module imports exceptions from gitdb.exc to republishthem, as well as defining its own (also for use from outside). Butbecause it did not define __all__, the intent for the exceptions itimported was unclear, since names that are introduced by importsand not present in __all__ are not generally considered public,even when __all__ is absent and a "*" import would reimport them.This rectifies that by adding __all__ and listing both imported andnewly introduced exceptions explicitly in it. Although thisstrictly expands which names are public under typical conventions,it strictly contracts which names are imported by a "*" import,because the presence of __all__ suppresses names not listed in itfrom being imported that way. However, because under typicalconventions those other names are not considered public, and theywere not even weakly documented as public, this should be okay.(Even though this is not a breaking change, in that code it wouldbreak would already technically be broken... if it turns out thatit is common to wrongly rely on the availabiliy of those names,then this may need to be revisited and slightly modified.)This brings the readily identified public interface of git.exc inline with what is weakly implied (and intended) by its docstring.This also modifies __init__.py accordingly: The top-level gitmodule has for some time used a "*" import on git.exc, causingthe extra names originally meant as implementation details to beincluded. Because its own __all__ was dynamically generated untilc862845,#1659 also added8edc53b to retain the formerly presentnames in __all__. So the change here imports those names from themodules that deliberately provide them, to preserve compatibility.
1 parent8197e90 commit7545b80

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

‎git/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
# @PydevCodeAnalysisIgnore
88
fromgit.excimport*# @NoMove @IgnorePep8
99
importos
10-
importsys
1110
importos.pathasosp
11+
importsys
1212

13-
fromtypingimportOptional
13+
fromtypingimportList,Optional,Sequence,Tuple,Union,TYPE_CHECKING
1414
fromgit.typesimportPathLike
1515

1616
__version__="git"
@@ -38,7 +38,10 @@ def _init_externals() -> None:
3838

3939
# { Imports
4040

41+
fromgitdb.utilimportto_hex_sha
42+
4143
try:
44+
fromgit.compatimportsafe_decode# @NoMove @IgnorePep8
4245
fromgit.configimportGitConfigParser# @NoMove @IgnorePep8
4346
fromgit.objectsimport*# @NoMove @IgnorePep8
4447
fromgit.refsimport*# @NoMove @IgnorePep8
@@ -53,6 +56,7 @@ def _init_externals() -> None:
5356
BlockingLockFile,
5457
Stats,
5558
Actor,
59+
remove_password_if_present,
5660
rmtree,
5761
)
5862
exceptGitErroras_exc:

‎git/exc.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,34 @@
55
# the BSD License: https://opensource.org/license/bsd-3-clause/
66
""" Module containing all exceptions thrown throughout the git package """
77

8-
fromgitdb.excimport (# noqa: @UnusedImport
8+
__all__= [
9+
# Defined in gitdb.exc:
10+
"AmbiguousObjectName",
11+
"BadName",
12+
"BadObject",
13+
"BadObjectType",
14+
"InvalidDBRoot",
15+
"ODBError",
16+
"ParseError",
17+
"UnsupportedOperation",
18+
# Introduced in this module:
19+
"GitError",
20+
"InvalidGitRepositoryError",
21+
"WorkTreeRepositoryUnsupported",
22+
"NoSuchPathError",
23+
"UnsafeProtocolError",
24+
"UnsafeOptionError",
25+
"CommandError",
26+
"GitCommandNotFound",
27+
"GitCommandError",
28+
"CheckoutError",
29+
"CacheError",
30+
"UnmergedEntriesError",
31+
"HookExecutionError",
32+
"RepositoryDirtyError",
33+
]
34+
35+
fromgitdb.excimport (
936
AmbiguousObjectName,
1037
BadName,
1138
BadObject,
@@ -14,7 +41,6 @@
1441
ODBError,
1542
ParseError,
1643
UnsupportedOperation,
17-
to_hex_sha,
1844
)
1945
fromgit.compatimportsafe_decode
2046
fromgit.utilimportremove_password_if_present

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp