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

Commitfc86a23

Browse files
committed
Incompletely change git.index imports to test modattrs.py
This also checks if the regression tests in test_imports.py work.This replaces wildcard imports in git.index with explicit imports,and adds git.index.__all__. But this temporarily omits from it thepublic attributes of git.index that name its Python submodules andare thus are present as an indirect effect of importing names*from* them (since doing so also imports them).This partial change, until it is completed in the next commit,represents the kind of bug that modattrs.py seeks to safeguardagainst, and verifies that a diff between old and current output ofmodattrs.py clearly shows it. This diff is temporarily included asab.diff, which will be deleted in the next commit.The key problem that diff reveals is the changed value of the utilattribute of the top-level git module. Due to the way wildcardimports have been used within GitPython for its own modules,expressions like `git.util` (where `git` is the top-level gitmodule) and imports like `from git import util` are actuallyreferring to git.index.util, rather than the util Python submoduleof the git module (conceptually git.util), which can only beaccessed via `from git.util import ...` or in `sys.modules`.Although this is not an inherently good situation, in practice ithas to be maintained at least until the next major version, becausereasonable code that uses GitPython would be broken if thesituation were changed to be more intuitive.But the more intuitive behavior automatically happens if wildcardimports are replaced with explicit imports of the names they hadoriginally intended to import (in this case, in the top-level gitmodule, which has not yet been done but will be), or if __all__ isadded where helpful (in this case, in git.index, which this does).Adding the names explicitly is sufficient to restore the oldbehavior that is needed for backward compatibility, and has thefurther advantage that the unintuitive behavior will be explicitonce all wildcard imports are replaced and __all__ is added to eachmodule where it would be helpful. The modattrs.py script serves toensure incompatible changes are not made; this commit checks it.The tests in test_imports.py also cover this specific anticipatedincompatibility in git.util, but not all breakages that may arisewhen refactoring imports and that diff-ing modattrs.py output wouldhelp catch.
1 parent5b2771d commitfc86a23

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

‎ab.diff

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
diff --git a/a b/b
2+
index 81b3f984..7b8c8ede 100644
3+
--- a/a
4+
+++ b/b
5+
@@ -83,14 +83,12 @@ git:
6+
__path__: ['C:\\Users\\ek\\source\\repos\\GitPython\\git']
7+
__spec__: ModuleSpec(name='git', loader=<_frozen_importlib_external.SourceFileLoader object at 0x...>, origin='C:\\Users\\ek\\source\\repos\\GitPython\\git\\__init__.py', submodule_search_locations=['C:\\Users\\ek\\source\\repos\\GitPython\\git'])
8+
__version__: 'git'
9+
- base: <module 'git.index.base' from 'C:\\Users\\ek\\source\\repos\\GitPython\\git\\index\\base.py'>
10+
cmd: <module 'git.cmd' from 'C:\\Users\\ek\\source\\repos\\GitPython\\git\\cmd.py'>
11+
compat: <module 'git.compat' from 'C:\\Users\\ek\\source\\repos\\GitPython\\git\\compat.py'>
12+
config: <module 'git.config' from 'C:\\Users\\ek\\source\\repos\\GitPython\\git\\config.py'>
13+
db: <module 'git.db' from 'C:\\Users\\ek\\source\\repos\\GitPython\\git\\db.py'>
14+
diff: <module 'git.diff' from 'C:\\Users\\ek\\source\\repos\\GitPython\\git\\diff.py'>
15+
exc: <module 'git.exc' from 'C:\\Users\\ek\\source\\repos\\GitPython\\git\\exc.py'>
16+
- fun: <module 'git.index.fun' from 'C:\\Users\\ek\\source\\repos\\GitPython\\git\\index\\fun.py'>
17+
head: <module 'git.refs.head' from 'C:\\Users\\ek\\source\\repos\\GitPython\\git\\refs\\head.py'>
18+
index: <module 'git.index' from 'C:\\Users\\ek\\source\\repos\\GitPython\\git\\index\\__init__.py'>
19+
log: <module 'git.refs.log' from 'C:\\Users\\ek\\source\\repos\\GitPython\\git\\refs\\log.py'>
20+
@@ -106,9 +104,8 @@ git:
21+
symbolic: <module 'git.refs.symbolic' from 'C:\\Users\\ek\\source\\repos\\GitPython\\git\\refs\\symbolic.py'>
22+
tag: <module 'git.refs.tag' from 'C:\\Users\\ek\\source\\repos\\GitPython\\git\\refs\\tag.py'>
23+
to_hex_sha: <function to_hex_sha at 0x...>
24+
- typ: <module 'git.index.typ' from 'C:\\Users\\ek\\source\\repos\\GitPython\\git\\index\\typ.py'>
25+
types: <module 'git.types' from 'C:\\Users\\ek\\source\\repos\\GitPython\\git\\types.py'>
26+
- util: <module 'git.index.util' from 'C:\\Users\\ek\\source\\repos\\GitPython\\git\\index\\util.py'>
27+
+ util: <module 'git.util' from 'C:\\Users\\ek\\source\\repos\\GitPython\\git\\util.py'>
28+
29+
30+
git.cmd:

‎git/index/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,14 @@
33

44
"""Initialize the index package."""
55

6-
from .baseimport*# noqa: F401 F403
7-
from .typimport*# noqa: F401 F403
6+
__all__= [
7+
"BaseIndexEntry",
8+
"BlobFilter",
9+
"CheckoutError",
10+
"IndexEntry",
11+
"IndexFile",
12+
"StageType",
13+
]
14+
15+
from .baseimportCheckoutError,IndexFile
16+
from .typimportBaseIndexEntry,BlobFilter,IndexEntry,StageType

‎git/index/base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"""Module containing :class:`IndexFile`, an Index implementation facilitating all kinds
77
of index manipulations such as querying and merging."""
88

9+
__all__= ("IndexFile","CheckoutError","StageType")
10+
911
importcontextlib
1012
importdatetime
1113
importglob
@@ -81,9 +83,6 @@
8183
# ------------------------------------------------------------------------------------
8284

8385

84-
__all__= ("IndexFile","CheckoutError","StageType")
85-
86-
8786
@contextlib.contextmanager
8887
def_named_temporary_file_for_subprocess(directory:PathLike)->Generator[str,None,None]:
8988
"""Create a named temporary file git subprocesses can open, deleting it afterward.

‎git/index/typ.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33

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

6+
__all__= ("BlobFilter","BaseIndexEntry","IndexEntry","StageType")
7+
68
frombinasciiimportb2a_hex
79
frompathlibimportPath
810

911
from .utilimportpack,unpack
1012
fromgit.objectsimportBlob
1113

12-
1314
# typing ----------------------------------------------------------------------
1415

1516
fromtypingimportNamedTuple,Sequence,TYPE_CHECKING,Tuple,Union,cast
@@ -23,8 +24,6 @@
2324

2425
# ---------------------------------------------------------------------------------
2526

26-
__all__= ("BlobFilter","BaseIndexEntry","IndexEntry","StageType")
27-
2827
# { Invariants
2928
CE_NAMEMASK=0x0FFF
3029
CE_STAGEMASK=0x3000

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp