Exemplo n.º 1
0
 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
Exemplo n.º 2
0
    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]]
Exemplo n.º 3
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)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
 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])
Exemplo n.º 9
0
 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)
Exemplo n.º 10
0
    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]
Exemplo n.º 11
0
 def step(self, i: SerdeInst, t: Any, ctx: SerdeStepContext) -> SerdeNode:
     return i.step(i.norm(t, ctx), ctx)
Exemplo n.º 12
0
    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]
Exemplo n.º 13
0
    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)
Exemplo n.º 14
0
 def norm(self, i: SerdeInst, t: Any, ctx: SerdeStepContext) -> Any:
     st = tuple(i.norm(x, ctx) for x in t.__args__)
     return Union[st]