Ivan Levkivskyi <levkivs...@gmail.com> added the comment:

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__()

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32873>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to