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

pickle documentation says that unpickling may not call __new__ #71822

Closed
tifv mannequin opened this issue Jul 27, 2016 · 7 comments
Closed

pickle documentation says that unpickling may not call __new__ #71822

tifv mannequin opened this issue Jul 27, 2016 · 7 comments
Labels
3.7 (EOL) end of life docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error

Comments

@tifv
Copy link
Mannequin

tifv mannequin commented Jul 27, 2016

BPO 27635
Nosy @avassalotti, @tifv, @serhiy-storchaka, @miss-islington, @furkanonder, @iritkatriel
PRs
  • bpo-27635: Fix pickle documentation about __new__ not being called. #19269
  • [3.8] bpo-27635: Fix pickle documentation about __new__ not being called. (GH-19269) #19585
  • [3.7] bpo-27635: Fix pickle documentation about __new__ not being called. (GH-19269) #19586
  • 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 = None
    closed_at = <Date 2020-10-11.20:22:32.477>
    created_at = <Date 2016-07-27.17:07:25.666>
    labels = ['type-bug', '3.7', 'docs']
    title = 'pickle documentation says that unpickling may not call __new__'
    updated_at = <Date 2020-10-11.20:22:32.477>
    user = 'https://github.com/tifv'

    bugs.python.org fields:

    activity = <Date 2020-10-11.20:22:32.477>
    actor = 'alexandre.vassalotti'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2020-10-11.20:22:32.477>
    closer = 'alexandre.vassalotti'
    components = ['Documentation']
    creation = <Date 2016-07-27.17:07:25.666>
    creator = 'july'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 27635
    keywords = ['patch']
    message_count = 7.0
    messages = ['271465', '365442', '366730', '366731', '366732', '366950', '378451']
    nosy_count = 7.0
    nosy_names = ['alexandre.vassalotti', 'july', 'docs@python', 'serhiy.storchaka', 'miss-islington', 'furkanonder', 'iritkatriel']
    pr_nums = ['19269', '19585', '19586']
    priority = 'normal'
    resolution = None
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue27635'
    versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']

    @tifv
    Copy link
    Mannequin Author

    tifv mannequin commented Jul 27, 2016

    A note just below object.__setstate__() documentation
    https://docs.python.org/3.6/library/pickle.html#object.\_\_setstate__
    says that
    """
    … the type should implement __getnewargs__() or __getnewargs_ex__() to establish such an invariant; otherwise, neither __new__() nor __init__() will be called.
    """

    I believe that note about not calling __new__() was relevant in python2. I could not find case in python3 in which __new__() would not be called. And __init__() is not called anyway, as far as I understand (unless explicitly by __setstate__() or something).

    Python 3.6.0a3+ (default:da9898e7e90d, Jul 27 2016, 19:51:12) 
    [GCC 4.9.3] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> class C:
    ...   def __getstate__(self): return {'foo' : self.foo}
    ...   def __setstate__(self, state): self.foo = state['foo']
    ...   def __new__(cls):
    ...     print('__new__ is called'); return super().__new__(cls)
    ...   def __init__(self):
    ...     print('__init__ is called'); self.foo = None; super().__init__()
    ... 
    >>> c = C(); c.foo = 'bar'
    __new__ is called
    __init__ is called
    >>> import pickle
    >>> c2 = pickle.loads(pickle.dumps(c))
    __new__ is called
    >>> c2.foo
    'bar'

    @tifv tifv mannequin assigned docspython Jul 27, 2016
    @tifv tifv mannequin added the docs Documentation in the Doc dir label Jul 27, 2016
    @serhiy-storchaka serhiy-storchaka added 3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error labels Feb 18, 2017
    @furkanonder
    Copy link
    Mannequin

    furkanonder mannequin commented Apr 1, 2020

    There is still an mistake in the document. I sent a pr to fix it.

    @miss-islington
    Copy link
    Contributor

    New changeset 482259d by Furkan Önder in branch 'master':
    bpo-27635: Fix pickle documentation about __new__ not being called. (GH-19269)
    482259d

    @miss-islington
    Copy link
    Contributor

    New changeset 0abb548 by Miss Islington (bot) in branch '3.7':
    bpo-27635: Fix pickle documentation about __new__ not being called. (GH-19269)
    0abb548

    @miss-islington
    Copy link
    Contributor

    New changeset 020f2aa by Miss Islington (bot) in branch '3.8':
    bpo-27635: Fix pickle documentation about __new__ not being called. (GH-19269)
    020f2aa

    @furkanonder
    Copy link
    Mannequin

    furkanonder mannequin commented Apr 21, 2020

    The problem is fixed, issue can be closed.

    @iritkatriel
    Copy link
    Member

    Ping (to close the issue).

    @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.7 (EOL) end of life docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants