Support deprecated message and fields (#126)

This commit is contained in:
Arun Babu Neelicattu
2020-07-30 14:47:01 +02:00
committed by GitHub
parent beafc812ff
commit 0cd9510b54
7 changed files with 82 additions and 0 deletions

View File

@@ -1,6 +1,9 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# sources: {{ ', '.join(description.input_filenames) }}
# plugin: python-betterproto
{% for i in description.python_module_imports|sort %}
import {{ i }}
{% endfor %}
from dataclasses import dataclass
{% if description.datetime_imports %}
from datetime import {% for i in description.datetime_imports|sort %}{{ i }}{% if not loop.last %}, {% endif %}{% endfor %}
@@ -50,6 +53,18 @@ class {{ message.py_name }}(betterproto.Message):
pass
{% endif %}
{% if message.deprecated or message.deprecated_fields %}
def __post_init__(self) -> None:
{% if message.deprecated %}
warnings.warn("{{ message.py_name }} is deprecated", DeprecationWarning)
{% endif %}
super().__post_init__()
{% for field in message.deprecated_fields %}
if self.{{ field }}:
warnings.warn("{{ message.py_name }}.{{ field }} is deprecated", DeprecationWarning)
{% endfor %}
{% endif %}
{% endfor %}
{% for service in description.services %}