Make Python code more idiomatic
This commit is contained in:
@@ -357,7 +357,7 @@ Log files will log the path to tracks relative to this directory.
|
||||
logger.debug('ripIfNotRipped: path %r' % path)
|
||||
trackResult.number = number
|
||||
|
||||
assert type(path) is unicode, "%r is not unicode" % path
|
||||
assert isinstance(path, unicode), "%r is not unicode" % path
|
||||
trackResult.filename = path
|
||||
if number > 0:
|
||||
trackResult.pregap = self.itable.tracks[number - 1].getPregap()
|
||||
|
||||
@@ -36,7 +36,7 @@ def main():
|
||||
ret = cmd.do()
|
||||
except SystemError as e:
|
||||
sys.stderr.write('whipper: error: %s\n' % e)
|
||||
if (type(e) is common.EjectError and
|
||||
if (isinstance(e, common.EjectError) and
|
||||
cmd.options.eject in ('failure', 'always')):
|
||||
eject_device(e.device)
|
||||
return 255
|
||||
|
||||
@@ -197,7 +197,7 @@ def getRealPath(refPath, filePath):
|
||||
|
||||
@type filePath: unicode
|
||||
"""
|
||||
assert type(filePath) is unicode, "%r is not unicode" % filePath
|
||||
assert isinstance(filePath, unicode), "%r is not unicode" % filePath
|
||||
|
||||
if os.path.exists(filePath):
|
||||
return filePath
|
||||
|
||||
@@ -25,7 +25,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _listify(listOrString):
|
||||
if type(listOrString) == str:
|
||||
if isinstance(listOrString, str):
|
||||
return [listOrString, ]
|
||||
|
||||
return listOrString
|
||||
|
||||
@@ -115,7 +115,7 @@ class Program:
|
||||
tdict = {}
|
||||
|
||||
# Ignore old cache, since we do not know what offset it used.
|
||||
if type(ptable.object) is dict:
|
||||
if isinstance(ptable.object, dict):
|
||||
tdict = ptable.object
|
||||
|
||||
if offset in tdict:
|
||||
@@ -193,8 +193,8 @@ class Program:
|
||||
- %x: audio extension, lowercase
|
||||
- %X: audio extension, uppercase
|
||||
"""
|
||||
assert type(outdir) is unicode, "%r is not unicode" % outdir
|
||||
assert type(template) is unicode, "%r is not unicode" % template
|
||||
assert isinstance(outdir, unicode), "%r is not unicode" % outdir
|
||||
assert isinstance(template, unicode), "%r is not unicode" % template
|
||||
v = {}
|
||||
v['A'] = 'Unknown Artist'
|
||||
v['d'] = mbdiscid # fallback for title
|
||||
|
||||
@@ -71,7 +71,7 @@ class CueFile(object):
|
||||
"""
|
||||
@type path: unicode
|
||||
"""
|
||||
assert type(path) is unicode, "%r is not unicode" % path
|
||||
assert isinstance(path, unicode), "%r is not unicode" % path
|
||||
|
||||
self._path = path
|
||||
self._rems = {}
|
||||
@@ -196,7 +196,7 @@ class File:
|
||||
"""
|
||||
@type path: unicode
|
||||
"""
|
||||
assert type(path) is unicode, "%r is not unicode" % path
|
||||
assert isinstance(path, unicode), "%r is not unicode" % path
|
||||
|
||||
self.path = path
|
||||
self.format = format
|
||||
|
||||
@@ -46,7 +46,7 @@ class Image(object):
|
||||
@type path: unicode
|
||||
@param path: .cue path
|
||||
"""
|
||||
assert type(path) is unicode, "%r is not unicode" % path
|
||||
assert isinstance(path, unicode), "%r is not unicode" % path
|
||||
|
||||
self._path = path
|
||||
self.cue = cue.CueFile(path)
|
||||
@@ -62,7 +62,7 @@ class Image(object):
|
||||
|
||||
@param path: .cue path
|
||||
"""
|
||||
assert type(path) is unicode, "%r is not unicode" % path
|
||||
assert isinstance(path, unicode), "%r is not unicode" % path
|
||||
|
||||
return self.cue.getRealPath(path)
|
||||
|
||||
@@ -129,7 +129,7 @@ class ImageVerifyTask(task.MultiSeparateTask):
|
||||
htoa = cue.table.tracks[0].indexes[0]
|
||||
track = cue.table.tracks[0]
|
||||
path = image.getRealPath(htoa.path)
|
||||
assert type(path) is unicode, "%r is not unicode" % path
|
||||
assert isinstance(path, unicode), "%r is not unicode" % path
|
||||
logger.debug('schedule scan of audio length of %r', path)
|
||||
taskk = AudioLengthTask(path)
|
||||
self.addTask(taskk)
|
||||
@@ -144,7 +144,7 @@ class ImageVerifyTask(task.MultiSeparateTask):
|
||||
|
||||
if length == -1:
|
||||
path = image.getRealPath(index.path)
|
||||
assert type(path) is unicode, "%r is not unicode" % path
|
||||
assert isinstance(path, unicode), "%r is not unicode" % path
|
||||
logger.debug('schedule scan of audio length of %r', path)
|
||||
taskk = AudioLengthTask(path)
|
||||
self.addTask(taskk)
|
||||
@@ -190,7 +190,7 @@ class ImageEncodeTask(task.MultiSeparateTask):
|
||||
def add(index):
|
||||
|
||||
path = image.getRealPath(index.path)
|
||||
assert type(path) is unicode, "%r is not unicode" % path
|
||||
assert isinstance(path, unicode), "%r is not unicode" % path
|
||||
logger.debug('schedule encode of %r', path)
|
||||
root, ext = os.path.splitext(os.path.basename(path))
|
||||
outpath = os.path.join(outdir, root + '.' + 'flac')
|
||||
|
||||
@@ -92,7 +92,7 @@ class Track:
|
||||
@type path: unicode or None
|
||||
"""
|
||||
if path is not None:
|
||||
assert type(path) is unicode, "%r is not unicode" % path
|
||||
assert isinstance(path, unicode), "%r is not unicode" % path
|
||||
|
||||
i = Index(number, absolute, path, relative, counter)
|
||||
self.indexes[number] = i
|
||||
@@ -107,13 +107,11 @@ class Track:
|
||||
Typically this is INDEX 01; but it could be INDEX 00 if there's
|
||||
a pre-gap.
|
||||
"""
|
||||
indexes = list(self.indexes.keys())
|
||||
indexes.sort()
|
||||
indexes = sorted(self.indexes.keys())
|
||||
return self.indexes[indexes[0]]
|
||||
|
||||
def getLastIndex(self):
|
||||
indexes = list(self.indexes.keys())
|
||||
indexes.sort()
|
||||
indexes = sorted(self.indexes.keys())
|
||||
return self.indexes[indexes[-1]]
|
||||
|
||||
def getPregap(self):
|
||||
@@ -145,7 +143,7 @@ class Index:
|
||||
counter=None):
|
||||
|
||||
if path is not None:
|
||||
assert type(path) is unicode, "%r is not unicode" % path
|
||||
assert isinstance(path, unicode), "%r is not unicode" % path
|
||||
|
||||
self.number = number
|
||||
self.absolute = absolute
|
||||
@@ -543,8 +541,7 @@ class Table(object):
|
||||
if not track.audio:
|
||||
continue
|
||||
|
||||
indexes = list(track.indexes.keys())
|
||||
indexes.sort()
|
||||
indexes = sorted(track.indexes.keys())
|
||||
|
||||
wroteTrack = False
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ class TocFile(object):
|
||||
"""
|
||||
@type path: unicode
|
||||
"""
|
||||
assert type(path) is unicode, "%r is not unicode" % path
|
||||
assert isinstance(path, unicode), "%r is not unicode" % path
|
||||
self._path = path
|
||||
self._messages = []
|
||||
self.table = table.Table()
|
||||
@@ -430,7 +430,7 @@ class File:
|
||||
@param start: starting point for the track in this file, in frames
|
||||
@param length: length for the track in this file, in frames
|
||||
"""
|
||||
assert type(path) is unicode, "%r is not unicode" % path
|
||||
assert isinstance(path, unicode), "%r is not unicode" % path
|
||||
|
||||
self.path = path
|
||||
self.start = start
|
||||
|
||||
@@ -238,7 +238,7 @@ class ReadTrackTask(task.Task):
|
||||
@param what: a string representing what's being read; e.g. Track
|
||||
@type what: str
|
||||
"""
|
||||
assert type(path) is unicode, "%r is not unicode" % path
|
||||
assert isinstance(path, unicode), "%r is not unicode" % path
|
||||
|
||||
self.path = path
|
||||
self._table = table
|
||||
|
||||
@@ -23,7 +23,7 @@ class AudioLengthTask(ctask.PopenTask):
|
||||
"""
|
||||
@type path: unicode
|
||||
"""
|
||||
assert type(path) is unicode, "%r is not unicode" % path
|
||||
assert isinstance(path, unicode), "%r is not unicode" % path
|
||||
|
||||
self.logName = os.path.basename(path).encode('utf-8')
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ def _diff(old, new, desc):
|
||||
|
||||
def diffStrings(orig, new, desc='input'):
|
||||
|
||||
assert type(orig) == type(new), 'type %s and %s are different' % (
|
||||
assert isinstance(orig, type(new)), 'type %s and %s are different' % (
|
||||
type(orig), type(new))
|
||||
|
||||
def _tolines(s):
|
||||
|
||||
Reference in New Issue
Block a user