From 5921b73e388c33b05bc8a5bd18a5854ae605067d Mon Sep 17 00:00:00 2001 From: Orion Martin <40585662+95-martin-orion@users.noreply.github.com> Date: Mon, 9 May 2022 11:06:40 -0700 Subject: [PATCH 1/4] verbosify cirq_type deprecation --- cirq-core/cirq/protocols/json_serialization.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cirq-core/cirq/protocols/json_serialization.py b/cirq-core/cirq/protocols/json_serialization.py index ce514e4a956..439220a14ae 100644 --- a/cirq-core/cirq/protocols/json_serialization.py +++ b/cirq-core/cirq/protocols/json_serialization.py @@ -283,9 +283,14 @@ def _json_dict_with_cirq_type(obj: Any): if 'cirq_type' in base_dict: # TODO: upgrade to ValueError in v0.15 warnings.warn( - f"Found 'cirq_type': '{base_dict['cirq_type']}' in _json_dict_. " - f"Custom values of this field are not permitted, and will produce " - "an error starting in Cirq v0.15.", + f"Found 'cirq_type': '{base_dict['cirq_type']}' in user-specified _json_dict_. " + "This field is now automatically generated from the class name and (if present) " + "its _json_namespace_ method. Starting in v0.15, custom 'cirq_type' values " + "will trigger an error." + "\n\n" + "To fix this, remove 'cirq_type' from the class _json_dict_ method. Classes " + "outside of cirq should also define a non-empty _json_namespace_ to avoid " + "collision with Cirq classes.", DeprecationWarning, ) return base_dict From 1034ac9318410576a5a26a71627678d01f3b06ae Mon Sep 17 00:00:00 2001 From: Orion Martin <40585662+95-martin-orion@users.noreply.github.com> Date: Mon, 9 May 2022 11:50:04 -0700 Subject: [PATCH 2/4] -vv --- cirq-core/cirq/protocols/json_serialization.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cirq-core/cirq/protocols/json_serialization.py b/cirq-core/cirq/protocols/json_serialization.py index 439220a14ae..b03bfe1035d 100644 --- a/cirq-core/cirq/protocols/json_serialization.py +++ b/cirq-core/cirq/protocols/json_serialization.py @@ -285,9 +285,10 @@ def _json_dict_with_cirq_type(obj: Any): warnings.warn( f"Found 'cirq_type': '{base_dict['cirq_type']}' in user-specified _json_dict_. " "This field is now automatically generated from the class name and (if present) " - "its _json_namespace_ method. Starting in v0.15, custom 'cirq_type' values " - "will trigger an error." + "its _json_namespace_ method; this produces the same serialization format as " + "the existing convention of `[namespace.]class_name`." "\n\n" + "Starting in v0.15, custom 'cirq_type' values will trigger an error. " "To fix this, remove 'cirq_type' from the class _json_dict_ method. Classes " "outside of cirq should also define a non-empty _json_namespace_ to avoid " "collision with Cirq classes.", From d10e892422e0992a077deac6acc39fdb555b4d90 Mon Sep 17 00:00:00 2001 From: Orion Martin <40585662+95-martin-orion@users.noreply.github.com> Date: Tue, 10 May 2022 13:52:24 -0700 Subject: [PATCH 3/4] -vvv --- cirq-core/cirq/protocols/json_serialization.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cirq-core/cirq/protocols/json_serialization.py b/cirq-core/cirq/protocols/json_serialization.py index b03bfe1035d..dbe83d6d521 100644 --- a/cirq-core/cirq/protocols/json_serialization.py +++ b/cirq-core/cirq/protocols/json_serialization.py @@ -284,14 +284,16 @@ def _json_dict_with_cirq_type(obj: Any): # TODO: upgrade to ValueError in v0.15 warnings.warn( f"Found 'cirq_type': '{base_dict['cirq_type']}' in user-specified _json_dict_. " - "This field is now automatically generated from the class name and (if present) " - "its _json_namespace_ method; this produces the same serialization format as " - "the existing convention of `[namespace.]class_name`." + "'cirq_type' is now automatically generated from the class's name and its " + "_json_namespace_ method as `cirq_type: '[.]'`." "\n\n" "Starting in v0.15, custom 'cirq_type' values will trigger an error. " - "To fix this, remove 'cirq_type' from the class _json_dict_ method. Classes " - "outside of cirq should also define a non-empty _json_namespace_ to avoid " - "collision with Cirq classes.", + "To fix this, remove 'cirq_type' from the class _json_dict_ method and " + "define _json_namespace_ for the class." + "\n\n" + "For backwards compatibility, classes whose old 'cirq_type' does not match the " + "new value must appear in `json_resolver_cache.py::_class_resolver_dictionary()` " + "under both values.", DeprecationWarning, ) return base_dict From 6627d9cc4d743e428316910450f18091224a916c Mon Sep 17 00:00:00 2001 From: Orion Martin <40585662+95-martin-orion@users.noreply.github.com> Date: Fri, 13 May 2022 15:32:41 -0700 Subject: [PATCH 4/4] point at custom resolver docs --- cirq-core/cirq/protocols/json_serialization.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cirq-core/cirq/protocols/json_serialization.py b/cirq-core/cirq/protocols/json_serialization.py index dbe83d6d521..d412f8dadde 100644 --- a/cirq-core/cirq/protocols/json_serialization.py +++ b/cirq-core/cirq/protocols/json_serialization.py @@ -291,9 +291,10 @@ def _json_dict_with_cirq_type(obj: Any): "To fix this, remove 'cirq_type' from the class _json_dict_ method and " "define _json_namespace_ for the class." "\n\n" - "For backwards compatibility, classes whose old 'cirq_type' does not match the " - "new value must appear in `json_resolver_cache.py::_class_resolver_dictionary()` " - "under both values.", + "For backwards compatibility, third-party classes whose old 'cirq_type' value " + "does not match the new value must appear under BOTH values in the resolver " + "for that package. For details on defining custom resolvers, see the " + "DEFAULT_RESOLVER docstring in cirq-core/cirq/protocols/json_serialization.py.", DeprecationWarning, ) return base_dict