summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo van Kemenade <hugovk@users.noreply.github.com>2022-11-16 18:17:20 +0200
committerHugo van Kemenade <hugovk@users.noreply.github.com>2022-11-16 18:17:20 +0200
commit7a68270d6c78b81f577b433dc6351b26bc27b7cf (patch)
tree12f0a4ff8748c723e8fa750720b32037a4debe90
parentfaed217d14965932b333c07219ed401a661d2651 (diff)
downloadgitdb-7a68270d6c78b81f577b433dc6351b26bc27b7cf.tar.gz
Upgrade Python syntax with pyupgrade --py37-plus
-rw-r--r--doc/source/conf.py9
-rw-r--r--gitdb/db/base.py12
-rw-r--r--gitdb/db/git.py4
-rw-r--r--gitdb/db/loose.py4
-rw-r--r--gitdb/db/mem.py2
-rw-r--r--gitdb/db/pack.py2
-rw-r--r--gitdb/db/ref.py8
-rw-r--r--gitdb/fun.py2
-rw-r--r--gitdb/pack.py4
-rw-r--r--gitdb/stream.py12
-rw-r--r--gitdb/test/db/test_ref.py2
-rw-r--r--gitdb/test/lib.py6
-rw-r--r--gitdb/test/performance/test_pack.py1
-rw-r--r--gitdb/test/performance/test_pack_streaming.py1
-rw-r--r--gitdb/test/performance/test_stream.py1
-rw-r--r--gitdb/test/test_example.py2
-rw-r--r--gitdb/test/test_stream.py4
-rw-r--r--gitdb/util.py14
18 files changed, 43 insertions, 47 deletions
diff --git a/doc/source/conf.py b/doc/source/conf.py
index 3ab15ab..b387f60 100644
--- a/doc/source/conf.py
+++ b/doc/source/conf.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
#
# GitDB documentation build configuration file, created by
# sphinx-quickstart on Wed Jun 30 00:01:32 2010.
@@ -38,8 +37,8 @@ source_suffix = '.rst'
master_doc = 'index'
# General information about the project.
-project = u'GitDB'
-copyright = u'2011, Sebastian Thiel'
+project = 'GitDB'
+copyright = '2011, Sebastian Thiel'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
@@ -172,8 +171,8 @@ htmlhelp_basename = 'GitDBdoc'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
- ('index', 'GitDB.tex', u'GitDB Documentation',
- u'Sebastian Thiel', 'manual'),
+ ('index', 'GitDB.tex', 'GitDB Documentation',
+ 'Sebastian Thiel', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
diff --git a/gitdb/db/base.py b/gitdb/db/base.py
index f0b8a05..e89052e 100644
--- a/gitdb/db/base.py
+++ b/gitdb/db/base.py
@@ -22,7 +22,7 @@ from functools import reduce
__all__ = ('ObjectDBR', 'ObjectDBW', 'FileDBBase', 'CompoundDB', 'CachingDB')
-class ObjectDBR(object):
+class ObjectDBR:
"""Defines an interface for object database lookup.
Objects are identified either by their 20 byte bin sha"""
@@ -63,7 +63,7 @@ class ObjectDBR(object):
#} END query interface
-class ObjectDBW(object):
+class ObjectDBW:
"""Defines an interface to create objects in the database"""
@@ -105,7 +105,7 @@ class ObjectDBW(object):
#} END edit interface
-class FileDBBase(object):
+class FileDBBase:
"""Provides basic facilities to retrieve files of interest, including
caching facilities to help mapping hexsha's to objects"""
@@ -117,7 +117,7 @@ class FileDBBase(object):
**Note:** The base will not perform any accessablity checking as the base
might not yet be accessible, but become accessible before the first
access."""
- super(FileDBBase, self).__init__()
+ super().__init__()
self._root_path = root_path
#{ Interface
@@ -133,7 +133,7 @@ class FileDBBase(object):
#} END interface
-class CachingDB(object):
+class CachingDB:
"""A database which uses caches to speed-up access"""
@@ -176,7 +176,7 @@ class CompoundDB(ObjectDBR, LazyMixin, CachingDB):
elif attr == '_db_cache':
self._db_cache = dict()
else:
- super(CompoundDB, self)._set_cache_(attr)
+ super()._set_cache_(attr)
def _db_query(self, sha):
""":return: database containing the given 20 byte sha
diff --git a/gitdb/db/git.py b/gitdb/db/git.py
index 7a43d72..e2cb468 100644
--- a/gitdb/db/git.py
+++ b/gitdb/db/git.py
@@ -39,7 +39,7 @@ class GitDB(FileDBBase, ObjectDBW, CompoundDB):
def __init__(self, root_path):
"""Initialize ourselves on a git objects directory"""
- super(GitDB, self).__init__(root_path)
+ super().__init__(root_path)
def _set_cache_(self, attr):
if attr == '_dbs' or attr == '_loose_db':
@@ -68,7 +68,7 @@ class GitDB(FileDBBase, ObjectDBW, CompoundDB):
# finally set the value
self._loose_db = loose_db
else:
- super(GitDB, self)._set_cache_(attr)
+ super()._set_cache_(attr)
# END handle attrs
#{ ObjectDBW interface
diff --git a/gitdb/db/loose.py b/gitdb/db/loose.py
index a63a2ef..4ef7750 100644
--- a/gitdb/db/loose.py
+++ b/gitdb/db/loose.py
@@ -75,7 +75,7 @@ class LooseObjectDB(FileDBBase, ObjectDBR, ObjectDBW):
new_objects_mode = int("644", 8)
def __init__(self, root_path):
- super(LooseObjectDB, self).__init__(root_path)
+ super().__init__(root_path)
self._hexsha_to_file = dict()
# Additional Flags - might be set to 0 after the first failure
# Depending on the root, this might work for some mounts, for others not, which
@@ -151,7 +151,7 @@ class LooseObjectDB(FileDBBase, ObjectDBR, ObjectDBW):
""":raise TypeError: if the stream does not support the Sha1Writer interface"""
if stream is not None and not isinstance(stream, Sha1Writer):
raise TypeError("Output stream musst support the %s interface" % Sha1Writer.__name__)
- return super(LooseObjectDB, self).set_ostream(stream)
+ return super().set_ostream(stream)
def info(self, sha):
m = self._map_loose_object(sha)
diff --git a/gitdb/db/mem.py b/gitdb/db/mem.py
index b2542ff..1b954cb 100644
--- a/gitdb/db/mem.py
+++ b/gitdb/db/mem.py
@@ -37,7 +37,7 @@ class MemoryDB(ObjectDBR, ObjectDBW):
exists in the target storage before introducing actual IO"""
def __init__(self):
- super(MemoryDB, self).__init__()
+ super().__init__()
self._db = LooseObjectDB("path/doesnt/matter")
# maps 20 byte shas to their OStream objects
diff --git a/gitdb/db/pack.py b/gitdb/db/pack.py
index 90de02b..1ce786b 100644
--- a/gitdb/db/pack.py
+++ b/gitdb/db/pack.py
@@ -39,7 +39,7 @@ class PackedDB(FileDBBase, ObjectDBR, CachingDB, LazyMixin):
_sort_interval = 500
def __init__(self, root_path):
- super(PackedDB, self).__init__(root_path)
+ super().__init__(root_path)
# list of lists with three items:
# * hits - number of times the pack was hit with a request
# * entity - Pack entity instance
diff --git a/gitdb/db/ref.py b/gitdb/db/ref.py
index 2bb1de7..6bb2a64 100644
--- a/gitdb/db/ref.py
+++ b/gitdb/db/ref.py
@@ -20,7 +20,7 @@ class ReferenceDB(CompoundDB):
ObjectDBCls = None
def __init__(self, ref_file):
- super(ReferenceDB, self).__init__()
+ super().__init__()
self._ref_file = ref_file
def _set_cache_(self, attr):
@@ -28,7 +28,7 @@ class ReferenceDB(CompoundDB):
self._dbs = list()
self._update_dbs_from_ref_file()
else:
- super(ReferenceDB, self)._set_cache_(attr)
+ super()._set_cache_(attr)
# END handle attrs
def _update_dbs_from_ref_file(self):
@@ -44,7 +44,7 @@ class ReferenceDB(CompoundDB):
try:
with codecs.open(self._ref_file, 'r', encoding="utf-8") as f:
ref_paths = [l.strip() for l in f]
- except (OSError, IOError):
+ except OSError:
pass
# END handle alternates
@@ -79,4 +79,4 @@ class ReferenceDB(CompoundDB):
def update_cache(self, force=False):
# re-read alternates and update databases
self._update_dbs_from_ref_file()
- return super(ReferenceDB, self).update_cache(force)
+ return super().update_cache(force)
diff --git a/gitdb/fun.py b/gitdb/fun.py
index abb4277..a4454de 100644
--- a/gitdb/fun.py
+++ b/gitdb/fun.py
@@ -113,7 +113,7 @@ def delta_chunk_apply(dc, bbuf, write):
# END handle chunk mode
-class DeltaChunk(object):
+class DeltaChunk:
"""Represents a piece of a delta, it can either add new data, or copy existing
one from a source buffer"""
diff --git a/gitdb/pack.py b/gitdb/pack.py
index 0b26c12..cabce4c 100644
--- a/gitdb/pack.py
+++ b/gitdb/pack.py
@@ -170,7 +170,7 @@ def write_stream_to_pack(read, write, zstream, base_crc=None):
#} END utilities
-class IndexWriter(object):
+class IndexWriter:
"""Utility to cache index information, allowing to write all information later
in one go to the given stream
@@ -257,7 +257,7 @@ class PackIndexFile(LazyMixin):
index_version_default = 2
def __init__(self, indexpath):
- super(PackIndexFile, self).__init__()
+ super().__init__()
self._indexpath = indexpath
def close(self):
diff --git a/gitdb/stream.py b/gitdb/stream.py
index 37380ad..222b843 100644
--- a/gitdb/stream.py
+++ b/gitdb/stream.py
@@ -219,13 +219,13 @@ class DecompressMemMapReader(LazyMixin):
# END clamp size
if size == 0:
- return bytes()
+ return b''
# END handle depletion
# deplete the buffer, then just continue using the decompress object
# which has an own buffer. We just need this to transparently parse the
# header from the zlib stream
- dat = bytes()
+ dat = b''
if self._buf:
if self._buflen >= size:
# have enough data
@@ -553,7 +553,7 @@ class DeltaApplyReader(LazyMixin):
#{ W Streams
-class Sha1Writer(object):
+class Sha1Writer:
"""Simple stream writer which produces a sha whenever you like as it degests
everything it is supposed to write"""
@@ -650,7 +650,7 @@ class FDCompressedSha1Writer(Sha1Writer):
exc = IOError("Failed to write all bytes to filedescriptor")
def __init__(self, fd):
- super(FDCompressedSha1Writer, self).__init__()
+ super().__init__()
self.fd = fd
self.zip = zlib.compressobj(zlib.Z_BEST_SPEED)
@@ -677,7 +677,7 @@ class FDCompressedSha1Writer(Sha1Writer):
#} END stream interface
-class FDStream(object):
+class FDStream:
"""A simple wrapper providing the most basic functions on a file descriptor
with the fileobject interface. Cannot use os.fdopen as the resulting stream
@@ -711,7 +711,7 @@ class FDStream(object):
close(self._fd)
-class NullStream(object):
+class NullStream:
"""A stream that does nothing but providing a stream interface.
Use it like /dev/null"""
diff --git a/gitdb/test/db/test_ref.py b/gitdb/test/db/test_ref.py
index 2049698..664aa54 100644
--- a/gitdb/test/db/test_ref.py
+++ b/gitdb/test/db/test_ref.py
@@ -23,7 +23,7 @@ class TestReferenceDB(TestDBBase):
The list can be empty"""
with open(alt_path, "wb") as alt_file:
for alt in alt_list:
- alt_file.write(alt.encode("utf-8") + "\n".encode("ascii"))
+ alt_file.write(alt.encode("utf-8") + b"\n")
@with_rw_directory
def test_writing(self, path):
diff --git a/gitdb/test/lib.py b/gitdb/test/lib.py
index 465a899..da59d3b 100644
--- a/gitdb/test/lib.py
+++ b/gitdb/test/lib.py
@@ -40,7 +40,7 @@ class TestBase(unittest.TestCase):
@classmethod
def setUpClass(cls):
try:
- super(TestBase, cls).setUpClass()
+ super().setUpClass()
except AttributeError:
pass
@@ -70,7 +70,7 @@ def with_rw_directory(func):
try:
return func(self, path)
except Exception:
- sys.stderr.write("Test {}.{} failed, output is at {!r}\n".format(type(self).__name__, func.__name__, path))
+ sys.stderr.write(f"Test {type(self).__name__}.{func.__name__} failed, output is at {path!r}\n")
keep = True
raise
finally:
@@ -161,7 +161,7 @@ def make_memory_file(size_in_bytes, randomize=False):
#{ Stream Utilities
-class DummyStream(object):
+class DummyStream:
def __init__(self):
self.was_read = False
diff --git a/gitdb/test/performance/test_pack.py b/gitdb/test/performance/test_pack.py
index 643186b..f034baf 100644
--- a/gitdb/test/performance/test_pack.py
+++ b/gitdb/test/performance/test_pack.py
@@ -3,7 +3,6 @@
# This module is part of GitDB and is released under
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
"""Performance tests for object store"""
-from __future__ import print_function
from gitdb.test.performance.lib import (
TestBigRepoR
diff --git a/gitdb/test/performance/test_pack_streaming.py b/gitdb/test/performance/test_pack_streaming.py
index 5bf6790..db790f1 100644
--- a/gitdb/test/performance/test_pack_streaming.py
+++ b/gitdb/test/performance/test_pack_streaming.py
@@ -3,7 +3,6 @@
# This module is part of GitDB and is released under
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
"""Specific test for pack streams only"""
-from __future__ import print_function
from gitdb.test.performance.lib import (
TestBigRepoR
diff --git a/gitdb/test/performance/test_stream.py b/gitdb/test/performance/test_stream.py
index 9a8b15b..91dc891 100644
--- a/gitdb/test/performance/test_stream.py
+++ b/gitdb/test/performance/test_stream.py
@@ -3,7 +3,6 @@
# This module is part of GitDB and is released under
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
"""Performance data streaming performance"""
-from __future__ import print_function
from gitdb.test.performance.lib import TestBigRepoR
from gitdb.db import LooseObjectDB
diff --git a/gitdb/test/test_example.py b/gitdb/test/test_example.py
index 6e80bf5..cc4d40d 100644
--- a/gitdb/test/test_example.py
+++ b/gitdb/test/test_example.py
@@ -32,7 +32,7 @@ class TestExamples(TestBase):
pass
# END ignore exception if there are no loose objects
- data = "my data".encode("ascii")
+ data = b"my data"
istream = IStream("blob", len(data), BytesIO(data))
# the object does not yet have a sha
diff --git a/gitdb/test/test_stream.py b/gitdb/test/test_stream.py
index 5d4b93d..5e2e1ba 100644
--- a/gitdb/test/test_stream.py
+++ b/gitdb/test/test_stream.py
@@ -115,13 +115,13 @@ class TestStream(TestBase):
def test_sha_writer(self):
writer = Sha1Writer()
- assert 2 == writer.write("hi".encode("ascii"))
+ assert 2 == writer.write(b"hi")
assert len(writer.sha(as_hex=1)) == 40
assert len(writer.sha(as_hex=0)) == 20
# make sure it does something ;)
prev_sha = writer.sha()
- writer.write("hi again".encode("ascii"))
+ writer.write(b"hi again")
assert writer.sha() != prev_sha
def test_compressed_writer(self):
diff --git a/gitdb/util.py b/gitdb/util.py
index f9f8c0e..3151c06 100644
--- a/gitdb/util.py
+++ b/gitdb/util.py
@@ -94,7 +94,7 @@ from gitdb.const import (
#{ compatibility stuff ...
-class _RandomAccessBytesIO(object):
+class _RandomAccessBytesIO:
"""Wrapper to provide required functionality in case memory maps cannot or may
not be used. This is only really required in python 2.4"""
@@ -131,7 +131,7 @@ def byte_ord(b):
#{ Routines
-def make_sha(source=''.encode("ascii")):
+def make_sha(source=b''):
"""A python2.4 workaround for the sha/hashlib module fiasco
**Note** From the dulwich project """
@@ -151,7 +151,7 @@ def allocate_memory(size):
try:
return mmap.mmap(-1, size) # read-write by default
- except EnvironmentError:
+ except OSError:
# setup real memory instead
# this of course may fail if the amount of memory is not available in
# one chunk - would only be the case in python 2.4, being more likely on
@@ -174,7 +174,7 @@ def file_contents_ro(fd, stream=False, allow_mmap=True):
# supports stream and random access
try:
return mmap.mmap(fd, 0, access=mmap.ACCESS_READ)
- except EnvironmentError:
+ except OSError:
# python 2.4 issue, 0 wants to be the actual size
return mmap.mmap(fd, os.fstat(fd).st_size, access=mmap.ACCESS_READ)
# END handle python 2.4
@@ -234,7 +234,7 @@ def to_bin_sha(sha):
#{ Utilities
-class LazyMixin(object):
+class LazyMixin:
"""
Base class providing an interface to lazily retrieve attribute values upon
@@ -266,7 +266,7 @@ class LazyMixin(object):
pass
-class LockedFD(object):
+class LockedFD:
"""
This class facilitates a safe read and write operation to a file on disk.
@@ -327,7 +327,7 @@ class LockedFD(object):
self._fd = fd
# END handle file descriptor
except OSError as e:
- raise IOError("Lock at %r could not be obtained" % self._lockfilepath()) from e
+ raise OSError("Lock at %r could not be obtained" % self._lockfilepath()) from e
# END handle lock retrieval
# open actual file if required