Skip to content

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

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

Merged
merged 1 commit into from
Mar 26, 2018

Conversation

miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Mar 26, 2018

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]

https://bugs.python.org/issue32873

… 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]>
Copy link
Member

@gvanrossum gvanrossum left a comment

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
Contributor Author

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

@miss-islington miss-islington merged commit d0e04c8 into python:3.7 Mar 26, 2018
@miss-islington
Copy link
Contributor Author

Thanks!

@miss-islington miss-islington deleted the backport-8349403-3.7 branch March 26, 2018 22:29
Sign up for free to 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