diff --git a/whipper/command/cd.py b/whipper/command/cd.py index 0ee9988..1fd8224 100644 --- a/whipper/command/cd.py +++ b/whipper/command/cd.py @@ -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() diff --git a/whipper/command/main.py b/whipper/command/main.py index b8e1bdd..4889fe9 100644 --- a/whipper/command/main.py +++ b/whipper/command/main.py @@ -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 diff --git a/whipper/common/common.py b/whipper/common/common.py index cb288e7..c8aefd4 100644 --- a/whipper/common/common.py +++ b/whipper/common/common.py @@ -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 diff --git a/whipper/common/drive.py b/whipper/common/drive.py index ccab884..ef5281c 100644 --- a/whipper/common/drive.py +++ b/whipper/common/drive.py @@ -25,7 +25,7 @@ logger = logging.getLogger(__name__) def _listify(listOrString): - if type(listOrString) == str: + if isinstance(listOrString, str): return [listOrString, ] return listOrString diff --git a/whipper/common/program.py b/whipper/common/program.py index d9a9839..abe3094 100644 --- a/whipper/common/program.py +++ b/whipper/common/program.py @@ -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 diff --git a/whipper/image/cue.py b/whipper/image/cue.py index 0876006..f657c77 100644 --- a/whipper/image/cue.py +++ b/whipper/image/cue.py @@ -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 diff --git a/whipper/image/image.py b/whipper/image/image.py index 9554961..be71127 100644 --- a/whipper/image/image.py +++ b/whipper/image/image.py @@ -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') diff --git a/whipper/image/table.py b/whipper/image/table.py index dbc1856..c6938fd 100644 --- a/whipper/image/table.py +++ b/whipper/image/table.py @@ -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 diff --git a/whipper/image/toc.py b/whipper/image/toc.py index ee80bd6..f327b5c 100644 --- a/whipper/image/toc.py +++ b/whipper/image/toc.py @@ -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 diff --git a/whipper/program/cdparanoia.py b/whipper/program/cdparanoia.py index e32706d..3163dc7 100644 --- a/whipper/program/cdparanoia.py +++ b/whipper/program/cdparanoia.py @@ -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 diff --git a/whipper/program/soxi.py b/whipper/program/soxi.py index 567b266..72f0caa 100644 --- a/whipper/program/soxi.py +++ b/whipper/program/soxi.py @@ -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') diff --git a/whipper/test/common.py b/whipper/test/common.py index 4e9a43f..ad2c084 100644 --- a/whipper/test/common.py +++ b/whipper/test/common.py @@ -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):