예제 #1
0
    def match(self, t: Any, ctx: SerdeStepContext) -> bool:
        t, _ = _build_generic_context(t, ctx)

        if sys.version_info >= (3, 7):
            if hasattr(t, '__origin__'):
                return t.__origin__ is tuple

        if inspect.isclass(t):
            return issubclass(t, Tuple)
        else:
            return False
예제 #2
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)
예제 #3
0
 def norm(self, i: SerdeInst, t: Any, ctx: SerdeStepContext) -> Any:
     t, ctx = _build_generic_context(t, ctx)
     return t
예제 #4
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]
예제 #5
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]
예제 #6
0
def build_generic_context(*args):
    _, r = _build_generic_context(*args)
    return r