Skip to content

Commit d4270ae

Browse files
authored
fix: import warnings when needed (#930)
* fix: import warnings when needed * fix: remove stray }
1 parent ceb64d9 commit d4270ae

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import os
88
import re
99
from typing import Callable, Dict, Optional, {% if service.any_server_streaming %}Iterable, {% endif %}{% if service.any_client_streaming %}Iterator, {% endif %}Sequence, Tuple, Type, Union
1010
import pkg_resources
11+
{% if service.any_deprecated %}
12+
import warnings
13+
{% endif %}
1114

1215
from google.api_core import client_options as client_options_lib # type: ignore
1316
from google.api_core import exceptions as core_exceptions # type: ignore
@@ -335,7 +338,9 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
335338
{% endif %}
336339
"""
337340
{% if method.is_deprecated %}
338-
warnings.warn("{{ method.name|snake_case }} is deprecated", warnings.DeprecationWarning)
341+
warnings.warn("{{ service.client_name }}.{{ method.name|snake_case }} is deprecated",
342+
warnings.DeprecationWarning)
343+
339344
{% endif %}
340345
{% if not method.client_streaming %}
341346
# Create or coerce a protobuf request object.

gapic/schema/wrappers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,10 @@ def any_client_streaming(self) -> bool:
12071207
def any_server_streaming(self) -> bool:
12081208
return any(m.server_streaming for m in self.methods.values())
12091209

1210+
@utils.cached_property
1211+
def any_deprecated(self) -> bool:
1212+
return any(m.is_deprecated for m in self.methods.values())
1213+
12101214
def with_context(self, *, collisions: FrozenSet[str]) -> 'Service':
12111215
"""Return a derivative of this service with the provided context.
12121216

gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import functools
77
import re
88
from typing import Dict, {% if service.any_server_streaming %}AsyncIterable, Awaitable, {% endif %}{% if service.any_client_streaming %}AsyncIterator, {% endif %}Sequence, Tuple, Type, Union
99
import pkg_resources
10+
{% if service.any_deprecated %}
11+
import warnings
12+
{% endif %}
1013

1114
import google.api_core.client_options as ClientOptions # type: ignore
1215
from google.api_core import exceptions as core_exceptions # type: ignore
@@ -196,6 +199,11 @@ class {{ service.async_client_name }}:
196199
{{ method.client_output_async.meta.doc|rst(width=72, indent=16, source_format='rst') }}
197200
{% endif %}
198201
"""
202+
{% if method.is_deprecated %}
203+
warnings.warn("{{ service.async_client_name }}.{{ method.name|snake_case }} is deprecated",
204+
warnings.DeprecationWarning)
205+
206+
{% endif %}
199207
{% if not method.client_streaming %}
200208
# Create or coerce a protobuf request object.
201209
{% if method.flattened_fields %}

gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import os
88
import re
99
from typing import Callable, Dict, Optional, {% if service.any_server_streaming %}Iterable, {% endif %}{% if service.any_client_streaming %}Iterator, {% endif %}Sequence, Tuple, Type, Union
1010
import pkg_resources
11+
{% if service.any_deprecated %}
12+
import warnings
13+
{% endif %}
1114

1215
from google.api_core import client_options as client_options_lib # type: ignore
1316
from google.api_core import exceptions as core_exceptions # type: ignore
@@ -360,7 +363,9 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
360363
{% endif %}
361364
"""
362365
{% if method.is_deprecated %}
363-
warnings.warn("{{ method.name|snake_case }} is deprecated", warnings.DeprecationWarning)
366+
warnings.warn("{{ service.client_name }}.{{ method.name|snake_case }} is deprecated",
367+
warnings.DeprecationWarning)
368+
364369
{% endif %}
365370
{% if not method.client_streaming %}
366371
# Create or coerce a protobuf request object.

0 commit comments

Comments
 (0)