From a469af892b3e929cbe9d29e414b6fcd59bec246e Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Mon, 3 Oct 2016 23:35:55 +0200 Subject: 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. + remote: minor fix progress dispatching unknown err-lines --- git/__init__.py | 24 +++---- git/compat.py | 23 ++++--- git/config.py | 4 +- git/db.py | 4 +- git/exc.py | 2 +- git/index/base.py | 13 ++-- git/index/fun.py | 2 +- git/objects/__init__.py | 16 +++-- git/objects/base.py | 2 +- git/objects/commit.py | 4 +- git/objects/fun.py | 4 +- git/objects/tag.py | 6 +- git/refs/reference.py | 2 +- git/refs/symbolic.py | 6 +- git/remote.py | 8 +-- git/repo/fun.py | 2 +- git/test/lib/asserts.py | 14 ++-- git/test/performance/test_streams.py | 4 +- git/test/test_commit.py | 2 +- git/test/test_docs.py | 11 ++-- git/test/test_exc.py | 14 ++-- git/test/test_git.py | 4 +- git/test/test_index.py | 4 +- git/test/test_refs.py | 4 +- git/test/test_remote.py | 6 +- git/test/test_repo.py | 2 +- git/test/test_submodule.py | 6 +- git/test/test_util.py | 122 +++++++++++++++++++---------------- git/util.py | 14 ++-- 29 files changed, 172 insertions(+), 157 deletions(-) diff --git a/git/__init__.py b/git/__init__.py index e8dae272..58e4e7b6 100644 --- a/git/__init__.py +++ b/git/__init__.py @@ -4,7 +4,7 @@ # This module is part of GitPython and is released under # the BSD License: http://www.opensource.org/licenses/bsd-license.php # flake8: noqa - +#@PydevCodeAnalysisIgnore import os import sys import inspect @@ -32,17 +32,17 @@ _init_externals() #{ Imports -from git.config import GitConfigParser -from git.objects import * -from git.refs import * -from git.diff import * -from git.exc import * -from git.db import * -from git.cmd import Git -from git.repo import Repo -from git.remote import * -from git.index import * -from git.util import ( +from git.config import GitConfigParser # @NoMove @IgnorePep8 +from git.objects import * # @NoMove @IgnorePep8 +from git.refs import * # @NoMove @IgnorePep8 +from git.diff import * # @NoMove @IgnorePep8 +from git.exc import * # @NoMove @IgnorePep8 +from git.db import * # @NoMove @IgnorePep8 +from git.cmd import Git # @NoMove @IgnorePep8 +from git.repo import Repo # @NoMove @IgnorePep8 +from git.remote import * # @NoMove @IgnorePep8 +from git.index import * # @NoMove @IgnorePep8 +from git.util import ( # @NoMove @IgnorePep8 LockFile, BlockingLockFile, Stats, diff --git a/git/compat.py b/git/compat.py index 441a3761..e7243e25 100644 --- a/git/compat.py +++ b/git/compat.py @@ -13,14 +13,14 @@ import sys from gitdb.utils.compat import ( xrange, - MAXSIZE, - izip, + MAXSIZE, # @UnusedImport + izip, # @UnusedImport ) from gitdb.utils.encoding import ( - string_types, - text_type, - force_bytes, - force_text + string_types, # @UnusedImport + text_type, # @UnusedImport + force_bytes, # @UnusedImport + force_text # @UnusedImport ) @@ -33,17 +33,21 @@ defenc = sys.getdefaultencoding() if PY3: import io FileType = io.IOBase + def byte_ord(b): return b + def bchr(n): return bytes([n]) + def mviter(d): return d.values() - range = xrange + + range = xrange # @ReservedAssignment unicode = str binary_type = bytes else: - FileType = file + FileType = file # @UndefinedVariable on PY3 # usually, this is just ascii, which might not enough for our encoding needs # Unless it's set specifically, we override it to be utf-8 if defenc == 'ascii': @@ -52,7 +56,8 @@ else: bchr = chr unicode = unicode binary_type = str - range = xrange + range = xrange # @ReservedAssignment + def mviter(d): return d.itervalues() diff --git a/git/config.py b/git/config.py index 3c6a32eb..eddfac15 100644 --- a/git/config.py +++ b/git/config.py @@ -40,7 +40,7 @@ log.addHandler(logging.NullHandler()) class MetaParserBuilder(abc.ABCMeta): """Utlity class wrapping base-class methods into decorators that assure read-only properties""" - def __new__(metacls, name, bases, clsdict): + def __new__(cls, name, bases, clsdict): """ Equip all base-class methods with a needs_values decorator, and all non-const methods with a set_dirty_and_flush_changes decorator in addition to that.""" @@ -62,7 +62,7 @@ class MetaParserBuilder(abc.ABCMeta): # END for each base # END if mutating methods configuration is set - new_type = super(MetaParserBuilder, metacls).__new__(metacls, name, bases, clsdict) + new_type = super(MetaParserBuilder, cls).__new__(cls, name, bases, clsdict) return new_type diff --git a/git/db.py b/git/db.py index c4e19858..39b9872a 100644 --- a/git/db.py +++ b/git/db.py @@ -7,7 +7,7 @@ from gitdb.util import ( bin_to_hex, hex_to_bin ) -from gitdb.db import GitDB +from gitdb.db import GitDB # @UnusedImport from gitdb.db import LooseObjectDB from .exc import ( @@ -54,7 +54,7 @@ class GitCmdObjectDB(LooseObjectDB): :note: currently we only raise BadObject as git does not communicate AmbiguousObjects separately""" try: - hexsha, typename, size = self._git.get_object_header(partial_hexsha) + hexsha, typename, size = self._git.get_object_header(partial_hexsha) # @UnusedVariable return hex_to_bin(hexsha) except (GitCommandError, ValueError): raise BadObject(partial_hexsha) diff --git a/git/exc.py b/git/exc.py index 47215c21..eb7c3c0e 100644 --- a/git/exc.py +++ b/git/exc.py @@ -5,7 +5,7 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php """ Module containing all exceptions thrown througout the git package, """ -from gitdb.exc import * # NOQA +from gitdb.exc import * # NOQA @UnusedWildImport from git.compat import UnicodeMixin, safe_decode, string_types diff --git a/git/index/base.py b/git/index/base.py index 9b6d28ab..ac2d3019 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -170,7 +170,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): def _deserialize(self, stream): """Initialize this instance with index values read from the given stream""" - self.version, self.entries, self._extension_data, conten_sha = read_cache(stream) + self.version, self.entries, self._extension_data, conten_sha = read_cache(stream) # @UnusedVariable return self def _entries_sorted(self): @@ -404,7 +404,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): continue # END glob handling try: - for root, dirs, files in os.walk(abs_path, onerror=raise_exc): + for root, dirs, files in os.walk(abs_path, onerror=raise_exc): # @UnusedVariable for rela_file in files: # add relative paths only yield os.path.join(root.replace(rs, ''), rela_file) @@ -599,7 +599,6 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): """Store file at filepath in the database and return the base index entry Needs the git_working_dir decorator active ! This must be assured in the calling code""" st = os.lstat(filepath) # handles non-symlinks as well - stream = None if S_ISLNK(st.st_mode): # in PY3, readlink is string, but we need bytes. In PY2, it's just OS encoded bytes, we assume UTF-8 open_stream = lambda: BytesIO(force_bytes(os.readlink(filepath), encoding=defenc)) @@ -1102,11 +1101,11 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): try: self.entries[(co_path, 0)] except KeyError: - dir = co_path - if not dir.endswith('/'): - dir += '/' + folder = co_path + if not folder.endswith('/'): + folder += '/' for entry in mviter(self.entries): - if entry.path.startswith(dir): + if entry.path.startswith(folder): p = entry.path self._write_path_to_stdin(proc, p, p, make_exc, fprogress, read_from_stdout=False) diff --git a/git/index/fun.py b/git/index/fun.py index 74ac929e..7a7593fe 100644 --- a/git/index/fun.py +++ b/git/index/fun.py @@ -264,7 +264,7 @@ def write_tree_from_cache(entries, odb, sl, si=0): # enter recursion # ci - 1 as we want to count our current item as well - sha, tree_entry_list = write_tree_from_cache(entries, odb, slice(ci - 1, xi), rbound + 1) + sha, tree_entry_list = write_tree_from_cache(entries, odb, slice(ci - 1, xi), rbound + 1) # @UnusedVariable tree_items_append((sha, S_IFDIR, base)) # skip ahead diff --git a/git/objects/__init__.py b/git/objects/__init__.py index ee642876..23b2416a 100644 --- a/git/objects/__init__.py +++ b/git/objects/__init__.py @@ -3,22 +3,24 @@ Import all submodules main classes into the package space """ # flake8: noqa from __future__ import absolute_import + import inspect + from .base import * +from .blob import * +from .commit import * +from .submodule import util as smutil +from .submodule.base import * +from .submodule.root import * +from .tag import * +from .tree import * # Fix import dependency - add IndexObject to the util module, so that it can be # imported by the submodule.base -from .submodule import util as smutil smutil.IndexObject = IndexObject smutil.Object = Object del(smutil) -from .submodule.base import * -from .submodule.root import * # must come after submodule was made available -from .tag import * -from .blob import * -from .commit import * -from .tree import * __all__ = [name for name, obj in locals().items() if not (name.startswith('_') or inspect.ismodule(obj))] diff --git a/git/objects/base.py b/git/objects/base.py index 77d0ed63..0b849960 100644 --- a/git/objects/base.py +++ b/git/objects/base.py @@ -40,7 +40,7 @@ class Object(LazyMixin): assert len(binsha) == 20, "Require 20 byte binary sha, got %r, len = %i" % (binsha, len(binsha)) @classmethod - def new(cls, repo, id): + def new(cls, repo, id): # @ReservedAssignment """ :return: New Object instance of a type appropriate to the object type behind id. The id of the newly created object will be a binsha even though diff --git a/git/objects/commit.py b/git/objects/commit.py index 000ab3d0..1534c552 100644 --- a/git/objects/commit.py +++ b/git/objects/commit.py @@ -140,7 +140,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): def _set_cache_(self, attr): if attr in Commit.__slots__: # read the data in a chunk, its faster - then provide a file wrapper - binsha, typename, self.size, stream = self.repo.odb.stream(self.binsha) + binsha, typename, self.size, stream = self.repo.odb.stream(self.binsha) # @UnusedVariable self._deserialize(BytesIO(stream.read())) else: super(Commit, self)._set_cache_(attr) @@ -267,7 +267,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): hexsha = line.strip() if len(hexsha) > 40: # split additional information, as returned by bisect for instance - hexsha, rest = line.split(None, 1) + hexsha, _ = line.split(None, 1) # END handle extra info assert len(hexsha) == 40, "Invalid line: %s" % hexsha diff --git a/git/objects/fun.py b/git/objects/fun.py index c04f80b5..5c0f4819 100644 --- a/git/objects/fun.py +++ b/git/objects/fun.py @@ -157,9 +157,9 @@ def traverse_trees_recursive(odb, tree_shas, path_prefix): if not item: continue # END skip already done items - entries = [None for n in range(nt)] + entries = [None for _ in range(nt)] entries[ti] = item - sha, mode, name = item # its faster to unpack + sha, mode, name = item # its faster to unpack @UnusedVariable is_dir = S_ISDIR(mode) # type mode bits # find this item in all other tree data items diff --git a/git/objects/tag.py b/git/objects/tag.py index c8684447..cefff083 100644 --- a/git/objects/tag.py +++ b/git/objects/tag.py @@ -21,7 +21,7 @@ class TagObject(base.Object): type = "tag" __slots__ = ("object", "tag", "tagger", "tagged_date", "tagger_tz_offset", "message") - def __init__(self, repo, binsha, object=None, tag=None, + def __init__(self, repo, binsha, object=None, tag=None, # @ReservedAssignment tagger=None, tagged_date=None, tagger_tz_offset=None, message=None): """Initialize a tag object with additional data @@ -55,8 +55,8 @@ class TagObject(base.Object): ostream = self.repo.odb.stream(self.binsha) lines = ostream.read().decode(defenc).splitlines() - obj, hexsha = lines[0].split(" ") # object - type_token, type_name = lines[1].split(" ") # type + obj, hexsha = lines[0].split(" ") # object @UnusedVariable + type_token, type_name = lines[1].split(" ") # type @UnusedVariable self.object = \ get_object_type_by_name(type_name.encode('ascii'))(self.repo, hex_to_bin(hexsha)) diff --git a/git/refs/reference.py b/git/refs/reference.py index 3e132aef..cc99dc26 100644 --- a/git/refs/reference.py +++ b/git/refs/reference.py @@ -50,7 +50,7 @@ class Reference(SymbolicReference, LazyMixin, Iterable): #{ Interface - def set_object(self, object, logmsg=None): + def set_object(self, object, logmsg=None): # @ReservedAssignment """Special version which checks if the head-log needs an update as well :return: self""" oldbinsha = None diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index 894b26d5..ebaff8ca 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -218,7 +218,7 @@ class SymbolicReference(object): return self - def set_object(self, object, logmsg=None): + def set_object(self, object, logmsg=None): # @ReservedAssignment """Set the object we point to, possibly dereference our symbolic reference first. If the reference does not exist, it will be created @@ -229,7 +229,7 @@ class SymbolicReference(object): :note: plain SymbolicReferences may not actually point to objects by convention :return: self""" if isinstance(object, SymbolicReference): - object = object.object + object = object.object # @ReservedAssignment # END resolve references is_detached = True @@ -595,7 +595,7 @@ class SymbolicReference(object): # END for each directory to walk # read packed refs - for sha, rela_path in cls._iter_packed_refs(repo): + for sha, rela_path in cls._iter_packed_refs(repo): # @UnusedVariable if rela_path.startswith(common_path): rela_paths.add(rela_path) # END relative path matches common path diff --git a/git/remote.py b/git/remote.py index c2ffcc1a..d35e1fad 100644 --- a/git/remote.py +++ b/git/remote.py @@ -176,7 +176,7 @@ class PushInfo(object): split_token = "..." if control_character == " ": split_token = ".." - old_sha, new_sha = summary.split(' ')[0].split(split_token) + old_sha, new_sha = summary.split(' ')[0].split(split_token) # @UnusedVariable # have to use constructor here as the sha usually is abbreviated old_commit = old_sha # END message handling @@ -262,7 +262,7 @@ class FetchInfo(object): # parse lines control_character, operation, local_remote_ref, remote_local_ref, note = match.groups() try: - new_hex_sha, fetch_operation, fetch_note = fetch_line.split("\t") + new_hex_sha, fetch_operation, fetch_note = fetch_line.split("\t") # @UnusedVariable ref_type_name, fetch_note = fetch_note.split(' ', 1) except ValueError: # unpack error raise ValueError("Failed to parse FETCH_HEAD line: %r" % fetch_line) @@ -625,8 +625,8 @@ class Remote(LazyMixin, Iterable): for pline in progress_handler(line): # END handle special messages for cmd in cmds: - if len(line) > 1 and line[0] == ' ' and line[1] == cmd: - fetch_info_lines.append(line) + if len(pline) > 1 and pline[0] == ' ' and pline[1] == cmd: + fetch_info_lines.append(pline) continue # end find command code # end for each comand code we know diff --git a/git/repo/fun.py b/git/repo/fun.py index 0483eaa9..320eb1c8 100644 --- a/git/repo/fun.py +++ b/git/repo/fun.py @@ -284,7 +284,7 @@ def rev_parse(repo, rev): try: if token == "~": obj = to_commit(obj) - for item in xrange(num): + for _ in xrange(num): obj = obj.parents[0] # END for each history item to walk elif token == "^": diff --git a/git/test/lib/asserts.py b/git/test/lib/asserts.py index 9edc49e0..6f5ba714 100644 --- a/git/test/lib/asserts.py +++ b/git/test/lib/asserts.py @@ -8,18 +8,18 @@ import re import stat from nose.tools import ( - assert_equal, - assert_not_equal, - assert_raises, - raises, - assert_true, - assert_false + assert_equal, # @UnusedImport + assert_not_equal, # @UnusedImport + assert_raises, # @UnusedImport + raises, # @UnusedImport + assert_true, # @UnusedImport + assert_false # @UnusedImport ) try: from unittest.mock import patch except ImportError: - from mock import patch + from mock import patch # @NoMove @UnusedImport __all__ = ['assert_instance_of', 'assert_not_instance_of', 'assert_none', 'assert_not_none', diff --git a/git/test/performance/test_streams.py b/git/test/performance/test_streams.py index 8194547c..42cbade5 100644 --- a/git/test/performance/test_streams.py +++ b/git/test/performance/test_streams.py @@ -120,7 +120,7 @@ class TestObjDBPerformance(TestBigRepoR): # read all st = time() - s, t, size, data = rwrepo.git.get_object_data(gitsha) + hexsha, typename, size, data = rwrepo.git.get_object_data(gitsha) # @UnusedVariable gelapsed_readall = time() - st print("Read %i KiB of %s data at once using git-cat-file in %f s ( %f Read KiB / s)" % (size_kib, desc, gelapsed_readall, size_kib / gelapsed_readall), file=sys.stderr) @@ -131,7 +131,7 @@ class TestObjDBPerformance(TestBigRepoR): # read chunks st = time() - s, t, size, stream = rwrepo.git.stream_object_data(gitsha) + hexsha, typename, size, stream = rwrepo.git.stream_object_data(gitsha) # @UnusedVariable while True: data = stream.read(cs) if len(data) < cs: diff --git a/git/test/test_commit.py b/git/test/test_commit.py index 66d988a3..fd9777fb 100644 --- a/git/test/test_commit.py +++ b/git/test/test_commit.py @@ -123,7 +123,7 @@ class TestCommit(TestBase): check_entries(stats.total) assert "files" in stats.total - for filepath, d in stats.files.items(): + for filepath, d in stats.files.items(): # @UnusedVariable check_entries(d) # END for each stated file diff --git a/git/test/test_docs.py b/git/test/test_docs.py index 6e505dd9..5c7ae7f0 100644 --- a/git/test/test_docs.py +++ b/git/test/test_docs.py @@ -70,7 +70,8 @@ class Tutorials(TestBase): # heads, tags and references # heads are branches in git-speak # [8-test_init_repo_object] - self.assertEqual(repo.head.ref, repo.heads.master) # head is a sym-ref pointing to master + self.assertEqual(repo.head.ref, repo.heads.master, # head is a sym-ref pointing to master + "It's ok if TC not running from `master`.") self.assertEqual(repo.tags['0.3.5'], repo.tag('refs/tags/0.3.5')) # you can access tags in various ways too self.assertEqual(repo.refs.master, repo.heads['master']) # .refs provides all refs, ie heads ... @@ -242,9 +243,9 @@ class Tutorials(TestBase): # [8-test_references_and_objects] hc = repo.head.commit hct = hc.tree - hc != hct - hc != repo.tags[0] - hc == repo.head.reference.commit + hc != hct # @NoEffect + hc != repo.tags[0] # @NoEffect + hc == repo.head.reference.commit # @NoEffect # ![8-test_references_and_objects] # [9-test_references_and_objects] @@ -347,7 +348,7 @@ class Tutorials(TestBase): # The index contains all blobs in a flat list assert len(list(index.iter_blobs())) == len([o for o in repo.head.commit.tree.traverse() if o.type == 'blob']) # Access blob objects - for (path, stage), entry in index.entries.items(): + for (path, stage), entry in index.entries.items(): # @UnusedVariable pass new_file_path = os.path.join(repo.working_tree_dir, 'new-file-name') open(new_file_path, 'w').close() diff --git a/git/test/test_exc.py b/git/test/test_exc.py index 7e6b023e..33f44034 100644 --- a/git/test/test_exc.py +++ b/git/test/test_exc.py @@ -29,13 +29,13 @@ _cmd_argvs = ( ('θνιψοδε', 'κι', 'αλλα', 'non-unicode', 'args'), ) _causes_n_substrings = ( - (None, None), # noqa: E241 - (7, "exit code(7)"), # noqa: E241 - ('Some string', "'Some string'"), # noqa: E241 - ('παλιο string', "'παλιο string'"), # noqa: E241 - (Exception("An exc."), "Exception('An exc.')"), # noqa: E241 - (Exception("Κακια exc."), "Exception('Κακια exc.')"), # noqa: E241 - (object(), "