Skip to content

Commit 5a7ee64

Browse files
committed
construct/lib/container: Remove unneeded methods
`collections.abc.MutableMapping` already implements `keys()`, `update()`, `__eq__()`, `__ne__()` and `__contains__()` – most importantly correctly, e.g. `update()` has many variants which the current implementation does not handle. Signed-off-by: Philipp Hahn <[email protected]>
1 parent 46fcbbc commit 5a7ee64

File tree

3 files changed

+5
-31
lines changed

3 files changed

+5
-31
lines changed

elftools/construct/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ def _parse(self, stream, context):
881881
except ConstructError:
882882
stream.seek(pos)
883883
else:
884-
context.__update__(context2)
884+
context.update(context2)
885885
if self.include_name:
886886
return sc.name, obj
887887
else:
@@ -903,7 +903,7 @@ def _build(self, obj, stream, context):
903903
except Exception:
904904
pass
905905
else:
906-
context.__update__(context2)
906+
context.update(context2)
907907
stream.write(stream2.getvalue())
908908
return
909909
raise SelectError("no subconstruct matched", obj)

elftools/construct/debug.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def printout(self, stream, context):
8181
frames.reverse()
8282
for f in frames:
8383
a = Container()
84-
a.__update__(f.f_locals)
84+
a.update(f.f_locals)
8585
obj.stack.append(a)
8686

8787
print("=" * 80)

elftools/construct/lib/container.py

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,45 +40,19 @@ def __delitem__(self, name):
4040
def __setitem__(self, name, value):
4141
self.__dict__[name] = value
4242

43-
def keys(self):
44-
return self.__dict__.keys()
43+
def __iter__(self):
44+
return iter(self.__dict__)
4545

4646
def __len__(self):
4747
return len(self.__dict__.keys())
4848

49-
# Extended dictionary interface.
50-
51-
def update(self, other):
52-
self.__dict__.update(other)
53-
54-
__update__ = update
55-
56-
def __contains__(self, value):
57-
return value in self.__dict__
58-
59-
# Rich comparisons.
60-
61-
def __eq__(self, other):
62-
try:
63-
return self.__dict__ == other.__dict__
64-
except AttributeError:
65-
return False
66-
67-
def __ne__(self, other):
68-
return not self == other
69-
7049
# Copy interface.
7150

7251
def copy(self):
7352
return self.__class__(**self.__dict__)
7453

7554
__copy__ = copy
7655

77-
# Iterator interface.
78-
79-
def __iter__(self):
80-
return iter(self.__dict__)
81-
8256
def __repr__(self):
8357
return "%s(%s)" % (self.__class__.__name__, repr(self.__dict__))
8458

0 commit comments

Comments
 (0)