-
-
Notifications
You must be signed in to change notification settings - Fork 435
Expand file tree
/
Copy pathdataclass.jinja2
More file actions
46 lines (44 loc) · 1.26 KB
/
dataclass.jinja2
File metadata and controls
46 lines (44 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{% for decorator in decorators -%}
{{ decorator }}
{% endfor -%}
{%- set args = [] %}
{%- for k, v in (dataclass_arguments or {}).items() %}
{%- if v is not none and v is not false %}
{%- set _ = args.append(k ~ '=' ~ (v|pprint)) %}
{%- endif %}
{%- endfor %}
{%- if args %}
@dataclass({{ args | join(', ') }})
{%- else %}
@dataclass
{%- endif %}
{%- if base_class %}
class {{ class_name }}({{ base_class }}):
{%- else %}
class {{ class_name }}:
{%- endif %}
{%- if description %}
{{ description | format_docstring(4) }}
{%- endif %}
{%- if not fields and not description %}
pass
{%- endif %}
{%- for field in fields -%}
{%- if field.field %}
{{ field.name }}: {{ field.type_hint }} = {{ field.field }}
{%- else %}
{{ field.name }}: {{ field.type_hint }}
{%- if not (field.required or (field.represented_default == 'None' and field.strip_default_none))
%} = {{ field.represented_default }}
{%- endif -%}
{%- endif %}
{%- if field.docstring %}
{{ field.docstring | format_docstring(4) }}
{%- if field.use_inline_field_description and not loop.last %}
{% endif %}
{%- elif field.inline_field_docstring %}
{{ field.inline_field_docstring }}
{%- if not loop.last %}
{% endif %}
{%- endif %}
{%- endfor -%}