Skip to content

Commit 00bfb01

Browse files
committed
Simplify conditional branches in serializer and deserializer functions
1 parent 2dcda2a commit 00bfb01

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

Lib/test/test_shelve.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,24 +174,19 @@ def serializer(obj, protocol):
174174
if isinstance(obj, (bytes, bytearray, str)):
175175
if protocol == 5:
176176
return obj
177-
else:
178-
return type(obj).__name__
177+
return type(obj).__name__
179178
elif isinstance(obj, array.array):
180179
return obj.tobytes()
181-
else:
182-
raise TypeError(
183-
f"Unsupported type for serialization: {type(obj)}"
184-
)
180+
raise TypeError(f"Unsupported type for serialization: {type(obj)}")
185181

186182
def deserializer(data):
187183
if isinstance(data, (bytes, bytearray, str)):
188184
return data.decode("utf-8")
189185
elif isinstance(data, array.array):
190186
return array.array("b", data)
191-
else:
192-
raise TypeError(
193-
f"Unsupported type for deserialization: {type(data)}"
194-
)
187+
raise TypeError(
188+
f"Unsupported type for deserialization: {type(data)}"
189+
)
195190

196191
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
197192
with self.subTest(proto=proto), shelve.open(

0 commit comments

Comments
 (0)