Author levkivskyi
Recipients gvanrossum, levkivskyi, serhiy.storchaka
Date 2018-02-19.16:43:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1519058617.01.0.467229070634.issue32873@psf.upfronthosting.co.za>
In-reply-to
Content
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 https://github.com/python/typing/issues/511 (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 https://github.com/python/typing/issues/512

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=(<builtins.int>,), ...)

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__()
History
Date User Action Args
2018-02-19 16:43:37levkivskyisetrecipients: + levkivskyi, gvanrossum, serhiy.storchaka
2018-02-19 16:43:37levkivskyisetmessageid: <1519058617.01.0.467229070634.issue32873@psf.upfronthosting.co.za>
2018-02-19 16:43:36levkivskyilinkissue32873 messages
2018-02-19 16:43:36levkivskyicreate