Beispiel #1
0
 def declared_dataclass(self) -> Alt[Exported]:
     return Alt.lift(
         self.export(
             self.default_dataclass_name,
             scripter.nameable_class_dec(
                 [],
                 [
                     line for field_name, field in self.fields
                     for typing_expr in field.typing_expr
                     for default_factory_expr in field.default_factory_expr
                     for line in (scripter.comments(
                         get_tag_values(field.ts_decon.context.field_tags,
                                        "description")
                     ) + [
                         scripter.assignment(
                             get_safe_ident(field_name),
                             self.apply_expr(
                                 self.dataclass_field_expr(
                                     default_factory=default_factory_expr)),
                             typing=self.apply_expr(typing_expr),
                         )
                     ])
                 ],
                 doc_str=get_tag_values(self.codegen_file.t.tags,
                                        "description"),
                 decorators=[
                     self.import_ident(
                         Exported(Path("dataclasses"), "dataclass"))
                 ],
             ),
         ))
Beispiel #2
0
    def declared_dataclass(self) -> Alt[Exported]:
        type_decon = get_material_type_deconstructor(
            self.idol_data.config.params.all_types, self.t)

        codegen_ident: Alt[str] = Alt(
            self.import_ident(codegen_schema, self.default_dataclass_name +
                              "Codegen") for codegen_schema in
            self.idol_data.codegen_file(self.t.named).declared_constructor
            if type_decon.get_struct() or type_decon.get_enum())

        return Alt(
            self.export(
                self.default_dataclass_name,
                scripter.nameable_class_dec(
                    [ident],
                    [],
                ),
            ) for ident in codegen_ident if type_decon.get_struct()) + Alt(
                self.export(
                    self.default_dataclass_name,
                    scripter.assignable(
                        ident,
                        scripter.index_access(
                            self.import_ident(Exported(Path("typing"),
                                                       "Type")), ident)),
                ) for ident in codegen_ident if type_decon.get_enum())
Beispiel #3
0
 def declared_enum(self) -> Alt[Exported]:
     return Alt.lift(
         self.export(
             self.default_enum_name,
             scripter.nameable_class_dec(
                 [self.import_ident(Exported(Path("enum"), "Enum"))],
                 [
                     scripter.assignment(name.upper(),
                                         scripter.literal(name))
                     for name in self.options
                 ],
                 doc_str=get_tag_values(self.codegen_file.t.tags,
                                        "description"),
             ),
         ))
Beispiel #4
0
    def declared_schema(self) -> Alt[Exported]:
        type_decon = get_material_type_deconstructor(
            self.idol_mar.config.params.all_types, self.t)

        codegen_schema_ident: Alt[str] = Alt(
            self.import_ident(codegen_schema, self.default_schema_name +
                              "Codegen") for codegen_schema in
            self.idol_mar.codegen_file(self.t.named).declared_schema
            if type_decon.get_struct())

        return Alt(
            self.export(
                self.default_schema_name,
                scripter.nameable_class_dec([codegen_ident], [],
                                            doc_str=get_tag_values(
                                                self.t.tags, "description")),
            ) for codegen_ident in codegen_schema_ident
            if type_decon.get_struct())
Beispiel #5
0
 def declared_ident(self) -> Alt[Exported]:
     return Alt.lift(
         self.export(
             self.codegen_file.default_type_name,
             scripter.nameable_class_dec(
                 [
                     self.import_ident(
                         self.codegen_file.idol_py.idol_py_file.struct)
                 ],
                 [
                     line for field_name, field in self.fields
                     for typing_expr in field.typing_expr
                     for line in (scripter.comments(
                         get_tag_values(field.ts_decon.context.field_tags,
                                        "description")
                     ) + [
                         scripter.typing(get_safe_ident(field_name),
                                         self.apply_expr(typing_expr)),
                         "",
                     ])
                 ] + [
                     scripter.assignment(
                         "__field_constructors__",
                         scripter.array(
                             scripter.tuple(
                                 scripter.literal(field_name),
                                 scripter.literal(get_safe_ident(
                                     field_name)),
                                 self.apply_expr(field_expr),
                                 scripter.invocation(
                                     "dict",
                                     optional=scripter.literal(
                                         includes_tag(
                                             field.ts_decon.context.
                                             field_tags, "optional")),
                                 ),
                             ) for field_name, field in self.fields
                             for field_expr in field.constructor_expr),
                     )
                 ],
                 doc_str=get_tag_values(self.codegen_file.t.tags,
                                        "description"),
             ),
         ))
Beispiel #6
0
 def declared_schema(self) -> Alt[Exported]:
     return Alt.lift(
         self.export(
             self.codegen_file.default_schema_name,
             scripter.nameable_class_dec(
                 [
                     self.import_ident(
                         Exported(Path("marshmallow"), "Schema"))
                 ],
                 [
                     line for field_name, field in self.fields
                     for composer in field.field_composer
                     for line in (scripter.comments(
                         get_tag_values(field.ts_decon.context.field_tags,
                                        "description")
                     ) + [
                         scripter.assignment(
                             get_safe_ident(field_name),
                             self.apply_expr(
                                 composer.with_more_kwds(
                                     dict(
                                         dump_to=scripter.literal(
                                             field_name),
                                         load_from=scripter.literal(
                                             field_name),
                                         allow_none=scripter.literal(
                                             includes_tag(
                                                 field.ts_decon.context.
                                                 field_tags,
                                                 "optional",
                                             )),
                                     )).field_instance_expr()),
                         )
                     ])
                 ],
                 doc_str=get_tag_values(self.codegen_file.t.tags,
                                        "description"),
             ),
         ))