Skip to content

loading fails for typing.Tuple[()] #517

@ryanthompson591

Description

@ryanthompson591

How to reproduce:

Run this code with 0.3.4 you will see it pass.
Run in 0.3.5.1 and you will see it fail.

import dill

from typing import Union, Tuple

FeatureValueType = Union[str, int, float]  # pylint: disable=invalid-name
SingletonSliceKeyType = Tuple[str, FeatureValueType]  # pylint: disable=invalid-name
A_TYPE = Union[Tuple[()], Tuple[SingletonSliceKeyType, ...]]

def a_function() -> A_TYPE:
  return ('string', 'feature_value_type')

serialized = dill.dumps(a_function)
loaded = dill.loads(serialized)

print(loaded())

I get the following error in 0.3.5.1

Traceback (most recent call last):
  File "/Users/ryanthompson/PycharmProjects/learningProjects/dill_regression/regression_test.py", line 13, 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 ().

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions