Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: import warnings when needed #930

Merged
merged 2 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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