Skip to content

[3.7] bpo-32873: Treat type variables and special typing forms as immutable by copy and pickle (GH-6216) - #6264

Merged
miss-islington merged 1 commit into
python:3.7from
miss-islington:backport-8349403-3.7
Mar 26, 2018
Merged

[3.7] bpo-32873: Treat type variables and special typing forms as immutable by copy and pickle (GH-6216)#6264
miss-islington merged 1 commit into
python:3.7from
miss-islington:backport-8349403-3.7

Conversation

@miss-islington

@miss-islingtonmiss-islington commented Mar 26, 2018

Copy link
Copy Markdown
Contributor

This also fixespython/typingGH-512
This also fixespython/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 levkivskyi@gmail.com

https://bugs.python.org/issue32873

… by copy and pickle (pythonGH-6216)
This also fixespython/typingGH-512
This also fixespython/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 <levkivskyi@gmail.com>

@gvanrossumgvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, backport to 3.7 is the intended target! (But no further.)

@miss-islington

Copy link
Copy Markdown
ContributorAuthor

@ilevkivskyi: Backport status check is done, and it's a success ✅ .

@miss-islington
miss-islington merged commit d0e04c8 into python:3.7Mar 26, 2018
@miss-islington

Copy link
Copy Markdown
ContributorAuthor

Thanks!

@miss-islington
miss-islington deleted the backport-8349403-3.7 branch March 26, 2018 22:29
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@miss-islington@gvanrossum@ilevkivskyi@the-knights-who-say-ni@bedevere-bot