Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-122311: Fix some error messages in pickle#122386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-122311: Fix some error messages in pickle
  • Loading branch information
@serhiy-storchaka
serhiy-storchaka committedJul 29, 2024
commitd7d8ba35ed344fe306d083a204c0ee0193bd0f4f
7 changes: 4 additions & 3 deletionsLib/pickle.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -314,16 +314,17 @@ def load_frame(self, frame_size):
# Tools used for pickling.

def _getattribute(obj, name):
top = obj
for subpath in name.split('.'):
if subpath == '<locals>':
raise AttributeError("Can't get local attribute {!r} on {!r}"
.format(name,obj))
.format(name,top))
try:
parent = obj
obj = getattr(obj, subpath)
except AttributeError:
raise AttributeError("Can't get attribute {!r} on {!r}"
.format(name,obj)) from None
.format(name,top)) from None
return obj, parent

def whichmodule(obj, name):
Expand DownExpand Up@@ -832,7 +833,7 @@ def save_bytearray(self, obj):
if _HAVE_PICKLE_BUFFER:
def save_picklebuffer(self, obj):
if self.proto < 5:
raise PicklingError("PickleBuffer can only pickled with "
raise PicklingError("PickleBuffer can onlybepickled with "
"protocol >= 5")
with obj.raw() as m:
if not m.contiguous:
Expand Down
4 changes: 3 additions & 1 deletionLib/test/pickletester.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1982,8 +1982,10 @@ def test_picklebuffer_error(self):
pb = pickle.PickleBuffer(b"foobar")
for proto in range(0, 5):
with self.subTest(proto=proto):
with self.assertRaises(pickle.PickleError):
with self.assertRaises(pickle.PickleError) as cm:
self.dumps(pb, proto)
self.assertEqual(str(cm.exception),
'PickleBuffer can only be pickled with protocol >= 5')

def test_non_continuous_buffer(self):
if self.pickler is pickle._Pickler:
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
Fix some error messages in :mod:`pickle`.
6 changes: 3 additions & 3 deletionsModules/_pickle.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1817,10 +1817,10 @@ get_dotted_path(PyObject *obj, PyObject *name)
if (_PyUnicode_EqualToASCIIString(subpath, "<locals>")) {
if (obj == NULL)
PyErr_Format(PyExc_AttributeError,
"Can'tpickle local object %R", name);
"Can'tget local object %R", name);
else
PyErr_Format(PyExc_AttributeError,
"Can'tpickle local attribute %R on %R", name, obj);
"Can'tget local attribute %R on %R", name, obj);
Py_DECREF(dotted_path);
return NULL;
}
Expand DownExpand Up@@ -2507,7 +2507,7 @@ save_picklebuffer(PickleState *st, PicklerObject *self, PyObject *obj)
{
if (self->proto < 5) {
PyErr_SetString(st->PicklingError,
"PickleBuffer can only pickled with protocol >= 5");
"PickleBuffer can onlybepickled with protocol >= 5");
return -1;
}
const Py_buffer* view = PyPickleBuffer_GetBuffer(obj);
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp