Skip to content

Commit 7a68270

Browse files
committed
Upgrade Python syntax with pyupgrade --py37-plus
1 parent faed217 commit 7a68270

18 files changed

+43
-47
lines changed

doc/source/conf.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# GitDB documentation build configuration file, created by
43
# sphinx-quickstart on Wed Jun 30 00:01:32 2010.
@@ -38,8 +37,8 @@
3837
master_doc = 'index'
3938

4039
# General information about the project.
41-
project = u'GitDB'
42-
copyright = u'2011, Sebastian Thiel'
40+
project = 'GitDB'
41+
copyright = '2011, Sebastian Thiel'
4342

4443
# The version info for the project you're documenting, acts as replacement for
4544
# |version| and |release|, also used in various other places throughout the
@@ -172,8 +171,8 @@
172171
# Grouping the document tree into LaTeX files. List of tuples
173172
# (source start file, target name, title, author, documentclass [howto/manual]).
174173
latex_documents = [
175-
('index', 'GitDB.tex', u'GitDB Documentation',
176-
u'Sebastian Thiel', 'manual'),
174+
('index', 'GitDB.tex', 'GitDB Documentation',
175+
'Sebastian Thiel', 'manual'),
177176
]
178177

179178
# The name of an image file (relative to this directory) to place at the top of

gitdb/db/base.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
__all__ = ('ObjectDBR', 'ObjectDBW', 'FileDBBase', 'CompoundDB', 'CachingDB')
2323

2424

25-
class ObjectDBR(object):
25+
class ObjectDBR:
2626

2727
"""Defines an interface for object database lookup.
2828
Objects are identified either by their 20 byte bin sha"""
@@ -63,7 +63,7 @@ def sha_iter(self):
6363
#} END query interface
6464

6565

66-
class ObjectDBW(object):
66+
class ObjectDBW:
6767

6868
"""Defines an interface to create objects in the database"""
6969

@@ -105,7 +105,7 @@ def store(self, istream):
105105
#} END edit interface
106106

107107

108-
class FileDBBase(object):
108+
class FileDBBase:
109109

110110
"""Provides basic facilities to retrieve files of interest, including
111111
caching facilities to help mapping hexsha's to objects"""
@@ -117,7 +117,7 @@ def __init__(self, root_path):
117117
**Note:** The base will not perform any accessablity checking as the base
118118
might not yet be accessible, but become accessible before the first
119119
access."""
120-
super(FileDBBase, self).__init__()
120+
super().__init__()
121121
self._root_path = root_path
122122

123123
#{ Interface
@@ -133,7 +133,7 @@ def db_path(self, rela_path):
133133
#} END interface
134134

135135

136-
class CachingDB(object):
136+
class CachingDB:
137137

138138
"""A database which uses caches to speed-up access"""
139139

@@ -176,7 +176,7 @@ def _set_cache_(self, attr):
176176
elif attr == '_db_cache':
177177
self._db_cache = dict()
178178
else:
179-
super(CompoundDB, self)._set_cache_(attr)
179+
super()._set_cache_(attr)
180180

181181
def _db_query(self, sha):
182182
""":return: database containing the given 20 byte sha

gitdb/db/git.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class GitDB(FileDBBase, ObjectDBW, CompoundDB):
3939

4040
def __init__(self, root_path):
4141
"""Initialize ourselves on a git objects directory"""
42-
super(GitDB, self).__init__(root_path)
42+
super().__init__(root_path)
4343

4444
def _set_cache_(self, attr):
4545
if attr == '_dbs' or attr == '_loose_db':
@@ -68,7 +68,7 @@ def _set_cache_(self, attr):
6868
# finally set the value
6969
self._loose_db = loose_db
7070
else:
71-
super(GitDB, self)._set_cache_(attr)
71+
super()._set_cache_(attr)
7272
# END handle attrs
7373

7474
#{ ObjectDBW interface

gitdb/db/loose.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class LooseObjectDB(FileDBBase, ObjectDBR, ObjectDBW):
7575
new_objects_mode = int("644", 8)
7676

7777
def __init__(self, root_path):
78-
super(LooseObjectDB, self).__init__(root_path)
78+
super().__init__(root_path)
7979
self._hexsha_to_file = dict()
8080
# Additional Flags - might be set to 0 after the first failure
8181
# Depending on the root, this might work for some mounts, for others not, which
@@ -151,7 +151,7 @@ def set_ostream(self, stream):
151151
""":raise TypeError: if the stream does not support the Sha1Writer interface"""
152152
if stream is not None and not isinstance(stream, Sha1Writer):
153153
raise TypeError("Output stream musst support the %s interface" % Sha1Writer.__name__)
154-
return super(LooseObjectDB, self).set_ostream(stream)
154+
return super().set_ostream(stream)
155155

156156
def info(self, sha):
157157
m = self._map_loose_object(sha)

gitdb/db/mem.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class MemoryDB(ObjectDBR, ObjectDBW):
3737
exists in the target storage before introducing actual IO"""
3838

3939
def __init__(self):
40-
super(MemoryDB, self).__init__()
40+
super().__init__()
4141
self._db = LooseObjectDB("path/doesnt/matter")
4242

4343
# maps 20 byte shas to their OStream objects

gitdb/db/pack.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class PackedDB(FileDBBase, ObjectDBR, CachingDB, LazyMixin):
3939
_sort_interval = 500
4040

4141
def __init__(self, root_path):
42-
super(PackedDB, self).__init__(root_path)
42+
super().__init__(root_path)
4343
# list of lists with three items:
4444
# * hits - number of times the pack was hit with a request
4545
# * entity - Pack entity instance

gitdb/db/ref.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ class ReferenceDB(CompoundDB):
2020
ObjectDBCls = None
2121

2222
def __init__(self, ref_file):
23-
super(ReferenceDB, self).__init__()
23+
super().__init__()
2424
self._ref_file = ref_file
2525

2626
def _set_cache_(self, attr):
2727
if attr == '_dbs':
2828
self._dbs = list()
2929
self._update_dbs_from_ref_file()
3030
else:
31-
super(ReferenceDB, self)._set_cache_(attr)
31+
super()._set_cache_(attr)
3232
# END handle attrs
3333

3434
def _update_dbs_from_ref_file(self):
@@ -44,7 +44,7 @@ def _update_dbs_from_ref_file(self):
4444
try:
4545
with codecs.open(self._ref_file, 'r', encoding="utf-8") as f:
4646
ref_paths = [l.strip() for l in f]
47-
except (OSError, IOError):
47+
except OSError:
4848
pass
4949
# END handle alternates
5050

@@ -79,4 +79,4 @@ def _update_dbs_from_ref_file(self):
7979
def update_cache(self, force=False):
8080
# re-read alternates and update databases
8181
self._update_dbs_from_ref_file()
82-
return super(ReferenceDB, self).update_cache(force)
82+
return super().update_cache(force)

gitdb/fun.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def delta_chunk_apply(dc, bbuf, write):
113113
# END handle chunk mode
114114

115115

116-
class DeltaChunk(object):
116+
class DeltaChunk:
117117

118118
"""Represents a piece of a delta, it can either add new data, or copy existing
119119
one from a source buffer"""

gitdb/pack.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def write_stream_to_pack(read, write, zstream, base_crc=None):
170170
#} END utilities
171171

172172

173-
class IndexWriter(object):
173+
class IndexWriter:
174174

175175
"""Utility to cache index information, allowing to write all information later
176176
in one go to the given stream
@@ -257,7 +257,7 @@ class PackIndexFile(LazyMixin):
257257
index_version_default = 2
258258

259259
def __init__(self, indexpath):
260-
super(PackIndexFile, self).__init__()
260+
super().__init__()
261261
self._indexpath = indexpath
262262

263263
def close(self):

gitdb/stream.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,13 @@ def read(self, size=-1):
219219
# END clamp size
220220

221221
if size == 0:
222-
return bytes()
222+
return b''
223223
# END handle depletion
224224

225225
# deplete the buffer, then just continue using the decompress object
226226
# which has an own buffer. We just need this to transparently parse the
227227
# header from the zlib stream
228-
dat = bytes()
228+
dat = b''
229229
if self._buf:
230230
if self._buflen >= size:
231231
# have enough data
@@ -553,7 +553,7 @@ def size(self):
553553

554554
#{ W Streams
555555

556-
class Sha1Writer(object):
556+
class Sha1Writer:
557557

558558
"""Simple stream writer which produces a sha whenever you like as it degests
559559
everything it is supposed to write"""
@@ -650,7 +650,7 @@ class FDCompressedSha1Writer(Sha1Writer):
650650
exc = IOError("Failed to write all bytes to filedescriptor")
651651

652652
def __init__(self, fd):
653-
super(FDCompressedSha1Writer, self).__init__()
653+
super().__init__()
654654
self.fd = fd
655655
self.zip = zlib.compressobj(zlib.Z_BEST_SPEED)
656656

@@ -677,7 +677,7 @@ def close(self):
677677
#} END stream interface
678678

679679

680-
class FDStream(object):
680+
class FDStream:
681681

682682
"""A simple wrapper providing the most basic functions on a file descriptor
683683
with the fileobject interface. Cannot use os.fdopen as the resulting stream
@@ -711,7 +711,7 @@ def close(self):
711711
close(self._fd)
712712

713713

714-
class NullStream(object):
714+
class NullStream:
715715

716716
"""A stream that does nothing but providing a stream interface.
717717
Use it like /dev/null"""

gitdb/test/db/test_ref.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def make_alt_file(self, alt_path, alt_list):
2323
The list can be empty"""
2424
with open(alt_path, "wb") as alt_file:
2525
for alt in alt_list:
26-
alt_file.write(alt.encode("utf-8") + "\n".encode("ascii"))
26+
alt_file.write(alt.encode("utf-8") + b"\n")
2727

2828
@with_rw_directory
2929
def test_writing(self, path):

gitdb/test/lib.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class TestBase(unittest.TestCase):
4040
@classmethod
4141
def setUpClass(cls):
4242
try:
43-
super(TestBase, cls).setUpClass()
43+
super().setUpClass()
4444
except AttributeError:
4545
pass
4646

@@ -70,7 +70,7 @@ def wrapper(self):
7070
try:
7171
return func(self, path)
7272
except Exception:
73-
sys.stderr.write("Test {}.{} failed, output is at {!r}\n".format(type(self).__name__, func.__name__, path))
73+
sys.stderr.write(f"Test {type(self).__name__}.{func.__name__} failed, output is at {path!r}\n")
7474
keep = True
7575
raise
7676
finally:
@@ -161,7 +161,7 @@ def make_memory_file(size_in_bytes, randomize=False):
161161
#{ Stream Utilities
162162

163163

164-
class DummyStream(object):
164+
class DummyStream:
165165

166166
def __init__(self):
167167
self.was_read = False

gitdb/test/performance/test_pack.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# This module is part of GitDB and is released under
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
55
"""Performance tests for object store"""
6-
from __future__ import print_function
76

87
from gitdb.test.performance.lib import (
98
TestBigRepoR

gitdb/test/performance/test_pack_streaming.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# This module is part of GitDB and is released under
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
55
"""Specific test for pack streams only"""
6-
from __future__ import print_function
76

87
from gitdb.test.performance.lib import (
98
TestBigRepoR

gitdb/test/performance/test_stream.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# This module is part of GitDB and is released under
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
55
"""Performance data streaming performance"""
6-
from __future__ import print_function
76

87
from gitdb.test.performance.lib import TestBigRepoR
98
from gitdb.db import LooseObjectDB

gitdb/test/test_example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_base(self):
3232
pass
3333
# END ignore exception if there are no loose objects
3434

35-
data = "my data".encode("ascii")
35+
data = b"my data"
3636
istream = IStream("blob", len(data), BytesIO(data))
3737

3838
# the object does not yet have a sha

gitdb/test/test_stream.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ def test_decompress_reader(self):
115115

116116
def test_sha_writer(self):
117117
writer = Sha1Writer()
118-
assert 2 == writer.write("hi".encode("ascii"))
118+
assert 2 == writer.write(b"hi")
119119
assert len(writer.sha(as_hex=1)) == 40
120120
assert len(writer.sha(as_hex=0)) == 20
121121

122122
# make sure it does something ;)
123123
prev_sha = writer.sha()
124-
writer.write("hi again".encode("ascii"))
124+
writer.write(b"hi again")
125125
assert writer.sha() != prev_sha
126126

127127
def test_compressed_writer(self):

gitdb/util.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def remove(*args, **kwargs):
9494
#{ compatibility stuff ...
9595

9696

97-
class _RandomAccessBytesIO(object):
97+
class _RandomAccessBytesIO:
9898

9999
"""Wrapper to provide required functionality in case memory maps cannot or may
100100
not be used. This is only really required in python 2.4"""
@@ -131,7 +131,7 @@ def byte_ord(b):
131131
#{ Routines
132132

133133

134-
def make_sha(source=''.encode("ascii")):
134+
def make_sha(source=b''):
135135
"""A python2.4 workaround for the sha/hashlib module fiasco
136136
137137
**Note** From the dulwich project """
@@ -151,7 +151,7 @@ def allocate_memory(size):
151151

152152
try:
153153
return mmap.mmap(-1, size) # read-write by default
154-
except EnvironmentError:
154+
except OSError:
155155
# setup real memory instead
156156
# this of course may fail if the amount of memory is not available in
157157
# 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):
174174
# supports stream and random access
175175
try:
176176
return mmap.mmap(fd, 0, access=mmap.ACCESS_READ)
177-
except EnvironmentError:
177+
except OSError:
178178
# python 2.4 issue, 0 wants to be the actual size
179179
return mmap.mmap(fd, os.fstat(fd).st_size, access=mmap.ACCESS_READ)
180180
# END handle python 2.4
@@ -234,7 +234,7 @@ def to_bin_sha(sha):
234234

235235
#{ Utilities
236236

237-
class LazyMixin(object):
237+
class LazyMixin:
238238

239239
"""
240240
Base class providing an interface to lazily retrieve attribute values upon
@@ -266,7 +266,7 @@ def _set_cache_(self, attr):
266266
pass
267267

268268

269-
class LockedFD(object):
269+
class LockedFD:
270270

271271
"""
272272
This class facilitates a safe read and write operation to a file on disk.
@@ -327,7 +327,7 @@ def open(self, write=False, stream=False):
327327
self._fd = fd
328328
# END handle file descriptor
329329
except OSError as e:
330-
raise IOError("Lock at %r could not be obtained" % self._lockfilepath()) from e
330+
raise OSError("Lock at %r could not be obtained" % self._lockfilepath()) from e
331331
# END handle lock retrieval
332332

333333
# open actual file if required

0 commit comments

Comments
 (0)