]> arthur.barton.de Git - bup.git/commitdiff
pylint: enable unidiomatic-typecheck
authorJohannes Berg <johannes@sipsolutions.net>
Fri, 27 Aug 2021 22:33:13 +0000 (00:33 +0200)
committerRob Browning <rlb@defaultvalue.org>
Fri, 17 Sep 2021 16:27:48 +0000 (11:27 -0500)
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
[rlb@defaultvalue.org: change isinstance str checks to compat.str_type]
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
.pylintrc
lib/bup/cmd/get.py
lib/bup/drecurse.py
lib/bup/index.py
lib/bup/main.py
lib/bup/vfs.py

index f7c5f604a2a2fb6104ed7a323b672d16b9223880..8a6e0fc35abfcdce84f3b051015c024993d640e3 100644 (file)
--- a/.pylintrc
+++ b/.pylintrc
@@ -6,6 +6,7 @@ enable=
   consider-using-in,
   return-in-init,
   trailing-whitespace,
+  unidiomatic-typecheck,
   unused-import,
   unused-wildcard-import,
   useless-return
index 6c9b8ed249d0f3f2e701d7f19233d312a3a9e91d..2b8ea1ac858908244dd909c16fc831cfe87170bf 100755 (executable)
@@ -229,7 +229,7 @@ def find_vfs_item(name, repo):
     elif kind == vfs.RevList:
         kind = 'branch'
     elif kind == vfs.Commit:
-        if len(res) > 1 and type(res[-2][1]) == vfs.RevList:
+        if len(res) > 1 and isinstance(res[-2][1], vfs.RevList):
             kind = 'save'
         else:
             kind = 'commit'
@@ -248,7 +248,7 @@ def find_vfs_item(name, repo):
                            follow=False, want_meta=False)
         leaf_name, leaf_item = res[-1]
         assert leaf_item
-        assert type(leaf_item) == vfs.Commit
+        assert isinstance(leaf_item, vfs.Commit)
         name = b'/'.join(x[0] for x in res)
         kind = 'save'
     else:
index b948b39e7e713fde5f244a6f17bfb66cf0443b8a..df41f6b6e0956ba4628af352bf3e0e50d1bb757d 100644 (file)
@@ -2,6 +2,7 @@
 from __future__ import absolute_import
 import stat, os
 
+from bup.compat import str_type
 from bup.helpers import add_error, should_rx_exclude_path, debug1, resolve_parent
 from bup.io import path_msg
 import bup.xstat as xstat
@@ -94,7 +95,7 @@ def recursive_dirlist(paths, xdev, bup_dir=None,
                       xdev_exceptions=frozenset()):
     startdir = OsFile(b'.')
     try:
-        assert(type(paths) != type(''))
+        assert not isinstance(paths, str_type)
         for path in paths:
             try:
                 pst = xstat.lstat(path)
index fde4a67d7f2ecba5710e53a4afce5e86d9387782..8eae53572f9c5c1429b15e34cab96203a9f977f3 100644 (file)
@@ -165,8 +165,8 @@ def _golevel(level, f, ename, newentry, metastore, tmax):
 
 class Entry:
     def __init__(self, basename, name, meta_ofs, tmax):
-        assert basename is None or type(basename) == bytes
-        assert name is None or type(name) == bytes
+        assert basename is None or isinstance(basename, bytes)
+        assert name is None or isinstance(name, bytes)
         self.basename = basename
         self.name = name
         self.meta_ofs = meta_ofs
index 5b6cad1f9b21fdf760df2d9ca68485f017c1ad90..0c21c88f57037d48fa1a35e7c25af723bbafe7c4 100755 (executable)
@@ -238,8 +238,7 @@ def filter_output(srcs, dests):
 
     """
     global sep_rx
-    assert all(type(x) in int_types for x in srcs)
-    assert all(type(x) in int_types for x in srcs)
+    assert all(isinstance(x, int_types) for x in srcs)
     assert len(srcs) == len(dests)
     srcs = tuple(srcs)
     dest_for = dict(zip(srcs, dests))
index fd016b27ed7ffae334caccb95ad976a226793da8..09bb1d37e33562bc9ff4cf1e8ed481a9edd9120f 100644 (file)
@@ -57,7 +57,7 @@ from time import localtime, strftime
 import re, sys
 
 from bup import git, vint
-from bup.compat import hexstr, range
+from bup.compat import hexstr, range, str_type
 from bup.git import BUP_CHUNKED, parse_commit, tree_decode
 from bup.helpers import debug2, last
 from bup.io import path_msg
@@ -274,8 +274,8 @@ Tags = namedtuple('Tags', ('meta'))
 RevList = namedtuple('RevList', ('meta', 'oid'))
 Commit = namedtuple('Commit', ('meta', 'oid', 'coid'))
 
-item_types = frozenset((Item, Chunky, Root, Tags, RevList, Commit))
-real_tree_types = frozenset((Item, Commit))
+item_types = (Item, Chunky, Root, Tags, RevList, Commit)
+real_tree_types = (Item, Commit)
 
 def write_item(port, item):
     kind = type(item)
@@ -392,8 +392,7 @@ def is_valid_cache_key(x):
       rvl:OID -> {'.', commit, '2012...', next_commit, ...}
     """
     # Suspect we may eventually add "(container_oid, name) -> ...", and others.
-    x_t = type(x)
-    if x_t is bytes:
+    if isinstance(x, bytes):
         tag = x[:4]
         if tag in (b'itm:', b'rvl:') and len(x) == 24:
             return True
@@ -672,7 +671,7 @@ def tree_items(oid, tree_data, names=frozenset(), bupm=None):
 
     # Assumes the tree is properly formed, i.e. there are no
     # duplicates, and entries will be in git tree order.
-    if type(names) not in (frozenset, set):
+    if isinstance(names, (frozenset, set)):
         names = frozenset(names)
     remaining = len(names)
 
@@ -847,7 +846,7 @@ def tags_items(repo, names):
         return
 
     # Assumes no duplicate refs
-    if type(names) not in (frozenset, set):
+    if isinstance(names, (frozenset, set)):
         names = frozenset(names)
     remaining = len(names)
     last_name = max(names)
@@ -894,8 +893,7 @@ def contents(repo, item, names=None, want_meta=True):
     global _root, _tags
     assert repo
     assert S_ISDIR(item_mode(item))
-    item_t = type(item)
-    if item_t in real_tree_types:
+    if isinstance(item, real_tree_types):
         it = repo.cat(hexlify(item.oid))
         _, obj_t, size = next(it)
         data = b''.join(it)
@@ -908,12 +906,12 @@ def contents(repo, item, names=None, want_meta=True):
             item_gen = tree_items_with_meta(repo, item.oid, data, names)
         else:
             item_gen = tree_items(item.oid, data, names)
-    elif item_t == RevList:
+    elif isinstance(item, RevList):
         item_gen = revlist_items(repo, item.oid, names,
                                  require_meta=want_meta)
-    elif item_t == Root:
+    elif isinstance(item, Root):
         item_gen = root_items(repo, names, want_meta)
-    elif item_t == Tags:
+    elif isinstance(item, Tags):
         item_gen = tags_items(repo, names)
     else:
         raise Exception('unexpected VFS item ' + str(item))
@@ -946,8 +944,8 @@ def _resolve_path(repo, path, parent=None, want_meta=True, follow=True):
     if parent:
         for x in parent:
             assert len(x) == 2
-            assert type(x[0]) in (bytes, str)
-            assert type(x[1]) in item_types
+            assert isinstance(x[0], (bytes, str_type))
+            assert isinstance(x[1], item_types)
         assert parent[0][1] == _root
         if not S_ISDIR(item_mode(parent[-1][1])):
             raise IOError(ENOTDIR,
@@ -1008,7 +1006,7 @@ def _resolve_path(repo, path, parent=None, want_meta=True, follow=True):
                         raise_dir_required_but_not_dir(path, parent, past)
                     return notice_resolution(tuple(past))
                 # It's treeish
-                if want_meta and type(item) in real_tree_types:
+                if want_meta and isinstance(item, real_tree_types):
                     dir_meta = _find_treeish_oid_metadata(repo, item.oid)
                     if dir_meta:
                         item = item._replace(meta=dir_meta)