Skip to content

Drop support for EOL Python 2.6 and 3.3 #737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 24, 2018
Prev Previous commit
Next Next commit
Rewrite unnecessary dict/list/tuple calls as literals
  • Loading branch information
hugovk committed Mar 18, 2018
commit ac4f7d34f8752ab78949efcaa9f0bd938df33622
8 changes: 4 additions & 4 deletions git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,10 @@ def readline(self, size=-1):

def readlines(self, size=-1):
if self._nbr == self._size:
return list()
return []

# leave all additional logic to our readline method, we just check the size
out = list()
out = []
nbr = 0
while True:
line = self.readline()
Expand Down Expand Up @@ -894,7 +894,7 @@ def transform_kwarg(self, name, value, split_single_char_options):

def transform_kwargs(self, split_single_char_options=True, **kwargs):
"""Transforms Python style kwargs into git command line options."""
args = list()
args = []
kwargs = OrderedDict(sorted(kwargs.items(), key=lambda x: x[0]))
for k, v in kwargs.items():
if isinstance(v, (list, tuple)):
Expand All @@ -913,7 +913,7 @@ def __unpack_args(cls, arg_list):
return [arg_list.encode(defenc)]
return [str(arg_list)]

outlist = list()
outlist = []
for arg in arg_list:
if isinstance(arg_list, (list, tuple)):
outlist.extend(cls.__unpack_args(arg))
Expand Down
4 changes: 2 additions & 2 deletions git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Diffable(object):
:note:
Subclasses require a repo member as it is the case for Object instances, for practical
reasons we do not derive from Object."""
__slots__ = tuple()
__slots__ = ()

# standin indicating you want to diff against the index
class Index(object):
Expand Down Expand Up @@ -106,7 +106,7 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs):
:note:
On a bare repository, 'other' needs to be provided as Index or as
as Tree/Commit, or a git command error will occur"""
args = list()
args = []
args.append("--abbrev=40") # we need full shas
args.append("--full-index") # get full index paths, not only filenames

Expand Down
32 changes: 16 additions & 16 deletions git/index/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def _set_cache_(self, attr):
ok = True
except OSError:
# in new repositories, there may be no index, which means we are empty
self.entries = dict()
self.entries = {}
return
finally:
if not ok:
Expand Down Expand Up @@ -324,7 +324,7 @@ def from_tree(cls, repo, *treeish, **kwargs):
if len(treeish) == 0 or len(treeish) > 3:
raise ValueError("Please specify between 1 and 3 treeish, got %i" % len(treeish))

arg_list = list()
arg_list = []
# ignore that working tree and index possibly are out of date
if len(treeish) > 1:
# drop unmerged entries when reading our index and merging
Expand Down Expand Up @@ -471,9 +471,9 @@ def unmerged_blobs(self):
are at stage 3 will not have a stage 3 entry.
"""
is_unmerged_blob = lambda t: t[0] != 0
path_map = dict()
path_map = {}
for stage, blob in self.iter_blobs(is_unmerged_blob):
path_map.setdefault(blob.path, list()).append((stage, blob))
path_map.setdefault(blob.path, []).append((stage, blob))
# END for each unmerged blob
for l in mviter(path_map):
l.sort()
Expand Down Expand Up @@ -576,8 +576,8 @@ def _to_relative_path(self, path):

def _preprocess_add_items(self, items):
""" Split the items into two lists of path strings and BaseEntries. """
paths = list()
entries = list()
paths = []
entries = []

for item in items:
if isinstance(item, string_types):
Expand Down Expand Up @@ -610,7 +610,7 @@ def _store_path(self, filepath, fprogress):
@unbare_repo
@git_working_dir
def _entries_for_paths(self, paths, path_rewriter, fprogress, entries):
entries_added = list()
entries_added = []
if path_rewriter:
for path in paths:
if osp.isabs(path):
Expand Down Expand Up @@ -742,7 +742,7 @@ def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=Non
# automatically
# paths can be git-added, for everything else we use git-update-index
paths, entries = self._preprocess_add_items(items)
entries_added = list()
entries_added = []
# This code needs a working tree, therefore we try not to run it unless required.
# That way, we are OK on a bare repository as well.
# If there are no paths, the rewriter has nothing to do either
Expand Down Expand Up @@ -809,7 +809,7 @@ def handle_null_entries(self):
def _items_to_rela_paths(self, items):
"""Returns a list of repo-relative paths from the given items which
may be absolute or relative paths, entries or blobs"""
paths = list()
paths = []
for item in items:
if isinstance(item, (BaseIndexEntry, (Blob, Submodule))):
paths.append(self._to_relative_path(item.path))
Expand Down Expand Up @@ -858,7 +858,7 @@ def remove(self, items, working_tree=False, **kwargs):
been removed effectively.
This is interesting to know in case you have provided a directory or
globs. Paths are relative to the repository. """
args = list()
args = []
if not working_tree:
args.append("--cached")
args.append("--")
Expand Down Expand Up @@ -897,7 +897,7 @@ def move(self, items, skip_errors=False, **kwargs):

:raise ValueError: If only one item was given
GitCommandError: If git could not handle your request"""
args = list()
args = []
if skip_errors:
args.append('-k')

Expand All @@ -910,7 +910,7 @@ def move(self, items, skip_errors=False, **kwargs):

# first execute rename in dryrun so the command tells us what it actually does
# ( for later output )
out = list()
out = []
mvlines = self.repo.git.mv(args, paths, **kwargs).splitlines()

# parse result - first 0:n/2 lines are 'checking ', the remaining ones
Expand Down Expand Up @@ -1041,9 +1041,9 @@ def handle_stderr(proc, iter_checked_out_files):
# line contents:
stderr = stderr.decode(defenc)
# git-checkout-index: this already exists
failed_files = list()
failed_reasons = list()
unknown_lines = list()
failed_files = []
failed_reasons = []
unknown_lines = []
endings = (' already exists', ' is not in the cache', ' does not exist at stage', ' is unmerged')
for line in stderr.splitlines():
if not line.startswith("git checkout-index: ") and not line.startswith("git-checkout-index: "):
Expand Down Expand Up @@ -1106,7 +1106,7 @@ def handle_stderr(proc, iter_checked_out_files):
proc = self.repo.git.checkout_index(args, **kwargs)
# FIXME: Reading from GIL!
make_exc = lambda: GitCommandError(("git-checkout-index",) + tuple(args), 128, proc.stderr.read())
checked_out_files = list()
checked_out_files = []

for path in paths:
co_path = to_native_path_linux(self._to_relative_path(path))
Expand Down
6 changes: 3 additions & 3 deletions git/index/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def read_cache(stream):
* content_sha is a 20 byte sha on all cache file contents"""
version, num_entries = read_header(stream)
count = 0
entries = dict()
entries = {}

read = stream.read
tell = stream.tell
Expand Down Expand Up @@ -236,7 +236,7 @@ def write_tree_from_cache(entries, odb, sl, si=0):
:param sl: slice indicating the range we should process on the entries list
:return: tuple(binsha, list(tree_entry, ...)) a tuple of a sha and a list of
tree entries being a tuple of hexsha, mode, name"""
tree_items = list()
tree_items = []
tree_items_append = tree_items.append
ci = sl.start
end = sl.stop
Expand Down Expand Up @@ -295,7 +295,7 @@ def aggressive_tree_merge(odb, tree_shas):
:param tree_shas: 1, 2 or 3 trees as identified by their binary 20 byte shas
If 1 or two, the entries will effectively correspond to the last given tree
If 3 are given, a 3 way merge is performed"""
out = list()
out = []
out_append = out.append

# one and two way is the same for us, as we don't have to handle an existing
Expand Down
2 changes: 1 addition & 1 deletion git/objects/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Blob(base.IndexObject):
file_mode = 0o100644
link_mode = 0o120000

__slots__ = tuple()
__slots__ = ()

@property
def mime_type(self):
Expand Down
4 changes: 2 additions & 2 deletions git/objects/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False,
parent_commits = [repo.head.commit]
except ValueError:
# empty repositories have no head commit
parent_commits = list()
parent_commits = []
# END handle parent commits
else:
for p in parent_commits:
Expand Down Expand Up @@ -450,7 +450,7 @@ def _deserialize(self, stream):
readline = stream.readline
self.tree = Tree(self.repo, hex_to_bin(readline().split()[1]), Tree.tree_id << 12, '')

self.parents = list()
self.parents = []
next_line = None
while True:
parent_line = readline()
Expand Down
10 changes: 5 additions & 5 deletions git/objects/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def tree_entries_from_data(data):
space_ord = ord(' ')
len_data = len(data)
i = 0
out = list()
out = []
while i < len_data:
mode = 0

Expand Down Expand Up @@ -132,18 +132,18 @@ def traverse_trees_recursive(odb, tree_shas, path_prefix):
:param path_prefix: a prefix to be added to the returned paths on this level,
set it '' for the first iteration
:note: The ordering of the returned items will be partially lost"""
trees_data = list()
trees_data = []
nt = len(tree_shas)
for tree_sha in tree_shas:
if tree_sha is None:
data = list()
data = []
else:
data = tree_entries_from_data(odb.stream(tree_sha).read())
# END handle muted trees
trees_data.append(data)
# END for each sha to get data for

out = list()
out = []
out_append = out.append

# find all matching entries and recursively process them together if the match
Expand Down Expand Up @@ -193,7 +193,7 @@ def traverse_tree_recursive(odb, tree_sha, path_prefix):
* [1] mode as int
* [2] path relative to the repository
:param path_prefix: prefix to prepend to the front of all returned paths"""
entries = list()
entries = []
data = tree_entries_from_data(odb.stream(tree_sha).read())

# unpacking/packing is faster than accessing individual items
Expand Down
4 changes: 2 additions & 2 deletions git/objects/submodule/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class UpdateProgress(RemoteProgress):
CLONE, FETCH, UPDWKTREE = [1 << x for x in range(RemoteProgress._num_op_codes, RemoteProgress._num_op_codes + 3)]
_num_op_codes = RemoteProgress._num_op_codes + 3

__slots__ = tuple()
__slots__ = ()


BEGIN = UpdateProgress.BEGIN
Expand Down Expand Up @@ -139,7 +139,7 @@ def _get_intermediate_items(self, item):
try:
return type(self).list_items(item.module())
except InvalidGitRepositoryError:
return list()
return []
# END handle intermediate items

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions git/objects/submodule/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class RootUpdateProgress(UpdateProgress):
1 << x for x in range(UpdateProgress._num_op_codes, UpdateProgress._num_op_codes + 4)]
_num_op_codes = UpdateProgress._num_op_codes + 4

__slots__ = tuple()
__slots__ = ()


BEGIN = RootUpdateProgress.BEGIN
Expand All @@ -38,7 +38,7 @@ class RootModule(Submodule):
"""A (virtual) Root of all submodules in the given repository. It can be used
to more easily traverse all submodules of the master repository"""

__slots__ = tuple()
__slots__ = ()

k_root_name = '__ROOT__'

Expand Down
2 changes: 1 addition & 1 deletion git/objects/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def __init__(self, repo, binsha, mode=tree_id << 12, path=None):
def _get_intermediate_items(cls, index_object):
if index_object.type == "tree":
return tuple(index_object._iter_convert_to_object(index_object._cache))
return tuple()
return ()

def _set_cache_(self, attr):
if attr == "_cache":
Expand Down
6 changes: 3 additions & 3 deletions git/objects/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def parse_date(string_date):
offset = utctz_to_altz(offset)

# now figure out the date and time portion - split time
date_formats = list()
date_formats = []
splitter = -1
if ',' in string_date:
date_formats.append("%a, %d %b %Y")
Expand Down Expand Up @@ -248,7 +248,7 @@ class Traversable(object):
into one direction.
Subclasses only need to implement one function.
Instances of the Subclass must be hashable"""
__slots__ = tuple()
__slots__ = ()

@classmethod
def _get_intermediate_items(cls, item):
Expand Down Expand Up @@ -344,7 +344,7 @@ def addToStack(stack, item, branch_first, depth):
class Serializable(object):

"""Defines methods to serialize and deserialize objects from and into a data stream"""
__slots__ = tuple()
__slots__ = ()

def _serialize(self, stream):
"""Serialize the data of this object into the given data stream
Expand Down
2 changes: 1 addition & 1 deletion git/refs/head.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class HEAD(SymbolicReference):
HEAD reference."""
_HEAD_NAME = 'HEAD'
_ORIG_HEAD_NAME = 'ORIG_HEAD'
__slots__ = tuple()
__slots__ = ()

def __init__(self, repo, path=_HEAD_NAME):
if path != self._HEAD_NAME:
Expand Down
2 changes: 1 addition & 1 deletion git/refs/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class RefLogEntry(tuple):

"""Named tuple allowing easy access to the revlog data fields"""
_re_hexsha_only = re.compile('^[0-9A-Fa-f]{40}$')
__slots__ = tuple()
__slots__ = ()

def __repr__(self):
"""Representation of ourselves in git reflog format"""
Expand Down
2 changes: 1 addition & 1 deletion git/refs/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Reference(SymbolicReference, LazyMixin, Iterable):

"""Represents a named reference to any object. Subclasses may apply restrictions though,
i.e. Heads can only point to commits."""
__slots__ = tuple()
__slots__ = ()
_points_to_commits_only = False
_resolve_ref_on_create = True
_common_path_default = "refs"
Expand Down
2 changes: 1 addition & 1 deletion git/refs/symbolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def delete(cls, repo, path):
pack_file_path = cls._get_packed_refs_path(repo)
try:
with open(pack_file_path, 'rb') as reader:
new_lines = list()
new_lines = []
made_change = False
dropped_last_line = False
for line in reader:
Expand Down
2 changes: 1 addition & 1 deletion git/refs/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TagReference(Reference):
if tagref.tag is not None:
print(tagref.tag.message)"""

__slots__ = tuple()
__slots__ = ()
_common_path_default = "refs/tags"

@property
Expand Down
2 changes: 1 addition & 1 deletion git/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def _get_fetch_info_from_stderr(self, proc, progress):
# lines which are no progress are fetch info lines
# this also waits for the command to finish
# Skip some progress lines that don't provide relevant information
fetch_info_lines = list()
fetch_info_lines = []
# Basically we want all fetch info lines which appear to be in regular form, and thus have a
# command character. Everything else we ignore,
cmds = set(FetchInfo._flag_map.keys())
Expand Down
Loading