Beispiel #1
0
 def inner(state: GeneratorAcc, path: Path):
     return scripter.invocation(
         scripter.prop_access(container_expr(state, path), "of"),
         scalar_expression(state, path),
         scripter.invocation(
             "dict",
             atleast_one=scripter.literal(
                 includes_tag(self.ts_decon.context.type_tags,
                              "atleast_one")),
         ),
     )
Beispiel #2
0
 def inner(state: GeneratorAcc, path: Path) -> str:
     return scripter.invocation(
         scripter.prop_access(
             state.import_ident(
                 path, self.idol_py.idol_py_file.primitive), "of"),
         prim_expr(state, path),
     )
Beispiel #3
0
 def inner(state: GeneratorAcc, path: Path) -> str:
     return scripter.invocation(
         scripter.prop_access(
             state.import_ident(path,
                                self.idol_py.idol_py_file.literal),
             "of"),
         scripter.literal(value),
     )
Beispiel #4
0
 def expr(state: GeneratorAcc, path: Path) -> str:
     args, kwds = self.resolve_args_and_kwds(state, path)
     return scripter.invocation(
         state.import_ident(path, idol_mar.idol_mar_file.wrap_field),
         self.constructor_ident(state, path),
         scripter.literal(name),
         *list(scripter.thunk(arg) for arg in args),
         **kwds,
     )
Beispiel #5
0
        def expr(state: GeneratorAcc, path: Path) -> str:
            kwds = {}
            if default:
                kwds["default"] = default(state, path)
            if default_factory:
                kwds["default_factory"] = default_factory(state, path)

            return scripter.invocation(
                state.import_ident(path, Exported(Path("dataclasses"),
                                                  "field")), **kwds)
Beispiel #6
0
                    def lazy_import(state: GeneratorAcc, path: Path) -> str:
                        import_module = state.import_ident(
                            path, Exported(Path("importlib"), "import_module"))

                        return scripter.prop_access(
                            scripter.invocation(
                                import_module,
                                scripter.literal(
                                    ImportPath.as_python_module_path(
                                        path.import_path_to(
                                            scaffold_declared_schema.path).
                                        rel_path)),
                                "__package__",
                            ),
                            scaffold_declared_schema.ident,
                        )
Beispiel #7
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 #8
0
 def expr(state: GeneratorAcc, path: Path) -> str:
     args, kwds = self.resolve_args_and_kwds(state, path)
     return scripter.invocation(self.constructor_ident(state, path),
                                *args, **kwds)
Beispiel #9
0
 def inner(state: GeneratorAcc, path: Path) -> str:
     return scripter.thunk(
         scripter.invocation(
             "next",
             scripter.invocation(
                 "iter", state.import_ident(path, declared_enum))))