python: add type hints for enum sub-classes and sub-class `__init__`

methods.
This commit is contained in:
Omar 2023-07-10 02:07:21 +03:00 коммит произвёл Jan-Erik Rediger
Родитель 2e5021df23
Коммит e7a6808398
1 изменённых файлов: 5 добавлений и 1 удалений

Просмотреть файл

@ -19,7 +19,11 @@ class {{ type_name }}:
# Each enum variant is a nested class of the enum itself. # Each enum variant is a nested class of the enum itself.
{% for variant in e.variants() -%} {% for variant in e.variants() -%}
class {{ variant.name()|enum_variant_py }}: class {{ variant.name()|enum_variant_py }}:
def __init__(self,{% for field in variant.fields() %}{{ field.name()|var_name }}{% if loop.last %}{% else %}, {% endif %}{% endfor %}): {% for field in variant.fields() %}
{{- field.name()|var_name }}: "{{- field|type_name }}";
{%- endfor %}
def __init__(self,{% for field in variant.fields() %}{{ field.name()|var_name }}: "{{- field|type_name }}"{% if loop.last %}{% else %}, {% endif %}{% endfor %}):
{% if variant.has_fields() %} {% if variant.has_fields() %}
{%- for field in variant.fields() %} {%- for field in variant.fields() %}
self.{{ field.name()|var_name }} = {{ field.name()|var_name }} self.{{ field.name()|var_name }} = {{ field.name()|var_name }}