Skip to content

Commit

Permalink
Update serialization.md to include deprecation of serializable values (
Browse files Browse the repository at this point in the history
…#4411)

I had to deprecate a serializable value in #4398 and couldn't find documentation around how to do it. This PR adds the relevant documentation.
  • Loading branch information
tanujkhattar committed Aug 11, 2021
1 parent 1168164 commit 8cba324
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cirq-core/cirq/testing/json.py
Expand Up @@ -53,7 +53,8 @@ class ModuleJsonTestSpec:
should_not_be_serialized: List[str]
# points to the resolver cache's dict for this module
resolver_cache: Dict[str, ObjectFactory]
# deprecations
# {DeprecatedClass: deprecation_deadline} pairs to avoid deprecation errors
# in serialization tests.
deprecated: Dict[str, str]

def __repr__(self):
Expand Down
12 changes: 12 additions & 0 deletions docs/dev/serialization.md
Expand Up @@ -113,6 +113,18 @@ Ideally, the contents of the `.repr` file are exactly the output of
`your_class_name.json` should contain the expected JSON output when serializing
the test value from `your_class_name.repr`.

## Deprecating a serializable value
When a serializable value is marked deprecated, but is not yet removed, the
`.json` and `.repr` files continue to exist but `json_serialization_test.py`
will start complaining that deprecated values cannot be used in tests.
In order to fix this, one should add an entry corresponding to deprecated value to the `deprecated` dict in
`cirq-<module>/cirq/protocols/json_test_data/spec.py`, of the form:
```python
deprecated={
'DeprecatedClass': 'deprecation_deadline',
}
```

## Removing a serializable value

When a serializable value is removed from cirq, old serialized instances
Expand Down

0 comments on commit 8cba324

Please sign in to comment.