Add better type support when generating evolution hints.

Review Request #11120 — Created Aug. 4, 2020 and submitted

Information

Django Evolution
master

Reviewers

When generating hints for an evolution, we attempt to construct some
usable Python based on the values provided to the field. We've supported
some basic primitive types, as well as models, but with constraint
support we'll be needing more than that.

This change introduces enhanced type support in hints. It now checks if
it's working with an object containing a deconstruct method, which
Django uses for some types for exactly this purpose. Based on those
values, we can generate a string containing Python code for
re-constructing that object, recursively going into any arguments
passed to it and serializing/reconstructing those.

It also supports directly specifying a class as a parameter, and fixes a
bug with single-item tuples.

Unit tests pass.

Tested this with some upcoming unit tests that make use of these new
type capabilities.

Summary ID
Add better type support when generating evolution hints.
When generating hints for an evolution, we attempt to construct some usable Python based on the values provided to the field. We've supported some basic primitive types, as well as models, but with constraint support we'll be needing more than that. This change introduces enhanced type support in hints. It now checks if it's working with an object containing a `deconstruct` method, which Django uses for some types for exactly this purpose. Based on those values, we can generate a string containing Python code for re-constructing that object, recursively going into any arguments passed to it and serializing/reconstructing those. It also supports directly specifying a class as a parameter, and fixes a bug with single-item tuples.
2deef443cb0d242ec2820e54cd79d519d8704f43
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to master (7be54cc)