[PATCH 3/7] Accommodate and enable pylint stop-iteration-return

0 views
Skip to first unread message

Rob Browning

unread,
Mar 14, 2026, 4:13:19 PM (10 days ago) Mar 14
to bup-...@googlegroups.com
We know the iterators in question won't throw StopIteration for
some/all of these cases (because, e.g. catpipe.get() always yields at
least the initial information), but just add a None next() default to
satisfy stop-iteration-return. We'll still crash on the failed
destructuring were a bug ever to produce None.

Signed-off-by: Rob Browning <r...@defaultvalue.org>
Tested-by: Rob Browning <r...@defaultvalue.org>
---
.pylintrc | 1 +
lib/bup/cmd/validate_object_links.py | 2 +-
lib/bup/git.py | 2 +-
lib/bup/repo/local.py | 2 +-
lib/bup/repo/remote.py | 2 +-
lib/bup/vfs.py | 2 +-
6 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/.pylintrc b/.pylintrc
index a5210325..8e533804 100644
--- a/.pylintrc
+++ b/.pylintrc
@@ -51,6 +51,7 @@ enable=
reimported,
return-in-init,
singleton-comparison,
+ stop-iteration-return,
subprocess-popen-preexec-fn,
super-init-not-called,
syntax-error,
diff --git a/lib/bup/cmd/validate_object_links.py b/lib/bup/cmd/validate_object_links.py
index 4f238176..75ad5213 100644
--- a/lib/bup/cmd/validate_object_links.py
+++ b/lib/bup/cmd/validate_object_links.py
@@ -64,7 +64,7 @@ class Pack:
yield oid, git._typermap[kind], data
elif kind in (5, 6, 7): # reserved obj_ofs_delta obj_ref_delta
it = self._cp.get(hexlify(oid))
- _, tp, _ = next(it)
+ _, tp, _ = next(it, None) # cannot return None
data = b''.join(it)
if tp == b'blob':
continue
diff --git a/lib/bup/git.py b/lib/bup/git.py
index a09eafe6..85c5d09f 100644
--- a/lib/bup/git.py
+++ b/lib/bup/git.py
@@ -1536,7 +1536,7 @@ def walk_object(get_ref, oidx, *, stop_at=None, include_data=None,
# must have data for commits, trees, or unknown
got_data = (exp_typ in (b'commit', b'tree', None)) or include_data
item_it = get_ref(oidx, include_data=got_data)
- get_oidx, typ, _ = next(item_it)
+ get_oidx, typ, _ = next(item_it, None) # cannot return None
if not get_oidx:
item = WalkItem(oid=unhexlify(oidx), type=exp_typ, name=name,
mode=mode, data=False)
diff --git a/lib/bup/repo/local.py b/lib/bup/repo/local.py
index b1be7d44..6fe2c2f5 100644
--- a/lib/bup/repo/local.py
+++ b/lib/bup/repo/local.py
@@ -111,7 +111,7 @@ class LocalRepo(RepoProtocol):

def cat(self, ref):
it = self._cp.get(ref)
- info = next(it)
+ info = next(it, None) # cannot return None
oidx = info[0]
yield info
if oidx: yield from it
diff --git a/lib/bup/repo/remote.py b/lib/bup/repo/remote.py
index 3649a5db..9f6e9de7 100644
--- a/lib/bup/repo/remote.py
+++ b/lib/bup/repo/remote.py
@@ -69,7 +69,7 @@ class RemoteRepo(RepoProtocol):
# oid, and verify that the data provided by the remote
# actually has that oid. If not, throw.
items = self.client.cat_batch((ref,))
- oidx, typ, size, it = info = next(items)
+ oidx, typ, size, it = info = next(items, None) # cannot return None
yield info[:-1]
if oidx:
if not _oidx_rx.fullmatch(ref):
diff --git a/lib/bup/vfs.py b/lib/bup/vfs.py
index c54a4137..97de7622 100644
--- a/lib/bup/vfs.py
+++ b/lib/bup/vfs.py
@@ -591,7 +591,7 @@ def root_items(repo, names=None, want_meta=True):
if ref in (b'.', b'.tag'):
continue
it = repo.cat(b'refs/heads/' + ref)
- oidx, typ, size_ = next(it)
+ oidx, typ, size_ = next(it, None) # cannot return None
if not oidx:
continue
assert typ == b'commit'
--
2.47.3

Reply all
Reply to author
Forward
0 new messages