diff options
author | Lars Wirzenius <liw@liw.fi> | 2015-09-28 18:43:42 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2015-09-28 21:59:11 +0300 |
commit | 772582a65463bfc5d54802087066ed72714f3f4c (patch) | |
tree | e9a2d7b9c3a5f364fba161ffb237c450919b61e1 | |
parent | cbf67a6cc375a268acc68f3688f98da7982acb72 (diff) | |
download | obnam-772582a65463bfc5d54802087066ed72714f3f4c.tar.gz |
Fix un-idiomatic type checks (thanks, pylint)
-rw-r--r-- | obnamlib/fmt_6/clientlist_tests.py | 3 | ||||
-rw-r--r-- | obnamlib/fmt_6/clientmetadatatree.py | 4 | ||||
-rw-r--r-- | obnamlib/fmt_6/repo_fmt_6.py | 2 | ||||
-rw-r--r-- | obnamlib/plugins/backup_plugin.py | 2 | ||||
-rw-r--r-- | obnamlib/plugins/sftp_plugin.py | 2 | ||||
-rw-r--r-- | obnamlib/repo_interface.py | 4 | ||||
-rw-r--r-- | obnamlib/vfs_local.py | 4 |
7 files changed, 12 insertions, 9 deletions
diff --git a/obnamlib/fmt_6/clientlist_tests.py b/obnamlib/fmt_6/clientlist_tests.py index 523334b1..4a206a22 100644 --- a/obnamlib/fmt_6/clientlist_tests.py +++ b/obnamlib/fmt_6/clientlist_tests.py @@ -54,7 +54,8 @@ class ClientListTests(unittest.TestCase): def test_added_client_has_integer_id(self): self.list.add_client('foo') - self.assert_(type(self.list.get_client_id('foo')) in [int, long]) + value = self.list.get_client_id('foo') + self.assertTrue(isinstance(value, int) or isinstance(value, long)) def test_added_client_is_listed(self): self.list.add_client('foo') diff --git a/obnamlib/fmt_6/clientmetadatatree.py b/obnamlib/fmt_6/clientmetadatatree.py index 88a91843..4417d2d8 100644 --- a/obnamlib/fmt_6/clientmetadatatree.py +++ b/obnamlib/fmt_6/clientmetadatatree.py @@ -122,11 +122,11 @@ class ClientMetadataTree(obnamlib.RepositoryTree): ''' - if type(subkey) == str: + if isinstance(subkey, str): subkey = (subkey + '\0' * 8)[:8] fmt = '!B8sB8s' else: - assert type(subkey) in [int, long] + assert isinstance(subkey, int) or isinstance(subkey, long) fmt = '!B8sBQ' return struct.pack(fmt, prefix, mainhash, subtype, subkey) diff --git a/obnamlib/fmt_6/repo_fmt_6.py b/obnamlib/fmt_6/repo_fmt_6.py index b69389d8..800f8b7e 100644 --- a/obnamlib/fmt_6/repo_fmt_6.py +++ b/obnamlib/fmt_6/repo_fmt_6.py @@ -606,7 +606,7 @@ class RepositoryFormat6(obnamlib.RepositoryInterface): def _is_in_tree_chunk_id(self, chunk_id): # Is this a chunk id for in-tree data? - return type(chunk_id) == tuple + return isinstance(chunk_id, tuple) def _chunk_filename(self, chunk_id): return self._chunk_idpath.convert(chunk_id) diff --git a/obnamlib/plugins/backup_plugin.py b/obnamlib/plugins/backup_plugin.py index 3b4b2729..3da18cc2 100644 --- a/obnamlib/plugins/backup_plugin.py +++ b/obnamlib/plugins/backup_plugin.py @@ -417,7 +417,7 @@ class BackupPlugin(obnamlib.ObnamPlugin): self.backup_parents('.') def translate_enverror_to_obnamerror(self, pathname, exc): - if type(exc) is IOError: + if isinstance(exc, IOError): return obnamlib.ObnamIOError( errno=exc.errno, strerror=exc.strerror, diff --git a/obnamlib/plugins/sftp_plugin.py b/obnamlib/plugins/sftp_plugin.py index 458f8d60..c4d5c2f7 100644 --- a/obnamlib/plugins/sftp_plugin.py +++ b/obnamlib/plugins/sftp_plugin.py @@ -171,7 +171,7 @@ class SftpFS(obnamlib.VirtualFileSystem): 'VFS: baseurl=%s roundtrips=%s', self.baseurl, self._roundtrips) def _to_string(self, str_or_unicode): - if type(str_or_unicode) is unicode: + if isinstance(str_or_unicode, unicode): return str_or_unicode.encode('utf-8') else: return str_or_unicode diff --git a/obnamlib/repo_interface.py b/obnamlib/repo_interface.py index 0077b6df..906a31d1 100644 --- a/obnamlib/repo_interface.py +++ b/obnamlib/repo_interface.py @@ -1500,7 +1500,9 @@ class RepositoryInterfaceTests(unittest.TestCase): # pragma: no cover gen_id = self.create_generation() for key in self.repo.get_allowed_generation_keys(): value = self.repo.get_generation_key(gen_id, key) - self.assertTrue(type(value) in (str, int)) + self.assertTrue( + isinstance(value, str) or + isinstance(value, int)) def test_has_empty_string_for_generation_test_key(self): if self.generation_test_key_is_allowed(): diff --git a/obnamlib/vfs_local.py b/obnamlib/vfs_local.py index e645a344..e01617ee 100644 --- a/obnamlib/vfs_local.py +++ b/obnamlib/vfs_local.py @@ -264,7 +264,7 @@ class LocalFS(obnamlib.VirtualFileSystem): ret = obnamlib._obnam.llistxattr(self.join(filename)) if ret is None: raise MallocError(function='llistxattr') - if type(ret) is int: + if isinstance(ret, int): raise OSError(ret, os.strerror(ret), filename) return [s for s in ret.split('\0') if s] @@ -272,7 +272,7 @@ class LocalFS(obnamlib.VirtualFileSystem): ret = obnamlib._obnam.lgetxattr(self.join(filename), attrname) if ret is None: raise MallocError(function='llistxattr') - if type(ret) is int: + if isinstance(ret, int): raise OSError(ret, os.strerror(ret), filename) return ret |