Skip to content

Commit

Permalink
chore(language): update samples
Browse files Browse the repository at this point in the history
- Remove unused region tags.
- Fixes for linter with types.
- Apply Python Style Guide.
  • Loading branch information
eapl-gemugami committed Feb 20, 2025
1 parent 71ec72d commit 2de7dee
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
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

0 comments on commit 2de7dee

Please sign in to comment.