GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — pickling fails for typing.Tuple[()] · Issue #94245 · python/cpython

pickling fails for typing.Tuple[()] #94245

New issue
Copy link
New issue
Copy link
Closed
Closed
pickling fails for typing.Tuple[()]#94245
Copy link
Labels
3.10 (EOL)end of lifeend of lifetopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@ryanthompson591
ryanthompson591
opened on Jun 24, 2022
Issue body actions

Bug report

A clear and concise description of what the bug is.
Include a minimal, reproducible example (https://stackoverflow.com/help/minimal-reproducible-example), if possible.

import pickle
from typing import Tuple

j = Tuple[()]
serialized = pickle.dumps(j)
loaded = pickle.loads(serialized)

Error message:

Traceback (most recent call last):
  File "/Users/ryanthompson/PycharmProjects/learningProjects/dill_regression/regression_test.py", line 6, in <module>
    loaded = dill.loads(serialized)
  File "/Users/ryanthompson/.pyenv/versions/3.8.11/lib/python3.8/site-packages/dill/_dill.py", line 387, in loads
    return load(file, ignore, **kwds)
  File "/Users/ryanthompson/.pyenv/versions/3.8.11/lib/python3.8/site-packages/dill/_dill.py", line 373, in load
    return Unpickler(file, ignore=ignore, **kwds).load()
  File "/Users/ryanthompson/.pyenv/versions/3.8.11/lib/python3.8/site-packages/dill/_dill.py", line 646, in load
    obj = StockUnpickler.load(self)
  File "/Users/ryanthompson/.pyenv/versions/3.8.11/lib/python3.8/typing.py", line 804, in __getitem__
    return self.__getitem_inner__(params)
  File "/Users/ryanthompson/.pyenv/versions/3.8.11/lib/python3.8/typing.py", line 261, in inner
    return func(*args, **kwds)
  File "/Users/ryanthompson/.pyenv/versions/3.8.11/lib/python3.8/typing.py", line 830, in __getitem_inner__
    params = tuple(_type_check(p, msg) for p in params)
  File "/Users/ryanthompson/.pyenv/versions/3.8.11/lib/python3.8/typing.py", line 830, in <genexpr>
    params = tuple(_type_check(p, msg) for p in params)
  File "/Users/ryanthompson/.pyenv/versions/3.8.11/lib/python3.8/typing.py", line 149, in _type_check
    raise TypeError(f"{msg} Got {arg!r:.100}.")
TypeError: Tuple[t0, t1, ...]: each t must be a type. Got ().


Your environment
python 3.8

  • CPython versions tested on:
    3.6 & 3.8
  • Operating system and architecture:
    Mac OS
Reacted by Chang Liu

Activity

  1. ryanthompson591
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Jun 24, 2022
  2. JelleZijlstra
    added
    topic-typing
    3.10 (EOL)end of lifeend of life
    on Jun 24, 2022
  3. JelleZijlstra commented on Jun 24, 2022

    @JelleZijlstra
    JelleZijlstra
    on Jun 24, 2022
    Member
    More actions

    Thanks for the report. I can reproduce on 3.9 and 3.10, but not a recent build of 3.11. I assume @serhiy-storchaka's changes to the representation of empty tuples fixed this issue.

    We're not going to fix this for 3.9 and lower because those branches are in security fix-only mode, but we can still fix it on 3.10.

  4. mmckerns commented on Jun 24, 2022

    @mmckerns
    mmckerns
    on Jun 24, 2022
    More actions

    Just for completeness... here's a little more information on the bug (from the OP issue at dill):

    >>> import pickle
    >>> import typing
    >>> t = typing.Tuple[()]
    >>> t
    typing.Tuple[()]
    >>> t = t.copy_with(())
    >>> t
    typing.Tuple[]
    >>> s = pickle.dumps(t)
    >>> pickle.loads(s)
    typing.Tuple[()]
    >>> typing.Tuple[]
      File "<stdin>", line 1
        typing.Tuple[]
                     ^
    SyntaxError: invalid syntax
    
  5. serhiy-storchaka
    added this to Pickle and copy issues 🥒on Jun 25, 2022
  6. serhiy-storchaka
    added 2 commits that reference this issue on Jun 25, 2022

    pythongh-94245: Test pickling and copying of typing.Tuple[()]

    72880a3

    pythongh-94245: Fix pickling and copying of typing.Tuple[()]

    8d1afcf
  7. serhiy-storchaka commented on Jun 25, 2022

    @serhiy-storchaka
    serhiy-storchaka
    on Jun 25, 2022
    Member
    More actions

    Backporting #31836 can fix this issue. #94260 is an alternate fix. #94259 contains tests, they should be added in all versions.

  8. serhiy-storchaka
    added 2 commits that reference this issue on Jun 25, 2022

    [3.10] gh-94245: Fix pickling and copying of typing.Tuple[()] (GH-94260)

    75dda3b

    gh-94245: Test pickling and copying of typing.Tuple[()] (GH-94259)

    75cb3ab
  9. miss-islington
    added 3 commits that reference this issue on Jun 25, 2022

    pythongh-94245: Test pickling and copying of typing.Tuple[()] (python…

    264d9a1

    pythongh-94245: Test pickling and copying of typing.Tuple[()] (python…

    74056fc

    gh-94245: Test pickling and copying of typing.Tuple[()] (GH-94259)

    1251467
  10. serhiy-storchaka
    added a commit that references this issue on Jun 26, 2022

    gh-94245: Test pickling and copying of typing.Tuple[()] (GH-94259) (G…

    1901d2a
  11. serhiy-storchaka
    closed this as completedon Jun 26, 2022
  12. serhiy-storchaka
    moved this to Done in Pickle and copy issues 🥒on Jun 26, 2022
  13. serhiy-storchaka
    added a commit that references this issue on Jun 26, 2022

    Revert 30935 defer bpo45162 to 312 (#94285)

    1ffde3e
  14. tvalentyn
    added a commit that references this issue on Jul 25, 2022

    fix: #517 special handling of typing module

    0ca195f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.10 (EOL)end of lifeend of lifetopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    • Pickle and copy issues 🥒
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.