Message312355
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__() |
|
Date |
User |
Action |
Args |
2018-02-19 16:43:37 | levkivskyi | set | recipients:
+ levkivskyi, gvanrossum, serhiy.storchaka |
2018-02-19 16:43:37 | levkivskyi | set | messageid: <1519058617.01.0.467229070634.issue32873@psf.upfronthosting.co.za> |
2018-02-19 16:43:36 | levkivskyi | link | issue32873 messages |
2018-02-19 16:43:36 | levkivskyi | create | |
|