]> granicus.if.org Git - python/commit
bpo-32873: Treat type variables and special typing forms as immutable by copy and...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 26 Mar 2018 22:29:06 +0000 (15:29 -0700)
committerGitHub <noreply@github.com>
Mon, 26 Mar 2018 22:29:06 +0000 (15:29 -0700)
commitd0e04c82448c750d4dc27f2bddeddea74bd353ff
treee73559afc231cef79bb0d32f43d94c0526523b38
parent05455637f3ba9bacd459700f4feab783e5967d69
bpo-32873: Treat type variables and special typing forms as immutable 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 834940375ae88bc95794226dd8eff1f25fba1cf9)

Co-authored-by: Ivan Levkivskyi <levkivskyi@gmail.com>
Lib/test/test_typing.py
Lib/typing.py
Misc/NEWS.d/next/Library/2018-03-24-19-54-48.bpo-32873.cHyoAm.rst [new file with mode: 0644]