Add warnings when calling deprecated method (#596)
* Add test * To run the workflow * Fix import * Format * Add warning * Fix indentation * Test deprecated method * More test * Format * Add import if needed --------- Co-authored-by: Adrien Vannson <adrien.vannson@gardacp.com>
This commit is contained in:
		| @@ -275,8 +275,21 @@ class OutputTemplate: | ||||
|     @property | ||||
|     def python_module_imports(self) -> Set[str]: | ||||
|         imports = set() | ||||
|  | ||||
|         has_deprecated = False | ||||
|         if any(m.deprecated for m in self.messages): | ||||
|             has_deprecated = True | ||||
|         if any(x for x in self.messages if any(x.deprecated_fields)): | ||||
|             has_deprecated = True | ||||
|         if any( | ||||
|             any(m.proto_obj.options.deprecated for m in s.methods) | ||||
|             for s in self.services | ||||
|         ): | ||||
|             has_deprecated = True | ||||
|  | ||||
|         if has_deprecated: | ||||
|             imports.add("warnings") | ||||
|  | ||||
|         if self.builtins_import: | ||||
|             imports.add("builtins") | ||||
|         return imports | ||||
|   | ||||
| @@ -84,6 +84,10 @@ class {{ service.py_name }}Stub(betterproto.ServiceStub): | ||||
|         {% if method.comment %} | ||||
| {{ method.comment }} | ||||
|  | ||||
|         {% endif %} | ||||
|         {% if method.proto_obj.options.deprecated %} | ||||
|         warnings.warn("{{ service.py_name }}.{{ method.py_name }} is deprecated", DeprecationWarning) | ||||
|  | ||||
|         {% endif %} | ||||
|         {% if method.server_streaming %} | ||||
|             {% if method.client_streaming %} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user