mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
bpo-32873: Treat type variables and special typing forms as immutable 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
This commit is contained in:
parent
0e7144b064
commit
834940375a
3 changed files with 58 additions and 11 deletions
|
@ -0,0 +1,3 @@
|
|||
Treat type variables and special typing forms as immutable by copy and
|
||||
pickle. This fixes several minor issues and inconsistencies, and improves
|
||||
backwards compatibility with Python 3.6.
|
Loading…
Add table
Add a link
Reference in a new issue