def norm(self, i: SerdeInst, t: FR, ctx: SerdeStepContext): if sys.version_info >= (3, 7): t = t._evaluate(ctx.mod.__dict__, ctx.mod.__dict__) else: t = t._eval_type(ctx.mod.__dict__, ctx.mod.__dict__) t = i.norm(t, ctx) return t
def norm(self, i: SerdeInst, t: Any, ctx: SerdeStepContext) -> Any: *args, _ = t.__args__ args = tuple(i.norm(x, ctx) for x in args) if len(args) > 1: return Optional[Union[args]] else: return Optional[args[0]]
def step(self, i: SerdeInst, t: Any, ctx: SerdeStepContext) -> SerdeNode: # todo: here, we may need to instantiate the generic items t, ctx = _build_generic_context(t, ctx) xt = t if sys.version_info >= (3, 7): is_gen = hasattr(t, '__origin__') if is_gen: xt = t.__origin__ logging.getLogger(__name__ + '.DataclassSerde.step').debug( '%s %s', t, ctx) return SerdeNode(i.norm(t, ctx), [ i.norm(f.type, ctx) for f in sorted(fields(xt), key=lambda x: x.name) ], ctx)
def step(self, i: SerdeInst, t: CallableArgsWrapper, ctx: SerdeStepContext) -> SerdeNode: if t.cls: ctx = build_generic_context(t.cls, ctx) ctx = ctx.merge(SerdeStepContext(mod=build_obj_module(t.cls))) types = sorted(self._build_args(t).items(), key=lambda x: x[0]) types = [i.norm(x, ctx) for _, x in types] return SerdeNode(t, types, ctx)
def step(self, i: SerdeInst, t: Any, ctx: SerdeStepContext) -> SerdeNode: xt = t if sys.version_info >= (3, 7): is_gen = hasattr(t, '__origin__') if is_gen: xt = t.__origin__ ctx = SerdeStepContext(mod=build_obj_module(t)) return SerdeNode( t, [i.norm(st, ctx) for f, st in sorted(xt._field_types.items())], ctx=ctx)
def step(self, i: SerdeInst, t: Any, ctx: SerdeStepContext) -> SerdeNode: *args, _ = t.__args__ args = tuple(i.norm(x, ctx) for x in args) deps = [] if len(args) > 1: deps = [Union[args]] else: deps = [args[0]] return SerdeNode(self.norm(i, t, ctx), deps, ctx)
def step(self, i: SerdeInst, t: CallableRetWrapper, ctx: SerdeStepContext) -> SerdeNode: if t.cls: ctx = build_generic_context(t.cls, ctx) ctx = ctx.merge(SerdeStepContext(mod=build_obj_module(t.cls))) RET = 'return' dt = None if RET in t.spec.annotations: dt = i.norm(t.spec.annotations[RET], ctx) return SerdeNode(t, [dt], ctx)
def step(self, i: SerdeInst, t: Any, ctx: SerdeStepContext) -> SerdeNode: kt, vt = t.__args__ kt, vt = i.norm(kt, ctx), i.norm(vt, ctx) return SerdeNode(Dict[kt, vt], [kt, vt])
def step(self, i: SerdeInst, t: Any, ctx: SerdeStepContext) -> SerdeNode: t = i.norm(t, ctx) return SerdeNode(t, [x for x in t.__args__], ctx=ctx)
def norm(self, i: SerdeInst, t: Any, ctx: SerdeStepContext) -> Any: _, ctx = _build_generic_context(t, ctx) args = tuple(i.norm(st, ctx) for st in t.__args__) return Tuple[args]
def step(self, i: SerdeInst, t: Any, ctx: SerdeStepContext) -> SerdeNode: return i.step(i.norm(t, ctx), ctx)
def norm(self, i: SerdeInst, t: Any, ctx: SerdeStepContext) -> Any: _, ctx = _build_generic_context(t, ctx) st, = t.__args__ st = i.norm(st, ctx) return List[st]
def step(self, i: SerdeInst, t: Any, ctx: SerdeStepContext) -> SerdeNode: ordered = self.extract_ordered(Union[tuple( i.norm(x, ctx) for x in t.__args__)]) return SerdeNode(Union[tuple(x for _, x in ordered)], [t for _, t in ordered], ctx)
def norm(self, i: SerdeInst, t: Any, ctx: SerdeStepContext) -> Any: st = tuple(i.norm(x, ctx) for x in t.__args__) return Union[st]