[issue32873] Pickling of typing types

Will T report at bugs.python.org
Wed Apr 4 17:47:35 EDT 2018


Will T <timwilloney at gmail.com> added the comment:

I believe I hit a bug with this fix (just pulled the code a few min ago):

    In [10]: pickle.loads(pickle.dumps(typing.List))
    Out[10]: typing.List

    In [11]: pickle.loads(pickle.dumps(typing.FrozenSet))
    ---------------------------------------------------------------------------
    PicklingError                             Traceback (most recent call last)
    <ipython-input-11-be060c6090e3> in <module>()
    ----> 1 pickle.loads(pickle.dumps(typing.FrozenSet))

    PicklingError: Can't pickle typing.Frozenset: attribute lookup Frozenset on typing failed

The cause is in _GenericAlias.__init__

            name = orig_name[0].title() + orig_name[1:]

Maybe just pass the name explicitly?

For context I originally hit this trying to explicitly getattr(typing, alias_name) not by pickling but I'm pleased to see that's at least apparently intended to be valid use (I need to get the underlying special's parameter variance which is lost when you give it args).

----------
nosy: +wrmsr

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32873>
_______________________________________


More information about the Python-bugs-list mailing list