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

Commitd70ba69

Browse files
committed
Extract all "import gc" to module level
The gc module was already imported at module scope ingit/repo/base.py, sincef1a82e4 (#555). Importing the top-levelgit module or any submodule of it runs that import statement.Because the gc module is already imported, reimporting it is fast.Imports that there is no specific reason to do locally should be atmodule scope. Having them local decreased readability, in partbecause of how black inserts a black line between them andgc.collect() calls they are imported to allow.An alternative to this change would be to remove the preexistingtop-level "import gc" (there is also another one in the test suite)and replace it with a local import as well. I am unsure if thatwould affect performance and, if so, whether the effect would begood or bad, since the small delay of the import might potentiallybe less desirable to an applicaion if it occurs while the work ofthe application is already in progress.If a gc.collect() call runs as a consequence of a finally block or__del__ method being called during interpreter shutdown, then in(very) rare cases the variable may have been set to None. But thisdoes not appear to have been the intent behind making the importslocal. More importantly, a local import should not be expected tosucceed, or the imported module usable, in such a situation.
1 parent68272aa commitd70ba69

File tree

10 files changed

+11
-20
lines changed

10 files changed

+11
-20
lines changed

‎git/objects/submodule/base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# This module is part of GitPython and is released under the
22
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
33

4+
importgc
45
fromioimportBytesIO
56
importlogging
67
importos
@@ -1079,8 +1080,6 @@ def remove(
10791080
self._clear_cache()
10801081
wtd=mod.working_tree_dir
10811082
delmod# Release file-handles (Windows).
1082-
importgc
1083-
10841083
gc.collect()
10851084
rmtree(str(wtd))
10861085
# END delete tree if possible

‎test/performance/test_commit.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
"""Performance tests for commits (iteration, traversal, and serialization)."""
77

8+
importgc
89
fromioimportBytesIO
910
fromtimeimporttime
1011
importsys
@@ -17,8 +18,6 @@
1718

1819
classTestPerformance(TestBigRepoRW,TestCommitSerialization):
1920
deftearDown(self):
20-
importgc
21-
2221
gc.collect()
2322

2423
# ref with about 100 commits in its history.

‎test/performance/test_streams.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
"""Performance tests for data streaming."""
55

6+
importgc
67
importos
78
importsubprocess
89
importsys
@@ -92,8 +93,6 @@ def test_large_data_streaming(self, rwrepo):
9293

9394
# del db file so git has something to do.
9495
ostream=None
95-
importgc
96-
9796
gc.collect()
9897
os.remove(db_file)
9998

‎test/test_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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+
importgc
67
importos
78
importsys
89
importtempfile
@@ -20,8 +21,6 @@
2021

2122
classTestBase(_TestBase):
2223
deftearDown(self):
23-
importgc
24-
2524
gc.collect()
2625

2726
type_tuples= (

‎test/test_docs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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+
importgc
67
importos
78
importsys
89

@@ -16,8 +17,6 @@
1617

1718
classTutorials(TestBase):
1819
deftearDown(self):
19-
importgc
20-
2120
gc.collect()
2221

2322
# ACTUALLY skipped by git.util.rmtree (in local onerror function), from the last call to it via

‎test/test_git.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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+
importgc
67
importinspect
78
importlogging
89
importos
@@ -34,8 +35,6 @@ def setUpClass(cls):
3435
cls.git=Git(cls.rorepo.working_dir)
3536

3637
deftearDown(self):
37-
importgc
38-
3938
gc.collect()
4039

4140
def_assert_logged_for_popen(self,log_watcher,name,value):

‎test/test_quick_doc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# This module is part of GitPython and is released under the
22
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
33

4+
importgc
5+
46
fromtest.libimportTestBase
57
fromtest.lib.helperimportwith_rw_directory
68

79

810
classQuickDoc(TestBase):
911
deftearDown(self):
10-
importgc
11-
1212
gc.collect()
1313

1414
@with_rw_directory

‎test/test_remote.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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+
importgc
67
importos
78
importos.pathasosp
89
frompathlibimportPath
@@ -105,8 +106,6 @@ def assert_received_message(self):
105106

106107
classTestRemote(TestBase):
107108
deftearDown(self):
108-
importgc
109-
110109
gc.collect()
111110

112111
def_print_fetchhead(self,repo):

‎test/test_repo.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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+
importgc
67
importglob
78
importio
89
fromioimportBytesIO
@@ -72,8 +73,6 @@ def tearDown(self):
7273
ifosp.isfile(lfp):
7374
raiseAssertionError("Previous TC left hanging git-lock file: {}".format(lfp))
7475

75-
importgc
76-
7776
gc.collect()
7877

7978
deftest_new_should_raise_on_invalid_repo_location(self):

‎test/test_submodule.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
33

44
importcontextlib
5+
importgc
56
importos
67
importos.pathasosp
78
frompathlibimportPath
@@ -61,8 +62,6 @@ def update(self, op, cur_count, max_count, message=""):
6162

6263
classTestSubmodule(TestBase):
6364
deftearDown(self):
64-
importgc
65-
6665
gc.collect()
6766

6867
k_subm_current="c15a6e1923a14bc760851913858a3942a4193cdb"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp