Skip to content

verbosify cirq_type deprecation #5339

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 5 commits into from
May 20, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions cirq-core/cirq/protocols/json_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,17 @@ 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_. "
"'cirq_type' is now automatically generated from the class's name and its "
"_json_namespace_ method as `cirq_type: '[<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 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()` "
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this instruction. My project does not have a json_resolver_cache.py file. Is this a file within cirq? Say it is within cirq, and give the full file path not the name.

Also, this seems rather extreme to require someone who wrote a different library to make a change in cirq to maintaing compatibility across versions? It sounds like this is saying I can't maintain compatibility.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry, I misunderstood how Cirq handles third-party JSON resolvers. The appropriate thing to update for this is whatever custom resolver you are using, as described here. I'll update the instructions to match.

"under both values.",
DeprecationWarning,
)
return base_dict
Expand Down