This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Improve standard error for uncopyable types
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: alexandre.vassalotti, christian.heimes, pitrou, serhiy.storchaka, xtreak
Priority: normal Keywords: patch

Created on 2018-03-25 16:21 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 6239 merged serhiy.storchaka, 2018-03-25 20:55
Messages (5)
msg314418 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-03-25 16:21
Currently most extension types are not pickleable and copyable. The default error messages is "can't pickle XXX objects". This is confusing in case of copying because not all know that copying falls back to the pickle protocol (see for example issue33023). The proposed PR changes the default error messages to more neutral "cannot serialize 'XXX' object". This or similar error messages are already used in some classes (files, sockets, compressors/decompressors).

It also removes __getstate__ methods raising an error from non-pickleable extension types. They where added when extension types were pickleable by default (fixed in issue22995). Now they are not needed.
msg318902 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-06-07 07:04
Current error messages for different classes:

   "can't pickle XXX objects" (default)
   "Cannot serialize XXX object" (socket, BZ2Compressor, BZ2Decompressor)
   "can not serialize a 'XXX' object" (buffered files in _pyio)
   "cannot serialize 'XXX' object" (FileIO, TextWrapperIO, WinConsoleIO, buffered files in _io, LZMACompressor, LZMADecompressor)

Yest one error message is proposed by PR 6099 in issue33023 for SSLContext:

   "cannot serialize {} object"

PR 6239 replaces them with unified

   "cannot serialize 'XXX' object"

which already is used in some extension classes. This is the most popular error message except the default error message. I'm not sure this is the best error message. "can't"/"Cannot"/"cannot"/"can not", using an article and quotes -- what is better?
msg325621 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-09-18 07:06
Does anybody have opinion about this issue? Is this option the best of possible? I'm going to merge the PR soon.
msg328962 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-31 00:28
New changeset 0353b4eaaf451ad463ce7eb3074f6b62d332f401 by Serhiy Storchaka in branch 'master':
bpo-33138: Change standard error message for non-pickleable and non-copyable types. (GH-6239)
https://github.com/python/cpython/commit/0353b4eaaf451ad463ce7eb3074f6b62d332f401
msg328979 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-31 09:18
Changed to "cannot pickle 'XXX' object" after discussing on Python-Dev:

https://mail.python.org/pipermail/python-dev/2018-October/155599.html
History
Date User Action Args
2022-04-11 14:58:59adminsetgithub: 77319
2018-10-31 09:18:54serhiy.storchakasetmessages: + msg328979
2018-10-31 00:28:36serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-10-31 00:28:10serhiy.storchakasetmessages: + msg328962
2018-09-18 09:29:08xtreaksetnosy: + xtreak
2018-09-18 07:06:28serhiy.storchakasetassignee: serhiy.storchaka
messages: + msg325621
2018-06-07 07:04:46serhiy.storchakasetmessages: + msg318902
2018-03-25 20:55:11serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request5978
2018-03-25 16:21:38serhiy.storchakacreate