-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't pickle generic types #511
Comments
This is a known issue, unfortunately it is not easy to fix, see discussion in #306. In short, |
Stupid question, but why isn't |
Currently, |
I guess my question was: why the whole design of having types be classes rather than instances? :-) |
This is a very old (relative to me) decision, I don't know for sure, but I think one of the main motivation was that things like this should work: class C(List[int], Generic[T]):
... |
Regardless of the class issue, it seems it's difficult to find a reliable way to rebuild a generic type from its attributes. The problem is, both |
This is the Unfortunately, for some reason it succeeds on |
Just a note that with PEP 560 in place the problems boils down to |
… by copy and pickle (pythonGH-6216) This also fixes python/typingGH-512 This also fixes python/typingGH-511 As was discussed in both issues, some typing forms deserve to be treated as immutable by copy and pickle modules, so that: * copy(X) is X * deepcopy(X) is X * loads(dumps(X)) is X GH- pickled by reference This PR adds such behaviour to: * Type variables * Special forms like Union, Any, ClassVar * Unsubscripted generic aliases to containers like List, Mapping, Iterable This not only resolves inconsistencies mentioned in the issues, but also improves backwards compatibility with previous versions of Python (including 3.6). Note that this requires some dances with __module__ for type variables (similar to NamedTuple) because the class TypeVar itself is define in typing, while type variables should get module where they were defined. https://bugs.python.org/issue32873 (cherry picked from commit 8349403) Co-authored-by: Ivan Levkivskyi <[email protected]>
… by copy and pickle (GH-6216) This also fixes python/typing#512 This also fixes python/typing#511 As was discussed in both issues, some typing forms deserve to be treated as immutable by copy and pickle modules, so that: * copy(X) is X * deepcopy(X) is X * loads(dumps(X)) is X # pickled by reference This PR adds such behaviour to: * Type variables * Special forms like Union, Any, ClassVar * Unsubscripted generic aliases to containers like List, Mapping, Iterable This not only resolves inconsistencies mentioned in the issues, but also improves backwards compatibility with previous versions of Python (including 3.6). Note that this requires some dances with __module__ for type variables (similar to NamedTuple) because the class TypeVar itself is define in typing, while type variables should get module where they were defined. https://bugs.python.org/issue32873
… by copy and pickle (GH-6216) This also fixes python/typingGH-512 This also fixes python/typingGH-511 As was discussed in both issues, some typing forms deserve to be treated as immutable by copy and pickle modules, so that: * copy(X) is X * deepcopy(X) is X * loads(dumps(X)) is X GH- pickled by reference This PR adds such behaviour to: * Type variables * Special forms like Union, Any, ClassVar * Unsubscripted generic aliases to containers like List, Mapping, Iterable This not only resolves inconsistencies mentioned in the issues, but also improves backwards compatibility with previous versions of Python (including 3.6). Note that this requires some dances with __module__ for type variables (similar to NamedTuple) because the class TypeVar itself is define in typing, while type variables should get module where they were defined. https://bugs.python.org/issue32873 (cherry picked from commit 8349403) Co-authored-by: Ivan Levkivskyi <[email protected]>
…zed form with cloudpickle. In Python 3.6, typing.List[str] cannot be pickled, therefore hydra configuration cannot be passed with pickle. PEP 560 fixes the issue in Python 3.7. As a workaround, we use more advanced serializtin library cloudpickle. See also: python/typing#511
Briefly:
This can be an issue with certain advanced serialization libraries such as dill or cloudpickle, which are often used by distributed computing frameworks.
The text was updated successfully, but these errors were encountered: