@@ -96,6 +96,8 @@ class RawBspLump:
96
96
offset : int # position in file where lump begins
97
97
_changes : Dict [int , bytes ]
98
98
# ^ {index: new_byte}
99
+ # NOTE: bytes objects don't support item assignment
100
+ # -- but we want to allow light hex editting with slice overrides
99
101
_length : int # number of indexable entries
100
102
101
103
def __init__ (self , file : io .BufferedReader , lump_header : Any ):
@@ -130,17 +132,14 @@ def __iadd__(self, other_bytes: bytes):
130
132
self ._length += len (other_bytes )
131
133
self [start :] = other_bytes
132
134
133
- def __setitem__ (self , index : Union [int , slice ], value : Any ):
135
+ def __setitem__ (self , index : slice , value : Any ):
136
+ """remapping slices is allowed, but only slices"""
137
+ if not isinstance (index , slice ):
138
+ raise TypeError (f"list indices must be integers or slices, not { type (index )} " )
139
+ _slice = _remap_slice (index , self ._length )
134
140
# TODO: allow slice assignment to act like insert/extend
135
- if isinstance (index , int ):
136
- index = _remap_negative_index (index , self ._length )
141
+ for i , v in zip (range (_slice .start , _slice .stop , _slice .step ), value ):
137
142
self ._changes [index ] = value
138
- elif isinstance (index , slice ):
139
- _slice = _remap_slice (index , self ._length )
140
- for i , v in zip (range (_slice .start , _slice .stop , _slice .step ), value ):
141
- self [i ] = v
142
- else :
143
- raise TypeError (f"list indices must be integers or slices, not { type (index )} " )
144
143
145
144
def __iter__ (self ):
146
145
return iter ([self [i ] for i in range (self ._length )])
0 commit comments