Пример #1
0
    def _BUILD_input_translate_fields(cls) -> Callable[[MutableMapping], None]:
        translate = [
            f'data[{field!r}] = data.pop({d.input_name!r}, None)'
            for field, d in cls._options.descriptors.items()
            if d.field != d.input_name
        ]

        return cast(Callable, classmethod(codegen.Function(
            '_input_translate_fields',
            ['cls', 'data'],
            translate if translate else ['pass'],
            globals=globals(),
            locals=locals(),
        )))
Пример #2
0
    def _BUILD_input_translate_fields(cls):
        """Copied and modified from faust's Record._BUILD_input_translate_fields"""
        translate = [
            f"data[{field!r}] = data.pop({d.input_name!r}, None)"
            for field, d in cls._options.descriptors.items()
            if d.field != d.input_name
        ]

        for field, d in cls._options.descriptors.items():
            if is_union_type(d.type):
                translate.append(f"data[{field!r}] = faust_annotate(data[{field!r}])")

        return cast(
            Callable,
            classmethod(
                codegen.Function(
                    "_input_translate_fields",
                    ["cls", "data"],
                    translate if translate else ["pass"],
                    globals=globals(),
                    locals=locals(),
                )
            ),
        )