scripts: Removed item/iter magic methods from fs object classes

So no more __getitem__, __contains__, or __iter__ for Rbyd, Btree, Mdir,
Mtree, Lfs.File, etc.

These were way too error-prone, especially when accidental unpacking
triggered unintended disk traversal and weird error states. We didn't
even use the implicit behavior because we preferred the full name for
heavy disk operations.

The motivation for this was Python not catching this bug, which is a bit
silly:

  rid, rattr, *path_ = rbyd
This commit is contained in:
Christopher Haster
2025-04-07 02:46:54 -05:00
parent 81b1a3cb71
commit b2911fbbe7
6 changed files with 1 additions and 304 deletions
+1 -16
View File
@@ -791,18 +791,6 @@ class Rbyd:
else:
return rattr_
def __getitem__(self, key):
if not isinstance(key, tuple):
key = (key,)
return self.lookup(*key)
def __contains__(self, key):
if not isinstance(key, tuple):
key = (key,)
return self.lookup(*key) is not None
def rids(self, *,
path=False):
rid = -1
@@ -869,9 +857,6 @@ class Rbyd:
yield rattr_
tag_ = rattr_.tag
def __iter__(self):
return self.rattrs()
# lookup by name
def namelookup(self, did, name):
# binary search
@@ -1647,7 +1632,7 @@ def dbg_tree(rbyd, *,
# dynamically size the id field
w_width = mt.ceil(mt.log10(max(1, rbyd.weight)+1))
for i, (rid, rattr) in enumerate(rbyd):
for i, (rid, rattr) in enumerate(rbyd.rattrs()):
# show human-readable tag representation
print('%08x: %s%*s %-*s %s' % (
rattr.toff,