Steps to reproduce:
import pickle
invalid_data = b"this is not valid pickle data"
try:
pickle.loads(invalid_data)
assert False, "Expected UnpicklingError to be raised"
except pickle.UnpicklingError:
assert True
except IndexError:
print("IndexError raised instead of UnpicklingError")
from unittest.mock import patch, mock_open
with patch("builtins.open", mock_open(read_data=invalid_data)):
with open("dummy_file", "rb") as f:
try:
pickle.load(f)
assert False, "Expected UnpicklingError to be raised"
except pickle.UnpicklingError:
assert True
except IndexError:
print("IndexError raised instead of UnpicklingError")
Expected (CPython behaviour): no output
Actual:
IndexError raised instead of UnpicklingError
IndexError raised instead of UnpicklingError
Note this is actually a bug in CPython's standard library: python/cpython#141749
Steps to reproduce:
Expected (CPython behaviour): no output
Actual:
Note this is actually a bug in CPython's standard library: python/cpython#141749