This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author levkivskyi
Recipients gvanrossum, levkivskyi, serhiy.storchaka
Date 2018-02-19.16:43:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Here is the situation for 3.6 and before:

Generic classes are all actual class objects, so they are pickled as immutable. However this creates a problem, parameterized generics, such as `List[int]` _cannot_ be pickled in 3.6 and before, see (and this is something very hard to fix).

Here is the situation for 3.7:

Almost no generics are actual class objects, so they are pickled as usual. This also fixes the pickling problems in 3.6. However, there is one problematic thing, type variables, they should be pickled as immutable (i.e. by name reference), but I didn't have time to fix this, this is tracked in

What is interesting this issue adds here is an idea that we can treat special typing aliases that are conceptually "unique" also as immutable. For example, `typing.List` will be pickled as "typing.List", while `typing.List[int]` will be pickled as _GenericAlias(<builtins.list>, args=(<>,), ...)

Conveniently, all the special typing aliases are already marked with `_special=True`, so the potential solution would be like this:

class _GenericAlias:
    def __reduce__(self):
        if self._special:
            return 'typing.' + self._name
        return super().__reduce__()
Date User Action Args
2018-02-19 16:43:37levkivskyisetrecipients: + levkivskyi, gvanrossum, serhiy.storchaka
2018-02-19 16:43:37levkivskyisetmessageid: <>
2018-02-19 16:43:36levkivskyilinkissue32873 messages
2018-02-19 16:43:36levkivskyicreate