[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] Standardize error message for non-pickleable types

On 2018-10-29 19:38, Serhiy Storchaka wrote:
> When you try to to pickle or copy a non-pickleable object, you will get
> an error. In most cases this will be a TypeError with one of few
> similar, but different variants:
>     "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)
>     "cannot serialize {} object" (proposed for SSLContext)
> Perhaps some of them where added without deep thinking and then were
> replicated in different places. I'm going to replace all of them with a
> standardized error message. But I'm unsure what variant is better.
> 1. "pickle" or "serialize"?
> 2. "can't", "Cannot", "can not" or "cannot"?
> 3. "object" or "objects"?
> 4. Use the "a" article or not?
> 5. Use quotes around type name or not?
> Please help me to choose the best variant.
1. If you're pickling, then saying "pickle" is more helpful.

2. In English the usual long form is "cannot". Error messages tend to 
avoid abbreviations, and also tend to have lowercase after the colon, e.g.:

     "ZeroDivisionError: division by zero"

     "ValueError: invalid literal for int() with base 10: 'foo'"

3. If it's failing on an object (singular), then it's clearer to say 

4. Articles tend to be omitted.

5. Error messages tend to have quotes around the type name.

Therefore, my preference is for:

     "cannot pickle 'XXX' object"