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
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 norm(self, i: SerdeInst, t: Any, ctx: SerdeStepContext) -> Any: t, ctx = _build_generic_context(t, ctx) return t
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 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 build_generic_context(*args): _, r = _build_generic_context(*args) return r