xsdata.formats.dataclass.generator module

class xsdata.formats.dataclass.generator.DataclassGenerator[source]

Bases: xsdata.formats.mixins.AbstractGenerator

Python dataclasses code generator.

render(classes)[source]

Return a iterator of the generated results.

Group classes into modules and yield an output per module and per package __init__.py file.

Parameters

classes (List[Class]) –

Return type

Iterator[GeneratorResult]

render_package(classes)[source]

Render the source code for the __init__.py with all the imports of the generated class names.

Parameters

classes (List[Class]) –

Return type

str

render_module(resolver, classes)[source]

Render the source code for the target module of the given class list.

Parameters
Return type

str

render_classes(classes)[source]

Render the source code of the classes.

Parameters

classes (List[Class]) –

Return type

str

classmethod ensure_packages(package)[source]

Ensure all the __init__ files exists for the target package path, otherwise yield the necessary filepath, name, source output that needs to be crated.

Parameters

package (Path) –

Return type

Iterator[GeneratorResult]

classmethod group_imports(imports)[source]

Group the given list of packages by the source path.

Parameters

imports (List[Package]) –

Return type

Dict[str, List[Package]]

classmethod module_name(module)[source]

Convert the given module name to safe snake case.

Parameters

module (str) –

Return type

str

classmethod package_name(package)[source]

Convert the given package name to safe snake case.

Parameters

package (str) –

Return type

str