Skip to content
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
Binary file removed language/snippets/cloud-client/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion language/snippets/cloud-client/v1/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Install Dependencies
.. _Python Development Environment Setup Guide:
https://cloud.google.com/python/setup

#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+.
#. Create a virtualenv. Samples are compatible with Python 3.9+.

.. code-block:: bash

Expand Down
12 changes: 5 additions & 7 deletions language/snippets/cloud-client/v1/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,21 @@
# limitations under the License.


def run_quickstart():
def run_quickstart() -> None:
# [START language_quickstart]
# Imports the Google Cloud client library
# Imports the Google Cloud client library.
from google.cloud import language_v1

# Instantiates a client
# [START language_python_migration_client]
# Instantiates a client.
client = language_v1.LanguageServiceClient()
# [END language_python_migration_client]

# The text to analyze
# The text to analyze.
text = "Hello, world!"
document = language_v1.types.Document(
content=text, type_=language_v1.types.Document.Type.PLAIN_TEXT
)

# Detects the sentiment of the text
# Detects the sentiment of the text.
sentiment = client.analyze_sentiment(
request={"document": document}
).document_sentiment
Expand Down
3 changes: 2 additions & 1 deletion language/snippets/cloud-client/v1/quickstart_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest

import quickstart


def test_quickstart(capsys):
def test_quickstart(capsys: pytest.LogCaptureFixture) -> None:
quickstart.run_quickstart()
out, _ = capsys.readouterr()
assert "Sentiment" in out
10 changes: 5 additions & 5 deletions language/snippets/cloud-client/v1/set_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@
# limitations under the License.


def set_endpoint():
"""Change your endpoint"""
def set_endpoint() -> None:
"""Change your endpoint."""
# [START language_set_endpoint]
# Imports the Google Cloud client library
from google.cloud import language_v1

client_options = {"api_endpoint": "eu-language.googleapis.com:443"}

# Instantiates a client
# Instantiates a client.
client = language_v1.LanguageServiceClient(client_options=client_options)
# [END language_set_endpoint]

# The text to analyze
# The text to analyze.
document = language_v1.Document(
content="Hello, world!", type_=language_v1.Document.Type.PLAIN_TEXT
)

# Detects the sentiment of the text
# Detects the sentiment of the text.
sentiment = client.analyze_sentiment(
request={"document": document}
).document_sentiment
Expand Down
4 changes: 3 additions & 1 deletion language/snippets/cloud-client/v1/set_endpoint_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest

import set_endpoint


def test_set_endpoint(capsys):
def test_set_endpoint(capsys: pytest.LogCaptureFixture) -> None:
set_endpoint.set_endpoint()

out, _ = capsys.readouterr()
Expand Down