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: # 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: Any, ctx: SerdeStepContext) -> SerdeNode: return SerdeNode(t, [])
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 = t if inspect.isclass(t) else t.__class__ return SerdeNode(t, [])
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 step(self, i: SerdeInst, t: Any, ctx: SerdeStepContext) -> SerdeNode: z = ([x for x in self.ATOMS if isinstance(t, x)] + [t for x in self.ATOMS if issubclass(t, x)])[0] return SerdeNode(z, [])
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)