Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve standard error for uncopyable types #77319

Closed
serhiy-storchaka opened this issue Mar 25, 2018 · 5 comments
Closed

Improve standard error for uncopyable types #77319

serhiy-storchaka opened this issue Mar 25, 2018 · 5 comments
Assignees
Labels
3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@serhiy-storchaka
Copy link
Member

BPO 33138
Nosy @pitrou, @tiran, @avassalotti, @serhiy-storchaka, @tirkarthi
PRs
  • bpo-33138: Change standard error message for non-pickleable and non-copyable types. #6239
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2018-10-31.00:28:36.664>
    created_at = <Date 2018-03-25.16:21:38.638>
    labels = ['interpreter-core', 'type-feature', '3.8']
    title = 'Improve standard error for uncopyable types'
    updated_at = <Date 2018-10-31.09:18:54.810>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2018-10-31.09:18:54.810>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2018-10-31.00:28:36.664>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2018-03-25.16:21:38.638>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 33138
    keywords = ['patch']
    message_count = 5.0
    messages = ['314418', '318902', '325621', '328962', '328979']
    nosy_count = 5.0
    nosy_names = ['pitrou', 'christian.heimes', 'alexandre.vassalotti', 'serhiy.storchaka', 'xtreak']
    pr_nums = ['6239']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue33138'
    versions = ['Python 3.8']

    @serhiy-storchaka
    Copy link
    Member Author

    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 bpo-33023). 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 bpo-22995). Now they are not needed.

    @serhiy-storchaka serhiy-storchaka added 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Mar 25, 2018
    @serhiy-storchaka
    Copy link
    Member Author

    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 bpo-33023 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?

    @serhiy-storchaka
    Copy link
    Member Author

    Does anybody have opinion about this issue? Is this option the best of possible? I'm going to merge the PR soon.

    @serhiy-storchaka serhiy-storchaka self-assigned this Sep 18, 2018
    @serhiy-storchaka
    Copy link
    Member Author

    New changeset 0353b4e by Serhiy Storchaka in branch 'master':
    bpo-33138: Change standard error message for non-pickleable and non-copyable types. (GH-6239)
    0353b4e

    @serhiy-storchaka
    Copy link
    Member Author

    Changed to "cannot pickle 'XXX' object" after discussing on Python-Dev:

    https://mail.python.org/pipermail/python-dev/2018-October/155599.html

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant