Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7a68270

Browse files
committed
Upgrade Python syntax with pyupgrade --py37-plus
1 parentfaed217 commit7a68270

18 files changed

+43
-47
lines changed

‎doc/source/conf.py

Lines changed: 4 additions & 5 deletions
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

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

2424

25-
classObjectDBR(object):
25+
classObjectDBR:
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-
classObjectDBW(object):
66+
classObjectDBW:
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-
classFileDBBase(object):
108+
classFileDBBase:
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-
classCachingDB(object):
136+
classCachingDB:
137137

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

@@ -176,7 +176,7 @@ def _set_cache_(self, attr):
176176
elifattr=='_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

Lines changed: 2 additions & 2 deletions
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
ifattr=='_dbs'orattr=='_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

Lines changed: 2 additions & 2 deletions
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
ifstreamisnotNoneandnotisinstance(stream,Sha1Writer):
153153
raiseTypeError("Output stream musst support the %s interface"%Sha1Writer.__name__)
154-
returnsuper(LooseObjectDB,self).set_ostream(stream)
154+
returnsuper().set_ostream(stream)
155155

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

‎gitdb/db/mem.py

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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
ifattr=='_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
withcodecs.open(self._ref_file,'r',encoding="utf-8")asf:
4646
ref_paths= [l.strip()forlinf]
47-
except(OSError,IOError):
47+
exceptOSError:
4848
pass
4949
# END handle alternates
5050

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

‎gitdb/fun.py

Lines changed: 1 addition & 1 deletion
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-
classDeltaChunk(object):
116+
classDeltaChunk:
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

Lines changed: 2 additions & 2 deletions
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-
classIndexWriter(object):
173+
classIndexWriter:
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
defclose(self):

‎gitdb/stream.py

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

221221
ifsize==0:
222-
returnbytes()
222+
returnb''
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
ifself._buf:
230230
ifself._buflen>=size:
231231
# have enough data
@@ -553,7 +553,7 @@ def size(self):
553553

554554
#{ W Streams
555555

556-
classSha1Writer(object):
556+
classSha1Writer:
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-
classFDStream(object):
680+
classFDStream:
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-
classNullStream(object):
714+
classNullStream:
715715

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

‎gitdb/test/db/test_ref.py

Lines changed: 1 addition & 1 deletion
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
withopen(alt_path,"wb")asalt_file:
2525
foraltinalt_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
deftest_writing(self,path):

‎gitdb/test/lib.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class TestBase(unittest.TestCase):
4040
@classmethod
4141
defsetUpClass(cls):
4242
try:
43-
super(TestBase,cls).setUpClass()
43+
super().setUpClass()
4444
exceptAttributeError:
4545
pass
4646

@@ -70,7 +70,7 @@ def wrapper(self):
7070
try:
7171
returnfunc(self,path)
7272
exceptException:
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-
classDummyStream(object):
164+
classDummyStream:
165165

166166
def__init__(self):
167167
self.was_read=False

‎gitdb/test/performance/test_pack.py

Lines changed: 0 additions & 1 deletion
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__importprint_function
76

87
fromgitdb.test.performance.libimport (
98
TestBigRepoR

‎gitdb/test/performance/test_pack_streaming.py

Lines changed: 0 additions & 1 deletion
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__importprint_function
76

87
fromgitdb.test.performance.libimport (
98
TestBigRepoR

‎gitdb/test/performance/test_stream.py

Lines changed: 0 additions & 1 deletion
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__importprint_function
76

87
fromgitdb.test.performance.libimportTestBigRepoR
98
fromgitdb.dbimportLooseObjectDB

‎gitdb/test/test_example.py

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ def test_decompress_reader(self):
115115

116116
deftest_sha_writer(self):
117117
writer=Sha1Writer()
118-
assert2==writer.write("hi".encode("ascii"))
118+
assert2==writer.write(b"hi")
119119
assertlen(writer.sha(as_hex=1))==40
120120
assertlen(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
assertwriter.sha()!=prev_sha
126126

127127
deftest_compressed_writer(self):

‎gitdb/util.py

Lines changed: 7 additions & 7 deletions
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-
defmake_sha(source=''.encode("ascii")):
134+
defmake_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
returnmmap.mmap(-1,size)# read-write by default
154-
exceptEnvironmentError:
154+
exceptOSError:
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
returnmmap.mmap(fd,0,access=mmap.ACCESS_READ)
177-
exceptEnvironmentError:
177+
exceptOSError:
178178
# python 2.4 issue, 0 wants to be the actual size
179179
returnmmap.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-
classLazyMixin(object):
237+
classLazyMixin:
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-
classLockedFD(object):
269+
classLockedFD:
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
exceptOSErrorase:
330-
raiseIOError("Lock at %r could not be obtained"%self._lockfilepath())frome
330+
raiseOSError("Lock at %r could not be obtained"%self._lockfilepath())frome
331331
# END handle lock retrieval
332332

333333
# open actual file if required

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp