![]() |
Create a dataclass that supports JSON serialization.
cirq.json_serializable_dataclass(
_cls: Optional[Type] = None,
*,
namespace: Optional[str] = None,
init: bool = True,
repr: bool = True,
eq: bool = True,
order: bool = False,
unsafe_hash: bool = False,
frozen: bool = False
)
This function defers to the ordinary dataclass
decorator but appends
the _json_dict_
protocol method which automatically determines
the appropriate fields from the dataclass.
Dataclasses are implemented with somewhat complex metaprogramming, and
tooling (PyCharm, mypy) have special cases for dealing with classes
decorated with @dataclass. There is very little support (and no plans for
support) for decorators that wrap @dataclass like this. Consider explicitly
defining _json_dict_
on your dataclasses which simply
return dataclass_json_dict(self)
.
Args | |
---|---|
_cls
|
The class to add JSON serializatin to. |
namespace
|
An optional prefix to the value associated with the key "cirq_type". The namespace name will be joined with the class name via a dot (.) |
init
|
Forwarded to the dataclass constructor.
|
repr
|
Forwarded to the dataclass constructor.
|
eq
|
Forwarded to the dataclass constructor.
|
order
|
Forwarded to the dataclass constructor.
|
unsafe_hash
|
Forwarded to the dataclass constructor.
|
frozen
|
Forwarded to the dataclass constructor.
|