summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@jelmer.uk>2017-02-05 22:46:43 +0000
committerJelmer Vernooij <jelmer@jelmer.uk>2017-02-05 22:46:43 +0000
commitde1f93ebac2c1fb27bf84749d55f6c12a0d0321e (patch)
tree3450e53ee701428585c4eb09f49ec578273c1843
parentf6a40577562bb4d3b91b0ef27565b299f9613043 (diff)
Use more idiomatic python.
-rw-r--r--dulwich/client.py12
-rw-r--r--dulwich/pack.py6
-rw-r--r--dulwich/patch.py4
-rw-r--r--dulwich/porcelain.py8
4 files changed, 13 insertions, 17 deletions
diff --git a/dulwich/client.py b/dulwich/client.py
index 07e127b0..5fbdcb8c 100644
--- a/dulwich/client.py
+++ b/dulwich/client.py
@@ -677,9 +677,9 @@ class TCPGitClient(TraditionalGitClient):
return urlparse.urlunsplit(("git", netloc, path, '', ''))
def _connect(self, cmd, path):
- if type(cmd) is not bytes:
+ if not isinstance(cmd, bytes):
raise TypeError(cmd)
- if type(path) is not bytes:
+ if not isinstance(path, bytes):
path = path.encode(self._remote_path_encoding)
sockaddrs = socket.getaddrinfo(
self._host, self._port, socket.AF_UNSPEC, socket.SOCK_STREAM)
@@ -777,9 +777,9 @@ class SubprocessGitClient(TraditionalGitClient):
git_command = None
def _connect(self, service, path):
- if type(service) is not bytes:
+ if not isinstance(service, bytes):
raise TypeError(service)
- if type(path) is not bytes:
+ if not isinstance(path, bytes):
path = path.encode(self._remote_path_encoding)
if self.git_command is None:
git_command = find_git_command()
@@ -1002,9 +1002,9 @@ class SSHGitClient(TraditionalGitClient):
return cmd
def _connect(self, cmd, path):
- if type(cmd) is not bytes:
+ if not isinstance(cmd, bytes):
raise TypeError(cmd)
- if type(path) is not bytes:
+ if not isinstance(path, bytes):
path = path.encode(self._remote_path_encoding)
if path.startswith(b"/~"):
path = path[1:]
diff --git a/dulwich/pack.py b/dulwich/pack.py
index 54af2e03..878162b9 100644
--- a/dulwich/pack.py
+++ b/dulwich/pack.py
@@ -1158,8 +1158,7 @@ class PackData(object):
object count
:return: List of tuples with (sha, offset, crc32)
"""
- ret = list(self.iterentries(progress=progress))
- ret.sort()
+ ret = sorted(self.iterentries(progress=progress))
return ret
def create_index_v1(self, filename, progress=None):
@@ -1495,8 +1494,7 @@ def write_pack(filename, objects, deltify=None, delta_window_size=None):
with GitFile(filename + '.pack', 'wb') as f:
entries, data_sum = write_pack_objects(f, objects,
delta_window_size=delta_window_size, deltify=deltify)
- entries = [(k, v[0], v[1]) for (k, v) in entries.items()]
- entries.sort()
+ entries = sorted([(k, v[0], v[1]) for (k, v) in entries.items()])
with GitFile(filename + '.idx', 'wb') as f:
return data_sum, write_pack_index_v2(f, entries, data_sum)
diff --git a/dulwich/patch.py b/dulwich/patch.py
index 32f4df05..3c3158e9 100644
--- a/dulwich/patch.py
+++ b/dulwich/patch.py
@@ -45,7 +45,7 @@ def write_commit_patch(f, commit, contents, progress, version=None, encoding=Non
:return: tuple with filename and contents
"""
encoding = encoding or getattr(f, "encoding", "ascii")
- if type(contents) is str:
+ if isinstance(contents, str):
contents = contents.encode(encoding)
(num, total) = progress
f.write(b"From " + commit.id + b" " + time.ctime(commit.commit_time).encode(encoding) + b"\n")
@@ -255,7 +255,7 @@ def git_am_patch_split(f, encoding=None):
"""
encoding = encoding or getattr(f, "encoding", "ascii")
contents = f.read()
- if type(contents) is bytes and getattr(email.parser, "BytesParser", None):
+ if isinstance(contents, bytes) and getattr(email.parser, "BytesParser", None):
parser = email.parser.BytesParser()
msg = parser.parsebytes(contents)
else:
diff --git a/dulwich/porcelain.py b/dulwich/porcelain.py
index bcf23073..a9efcf26 100644
--- a/dulwich/porcelain.py
+++ b/dulwich/porcelain.py
@@ -448,7 +448,7 @@ def print_name_status(changes):
for change in changes:
if not change:
continue
- if type(change) is list:
+ if isinstance(change, list):
change = change[0]
if change.type == CHANGE_ADD:
path1 = change.new.path
@@ -605,8 +605,7 @@ def tag_list(repo, outstream=sys.stdout):
:param outstream: Stream to write tags to
"""
with open_repo_closing(repo) as r:
- tags = list(r.refs.as_dict(b"refs/tags"))
- tags.sort()
+ tags = sorted(r.refs.as_dict(b"refs/tags"))
return tags
@@ -948,8 +947,7 @@ def pack_objects(repo, object_ids, packf, idxf, delta_window_size=None):
r.object_store.iter_shas((oid, None) for oid in object_ids),
delta_window_size=delta_window_size)
if idxf is not None:
- entries = [(k, v[0], v[1]) for (k, v) in entries.items()]
- entries.sort()
+ entries = sorted([(k, v[0], v[1]) for (k, v) in entries.items()])
write_pack_index(idxf, entries, data_sum)