Type operator Unpack from PEP646. Can be either with Unpack[] or unpacking * syntax. The inner type should be either a TypeVarTuple, or a variable length tuple. In an exceptional case of callable star argument it can be a fixed length tuple. Note: the above restrictions are only gu
| 1213 | |
| 1214 | |
| 1215 | class UnpackType(ProperType): |
| 1216 | """Type operator Unpack from PEP646. Can be either with Unpack[] |
| 1217 | or unpacking * syntax. |
| 1218 | |
| 1219 | The inner type should be either a TypeVarTuple, or a variable length tuple. |
| 1220 | In an exceptional case of callable star argument it can be a fixed length tuple. |
| 1221 | |
| 1222 | Note: the above restrictions are only guaranteed by normalizations after semantic |
| 1223 | analysis, if your code needs to handle UnpackType *during* semantic analysis, it is |
| 1224 | wild west, technically anything can be present in the wrapped type. |
| 1225 | """ |
| 1226 | |
| 1227 | __slots__ = ["type", "from_star_syntax"] |
| 1228 | |
| 1229 | def __init__( |
| 1230 | self, typ: Type, line: int = -1, column: int = -1, from_star_syntax: bool = False |
| 1231 | ) -> None: |
| 1232 | super().__init__(line, column) |
| 1233 | self.type = typ |
| 1234 | self.from_star_syntax = from_star_syntax |
| 1235 | |
| 1236 | def accept(self, visitor: TypeVisitor[T]) -> T: |
| 1237 | return visitor.visit_unpack_type(self) |
| 1238 | |
| 1239 | def serialize(self) -> JsonDict: |
| 1240 | return {".class": "UnpackType", "type": self.type.serialize()} |
| 1241 | |
| 1242 | def write(self, data: WriteBuffer) -> None: |
| 1243 | write_tag(data, UNPACK_TYPE) |
| 1244 | self.type.write(data) |
| 1245 | write_tag(data, END_TAG) |
| 1246 | |
| 1247 | @classmethod |
| 1248 | def read(cls, data: ReadBuffer) -> UnpackType: |
| 1249 | ret = UnpackType(read_type(data)) |
| 1250 | assert read_tag(data) == END_TAG |
| 1251 | return ret |
| 1252 | |
| 1253 | @classmethod |
| 1254 | def deserialize(cls, data: JsonDict) -> UnpackType: |
| 1255 | assert data[".class"] == "UnpackType" |
| 1256 | typ = data["type"] |
| 1257 | return UnpackType(deserialize_type(typ)) |
| 1258 | |
| 1259 | def __hash__(self) -> int: |
| 1260 | return hash(self.type) |
| 1261 | |
| 1262 | def __eq__(self, other: object) -> bool: |
| 1263 | return isinstance(other, UnpackType) and self.type == other.type |
| 1264 | |
| 1265 | |
| 1266 | class AnyType(ProperType): |
no outgoing calls
searching dependent graphs…