Skip to content

Commit c7f459f

Browse files
committed
src: No PyDev warnings
+ Mark all unused vars and other non-pep8 (PyDev) warnings + test_utils: + enable & fix forgotten IterableList looped path. + unittestize all assertions.
1 parent be44602 commit c7f459f

20 files changed

+129
-119
lines changed

Diff for: git/__init__.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This module is part of GitPython and is released under
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66
# flake8: noqa
7-
7+
#@PydevCodeAnalysisIgnore
88
import os
99
import sys
1010
import inspect
@@ -32,17 +32,17 @@ def _init_externals():
3232

3333
#{ Imports
3434

35-
from git.config import GitConfigParser
36-
from git.objects import *
37-
from git.refs import *
38-
from git.diff import *
39-
from git.exc import *
40-
from git.db import *
41-
from git.cmd import Git
42-
from git.repo import Repo
43-
from git.remote import *
44-
from git.index import *
45-
from git.util import (
35+
from git.config import GitConfigParser # @NoMove @IgnorePep8
36+
from git.objects import * # @NoMove @IgnorePep8
37+
from git.refs import * # @NoMove @IgnorePep8
38+
from git.diff import * # @NoMove @IgnorePep8
39+
from git.exc import * # @NoMove @IgnorePep8
40+
from git.db import * # @NoMove @IgnorePep8
41+
from git.cmd import Git # @NoMove @IgnorePep8
42+
from git.repo import Repo # @NoMove @IgnorePep8
43+
from git.remote import * # @NoMove @IgnorePep8
44+
from git.index import * # @NoMove @IgnorePep8
45+
from git.util import ( # @NoMove @IgnorePep8
4646
LockFile,
4747
BlockingLockFile,
4848
Stats,

Diff for: git/index/base.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def _delete_entries_cache(self):
170170

171171
def _deserialize(self, stream):
172172
"""Initialize this instance with index values read from the given stream"""
173-
self.version, self.entries, self._extension_data, conten_sha = read_cache(stream)
173+
self.version, self.entries, self._extension_data, conten_sha = read_cache(stream) # @UnusedVariable
174174
return self
175175

176176
def _entries_sorted(self):
@@ -404,7 +404,7 @@ def raise_exc(e):
404404
continue
405405
# END glob handling
406406
try:
407-
for root, dirs, files in os.walk(abs_path, onerror=raise_exc):
407+
for root, dirs, files in os.walk(abs_path, onerror=raise_exc): # @UnusedVariable
408408
for rela_file in files:
409409
# add relative paths only
410410
yield os.path.join(root.replace(rs, ''), rela_file)
@@ -599,7 +599,6 @@ def _store_path(self, filepath, fprogress):
599599
"""Store file at filepath in the database and return the base index entry
600600
Needs the git_working_dir decorator active ! This must be assured in the calling code"""
601601
st = os.lstat(filepath) # handles non-symlinks as well
602-
stream = None
603602
if S_ISLNK(st.st_mode):
604603
# in PY3, readlink is string, but we need bytes. In PY2, it's just OS encoded bytes, we assume UTF-8
605604
open_stream = lambda: BytesIO(force_bytes(os.readlink(filepath), encoding=defenc))

Diff for: git/index/fun.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def write_tree_from_cache(entries, odb, sl, si=0):
264264

265265
# enter recursion
266266
# ci - 1 as we want to count our current item as well
267-
sha, tree_entry_list = write_tree_from_cache(entries, odb, slice(ci - 1, xi), rbound + 1)
267+
sha, tree_entry_list = write_tree_from_cache(entries, odb, slice(ci - 1, xi), rbound + 1) # @UnusedVariable
268268
tree_items_append((sha, S_IFDIR, base))
269269

270270
# skip ahead

Diff for: git/objects/__init__.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,24 @@
33
"""
44
# flake8: noqa
55
from __future__ import absolute_import
6+
67
import inspect
8+
79
from .base import *
10+
from .blob import *
11+
from .commit import *
12+
from .submodule import util as smutil
13+
from .submodule.base import *
14+
from .submodule.root import *
15+
from .tag import *
16+
from .tree import *
817
# Fix import dependency - add IndexObject to the util module, so that it can be
918
# imported by the submodule.base
10-
from .submodule import util as smutil
1119
smutil.IndexObject = IndexObject
1220
smutil.Object = Object
1321
del(smutil)
14-
from .submodule.base import *
15-
from .submodule.root import *
1622

1723
# must come after submodule was made available
18-
from .tag import *
19-
from .blob import *
20-
from .commit import *
21-
from .tree import *
2224

2325
__all__ = [name for name, obj in locals().items()
2426
if not (name.startswith('_') or inspect.ismodule(obj))]

Diff for: git/objects/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self, repo, binsha):
4040
assert len(binsha) == 20, "Require 20 byte binary sha, got %r, len = %i" % (binsha, len(binsha))
4141

4242
@classmethod
43-
def new(cls, repo, id):
43+
def new(cls, repo, id): # @ReservedAssignment
4444
"""
4545
:return: New Object instance of a type appropriate to the object type behind
4646
id. The id of the newly created object will be a binsha even though

Diff for: git/objects/commit.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def _get_intermediate_items(cls, commit):
140140
def _set_cache_(self, attr):
141141
if attr in Commit.__slots__:
142142
# read the data in a chunk, its faster - then provide a file wrapper
143-
binsha, typename, self.size, stream = self.repo.odb.stream(self.binsha)
143+
binsha, typename, self.size, stream = self.repo.odb.stream(self.binsha) # @UnusedVariable
144144
self._deserialize(BytesIO(stream.read()))
145145
else:
146146
super(Commit, self)._set_cache_(attr)
@@ -267,7 +267,7 @@ def _iter_from_process_or_stream(cls, repo, proc_or_stream):
267267
hexsha = line.strip()
268268
if len(hexsha) > 40:
269269
# split additional information, as returned by bisect for instance
270-
hexsha, rest = line.split(None, 1)
270+
hexsha, _ = line.split(None, 1)
271271
# END handle extra info
272272

273273
assert len(hexsha) == 40, "Invalid line: %s" % hexsha

Diff for: git/refs/reference.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __str__(self):
5050

5151
#{ Interface
5252

53-
def set_object(self, object, logmsg=None):
53+
def set_object(self, object, logmsg=None): # @ReservedAssignment
5454
"""Special version which checks if the head-log needs an update as well
5555
:return: self"""
5656
oldbinsha = None

Diff for: git/refs/symbolic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def set_commit(self, commit, logmsg=None):
218218

219219
return self
220220

221-
def set_object(self, object, logmsg=None):
221+
def set_object(self, object, logmsg=None): # @ReservedAssignment
222222
"""Set the object we point to, possibly dereference our symbolic reference first.
223223
If the reference does not exist, it will be created
224224
@@ -229,7 +229,7 @@ def set_object(self, object, logmsg=None):
229229
:note: plain SymbolicReferences may not actually point to objects by convention
230230
:return: self"""
231231
if isinstance(object, SymbolicReference):
232-
object = object.object
232+
object = object.object # @ReservedAssignment
233233
# END resolve references
234234

235235
is_detached = True

Diff for: git/repo/fun.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def rev_parse(repo, rev):
284284
try:
285285
if token == "~":
286286
obj = to_commit(obj)
287-
for item in xrange(num):
287+
for _ in xrange(num):
288288
obj = obj.parents[0]
289289
# END for each history item to walk
290290
elif token == "^":

Diff for: git/test/lib/asserts.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
import stat
99

1010
from nose.tools import (
11-
assert_equal,
12-
assert_not_equal,
13-
assert_raises,
14-
raises,
15-
assert_true,
16-
assert_false
11+
assert_equal, # @UnusedImport
12+
assert_not_equal, # @UnusedImport
13+
assert_raises, # @UnusedImport
14+
raises, # @UnusedImport
15+
assert_true, # @UnusedImport
16+
assert_false # @UnusedImport
1717
)
1818

1919
try:
2020
from unittest.mock import patch
2121
except ImportError:
22-
from mock import patch
22+
from mock import patch # @NoMove @UnusedImport
2323

2424
__all__ = ['assert_instance_of', 'assert_not_instance_of',
2525
'assert_none', 'assert_not_none',

Diff for: git/test/performance/test_streams.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def test_large_data_streaming(self, rwrepo):
120120

121121
# read all
122122
st = time()
123-
s, t, size, data = rwrepo.git.get_object_data(gitsha)
123+
hexsha, otype, size, data = rwrepo.git.get_object_data(gitsha) # @UnusedVariable
124124
gelapsed_readall = time() - st
125125
print("Read %i KiB of %s data at once using git-cat-file in %f s ( %f Read KiB / s)"
126126
% (size_kib, desc, gelapsed_readall, size_kib / gelapsed_readall), file=sys.stderr)
@@ -131,7 +131,7 @@ def test_large_data_streaming(self, rwrepo):
131131

132132
# read chunks
133133
st = time()
134-
s, t, size, stream = rwrepo.git.stream_object_data(gitsha)
134+
hexsha, otype, size, stream = rwrepo.git.stream_object_data(gitsha) # @UnusedVariable
135135
while True:
136136
data = stream.read(cs)
137137
if len(data) < cs:

Diff for: git/test/test_commit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def check_entries(d):
123123
check_entries(stats.total)
124124
assert "files" in stats.total
125125

126-
for filepath, d in stats.files.items():
126+
for filepath, d in stats.files.items(): # @UnusedVariable
127127
check_entries(d)
128128
# END for each stated file
129129

Diff for: git/test/test_docs.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ def test_init_repo_object(self, rw_dir):
7070
# heads, tags and references
7171
# heads are branches in git-speak
7272
# [8-test_init_repo_object]
73-
self.assertEqual(repo.head.ref, repo.heads.master) # head is a sym-ref pointing to master
73+
self.assertEqual(repo.head.ref, repo.heads.master, # head is a sym-ref pointing to master
74+
"It's ok if TC not running from `master`.")
7475
self.assertEqual(repo.tags['0.3.5'], repo.tag('refs/tags/0.3.5')) # you can access tags in various ways too
7576
self.assertEqual(repo.refs.master, repo.heads['master']) # .refs provides all refs, ie heads ...
7677

@@ -242,9 +243,9 @@ def test_references_and_objects(self, rw_dir):
242243
# [8-test_references_and_objects]
243244
hc = repo.head.commit
244245
hct = hc.tree
245-
hc != hct
246-
hc != repo.tags[0]
247-
hc == repo.head.reference.commit
246+
hc != hct # @NoEffect
247+
hc != repo.tags[0] # @NoEffect
248+
hc == repo.head.reference.commit # @NoEffect
248249
# ![8-test_references_and_objects]
249250

250251
# [9-test_references_and_objects]
@@ -347,7 +348,7 @@ def test_references_and_objects(self, rw_dir):
347348
# The index contains all blobs in a flat list
348349
assert len(list(index.iter_blobs())) == len([o for o in repo.head.commit.tree.traverse() if o.type == 'blob'])
349350
# Access blob objects
350-
for (path, stage), entry in index.entries.items():
351+
for (path, stage), entry in index.entries.items(): # @UnusedVariable
351352
pass
352353
new_file_path = os.path.join(repo.working_tree_dir, 'new-file-name')
353354
open(new_file_path, 'w').close()

Diff for: git/test/test_exc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
)
3131
_causes_n_substrings = (
3232
(None, None), # noqa: E241
33-
(7, "exit code(7)"), # noqa: E241
33+
(7, "exit code(7)"), # noqa: E241
3434
('Some string', "'Some string'"), # noqa: E241
3535
('παλιο string', "'παλιο string'"), # noqa: E241
3636
(Exception("An exc."), "Exception('An exc.')"), # noqa: E241
3737
(Exception("Κακια exc."), "Exception('Κακια exc.')"), # noqa: E241
38-
(object(), "<object object at "), # noqa: E241
38+
(object(), "<object object at "), # noqa: E241
3939
)
4040

4141
_streams_n_substrings = (None, 'steram', 'ομορφο stream', )

Diff for: git/test/test_git.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def test_persistent_cat_file_command(self):
121121

122122
# read data - have to read it in one large chunk
123123
size = int(obj_info.split()[2])
124-
data = g.stdout.read(size)
124+
g.stdout.read(size)
125125
g.stdout.read(1)
126126

127127
# now we should be able to read a new object
@@ -131,7 +131,7 @@ def test_persistent_cat_file_command(self):
131131

132132
# same can be achived using the respective command functions
133133
hexsha, typename, size = self.git.get_object_header(hexsha)
134-
hexsha, typename_two, size_two, data = self.git.get_object_data(hexsha)
134+
hexsha, typename_two, size_two, data = self.git.get_object_data(hexsha) # @UnusedVariable
135135
self.assertEqual(typename, typename_two)
136136
self.assertEqual(size, size_two)
137137

Diff for: git/test/test_remote.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def make_assertion(self):
9090
assert self._stages_per_op
9191

9292
# must have seen all stages
93-
for op, stages in self._stages_per_op.items():
93+
for op, stages in self._stages_per_op.items(): # @UnusedVariable
9494
assert stages & self.STAGE_MASK == self.STAGE_MASK
9595
# END for each op/stage
9696

@@ -331,7 +331,7 @@ def _assert_push_and_pull(self, remote, rw_repo, remote_repo):
331331
# push new tags
332332
progress = TestRemoteProgress()
333333
to_be_updated = "my_tag.1.0RV"
334-
new_tag = TagReference.create(rw_repo, to_be_updated)
334+
new_tag = TagReference.create(rw_repo, to_be_updated) # @UnusedVariable
335335
other_tag = TagReference.create(rw_repo, "my_obj_tag.2.1aRV", message="my message")
336336
res = remote.push(progress=progress, tags=True)
337337
assert res[-1].flags & PushInfo.NEW_TAG
@@ -432,7 +432,7 @@ def test_base(self, rw_repo, remote_repo):
432432
assert remote.rename(other_name) == remote
433433
assert prev_name != remote.name
434434
# multiple times
435-
for time in range(2):
435+
for _ in range(2):
436436
assert remote.rename(prev_name).name == prev_name
437437
# END for each rename ( back to prev_name )
438438

Diff for: git/test/test_repo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ def last_commit(repo, rev, path):
809809
# And we expect to set max handles to a low value, like 64
810810
# You should set ulimit -n X, see .travis.yml
811811
# The loops below would easily create 500 handles if these would leak (4 pipes + multiple mapped files)
812-
for i in range(64):
812+
for _ in range(64):
813813
for repo_type in (GitCmdObjectDB, GitDB):
814814
repo = Repo(self.rorepo.working_tree_dir, odbt=repo_type)
815815
last_commit(repo, 'master', 'git/test/test_base.py')

Diff for: git/test/test_submodule.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def _do_base_tests(self, rwrepo):
9898

9999
# force it to reread its information
100100
del(smold._url)
101-
smold.url == sm.url
101+
smold.url == sm.url # @NoEffect
102102

103103
# test config_reader/writer methods
104104
sm.config_reader()
@@ -225,7 +225,7 @@ def _do_base_tests(self, rwrepo):
225225
assert csm.module_exists()
226226

227227
# tracking branch once again
228-
csm.module().head.ref.tracking_branch() is not None
228+
csm.module().head.ref.tracking_branch() is not None # @NoEffect
229229

230230
# this flushed in a sub-submodule
231231
assert len(list(rwrepo.iter_submodules())) == 2

0 commit comments

Comments
 (0)