Fix incorrect deprecation warnings on defaults (#348)

This change ensures that deprecation warnings are only raised when
either a deprecated field is explicitly set or a deprecated message is
initialised.

Resolves: #347
This commit is contained in:
Arun Babu Neelicattu
2022-03-11 23:36:14 +00:00
committed by GitHub
parent 9c1bf25304
commit 69f4192341
7 changed files with 65 additions and 39 deletions
+1 -1
View File
@@ -63,7 +63,7 @@ class {{ message.py_name }}(betterproto.Message):
{% endif %}
super().__post_init__()
{% for field in message.deprecated_fields %}
if self.{{ field }}:
if self.is_set("{{ field }}"):
warnings.warn("{{ message.py_name }}.{{ field }} is deprecated", DeprecationWarning)
{% endfor %}
{% endif %}