Skip to content

Commit

Permalink
fix: import warnings when needed (#930)
Browse files Browse the repository at this point in the history
* fix: import warnings when needed

* fix: remove stray }
  • Loading branch information
busunkim96 authored Jun 28, 2021
1 parent ceb64d9 commit d4270ae
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import os
import re
from typing import Callable, Dict, Optional, {% if service.any_server_streaming %}Iterable, {% endif %}{% if service.any_client_streaming %}Iterator, {% endif %}Sequence, Tuple, Type, Union
import pkg_resources
{% if service.any_deprecated %}
import warnings
{% endif %}

from google.api_core import client_options as client_options_lib # type: ignore
from google.api_core import exceptions as core_exceptions # type: ignore
Expand Down Expand Up @@ -335,7 +338,9 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
{% endif %}
"""
{% if method.is_deprecated %}
warnings.warn("{{ method.name|snake_case }} is deprecated", warnings.DeprecationWarning)
warnings.warn("{{ service.client_name }}.{{ method.name|snake_case }} is deprecated",
warnings.DeprecationWarning)

{% endif %}
{% if not method.client_streaming %}
# Create or coerce a protobuf request object.
Expand Down
4 changes: 4 additions & 0 deletions gapic/schema/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,10 @@ def any_client_streaming(self) -> bool:
def any_server_streaming(self) -> bool:
return any(m.server_streaming for m in self.methods.values())

@utils.cached_property
def any_deprecated(self) -> bool:
return any(m.is_deprecated for m in self.methods.values())

def with_context(self, *, collisions: FrozenSet[str]) -> 'Service':
"""Return a derivative of this service with the provided context.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import functools
import re
from typing import Dict, {% if service.any_server_streaming %}AsyncIterable, Awaitable, {% endif %}{% if service.any_client_streaming %}AsyncIterator, {% endif %}Sequence, Tuple, Type, Union
import pkg_resources
{% if service.any_deprecated %}
import warnings
{% endif %}

import google.api_core.client_options as ClientOptions # type: ignore
from google.api_core import exceptions as core_exceptions # type: ignore
Expand Down Expand Up @@ -196,6 +199,11 @@ class {{ service.async_client_name }}:
{{ method.client_output_async.meta.doc|rst(width=72, indent=16, source_format='rst') }}
{% endif %}
"""
{% if method.is_deprecated %}
warnings.warn("{{ service.async_client_name }}.{{ method.name|snake_case }} is deprecated",
warnings.DeprecationWarning)

{% endif %}
{% if not method.client_streaming %}
# Create or coerce a protobuf request object.
{% if method.flattened_fields %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import os
import re
from typing import Callable, Dict, Optional, {% if service.any_server_streaming %}Iterable, {% endif %}{% if service.any_client_streaming %}Iterator, {% endif %}Sequence, Tuple, Type, Union
import pkg_resources
{% if service.any_deprecated %}
import warnings
{% endif %}

from google.api_core import client_options as client_options_lib # type: ignore
from google.api_core import exceptions as core_exceptions # type: ignore
Expand Down Expand Up @@ -360,7 +363,9 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
{% endif %}
"""
{% if method.is_deprecated %}
warnings.warn("{{ method.name|snake_case }} is deprecated", warnings.DeprecationWarning)
warnings.warn("{{ service.client_name }}.{{ method.name|snake_case }} is deprecated",
warnings.DeprecationWarning)

{% endif %}
{% if not method.client_streaming %}
# Create or coerce a protobuf request object.
Expand Down

0 comments on commit d4270ae

Please sign in to comment.