Skip to content

Commit 8cba324

Browse files
authored
Update serialization.md to include deprecation of serializable values (#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.
1 parent 1168164 commit 8cba324

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

cirq-core/cirq/testing/json.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class ModuleJsonTestSpec:
5353
should_not_be_serialized: List[str]
5454
# points to the resolver cache's dict for this module
5555
resolver_cache: Dict[str, ObjectFactory]
56-
# deprecations
56+
# {DeprecatedClass: deprecation_deadline} pairs to avoid deprecation errors
57+
# in serialization tests.
5758
deprecated: Dict[str, str]
5859

5960
def __repr__(self):

docs/dev/serialization.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ Ideally, the contents of the `.repr` file are exactly the output of
113113
`your_class_name.json` should contain the expected JSON output when serializing
114114
the test value from `your_class_name.repr`.
115115

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

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

0 commit comments

Comments
 (0)