Deserialize a JSON-serialized RType. Arguments: data: The decoded JSON of the serialized type ctx: The deserialization maps to use
(data: JsonDict | str, ctx: DeserMaps)
| 114 | |
| 115 | |
| 116 | def deserialize_type(data: JsonDict | str, ctx: DeserMaps) -> RType: |
| 117 | """Deserialize a JSON-serialized RType. |
| 118 | |
| 119 | Arguments: |
| 120 | data: The decoded JSON of the serialized type |
| 121 | ctx: The deserialization maps to use |
| 122 | """ |
| 123 | # Since there are so few types, we just case on them directly. If |
| 124 | # more get added we should switch to a system like mypy.types |
| 125 | # uses. |
| 126 | if isinstance(data, str): |
| 127 | if data in ctx.classes: |
| 128 | return RInstance(ctx.classes[data]) |
| 129 | elif data in RPrimitive.primitive_map: |
| 130 | return RPrimitive.primitive_map[data] |
| 131 | elif data == "void": |
| 132 | return RVoid() |
| 133 | else: |
| 134 | assert False, f"Can't find class {data}" |
| 135 | elif data[".class"] == "RTuple": |
| 136 | return RTuple.deserialize(data, ctx) |
| 137 | elif data[".class"] == "RUnion": |
| 138 | return RUnion.deserialize(data, ctx) |
| 139 | elif data[".class"] == "RVec": |
| 140 | return RVec.deserialize(data, ctx) |
| 141 | raise NotImplementedError("unexpected .class {}".format(data[".class"])) |
| 142 | |
| 143 | |
| 144 | class RTypeVisitor(Generic[T]): |
no test coverage detected
searching dependent graphs…