def _pretty_print(cls, values: typing.MutableMapping, translate_dict: typing.Dict[str, AlgorithmProperty], indent=0): res = "" for k, v in values.items(): if k not in translate_dict: if isinstance(v, typing.MutableMapping): res += " " * indent + f"{k}: {cls._pretty_print(v, {}, indent + 2)}\n" else: res += " " * indent + f"{k}: {v}\n" continue desc = translate_dict[k] res += " " * indent + desc.user_name + ": " if issubclass(desc.value_type, Channel): res += str(Channel(v)) elif issubclass(desc.value_type, AlgorithmDescribeBase): res += desc.possible_values[v["name"]].get_name() if v["values"]: res += "\n" res += cls._pretty_print( v["values"], desc.possible_values[v["name"]].get_fields_dict(), indent + 2) elif isinstance(v, typing.MutableMapping): res += cls._pretty_print(v, {}, indent + 2) else: res += str(v) res += "\n" return res[:-1]
def _func(self, args: t.MutableMapping): # map args back onto the signature. pargs = [] # type: t.List[t.Any] for param in self.positionals: if param.kind == param.VAR_POSITIONAL: pargs.extend(args.pop(param.name)) elif param.kind == param.POSITIONAL_OR_KEYWORD: pargs.append(args.pop(param.name)) for key, value in args.items(): if key.startswith('no_'): args[key[3:]] = args.pop(key) continue return (self.function or (lambda: None))(*pargs, **args)
def filter_empty_fields(data: typing.MutableMapping) -> typing.MutableMapping: required = ('errors', ) if data.get('errors') else ('data', ) return { key: value for key, value in data.items() if key in required or value }