Skip to content

Add type hints to files in examples/advanced_operations #962

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bobhancockg
Copy link
Contributor

This commit introduces type hints to several files within the examples/advanced_operations directory for Google Ads API v19.

The following files have been updated:

  • examples/advanced_operations/add_ad_customizer.py
  • examples/advanced_operations/add_ad_group_bid_modifier.py
  • examples/advanced_operations/add_app_campaign.py
  • examples/advanced_operations/add_bidding_data_exclusion.py
  • examples/advanced_operations/add_bidding_seasonality_adjustment.py
  • examples/advanced_operations/add_call_ad.py
  • examples/advanced_operations/add_demand_gen_campaign.py
  • examples/advanced_operations/add_display_upload_ad.py

Changes include adding type hints for function arguments, return values, and relevant local variables. Necessary types were imported from the typing module and google.ads.googleads.client.

In add_display_upload_ad.py, an argparse type for ad_group_id was corrected from int to str to match its usage.

This commit introduces type hints to several files within the
examples/advanced_operations directory for Google Ads API v19.

The following files have been updated:
- examples/advanced_operations/add_ad_customizer.py
- examples/advanced_operations/add_ad_group_bid_modifier.py
- examples/advanced_operations/add_app_campaign.py
- examples/advanced_operations/add_bidding_data_exclusion.py
- examples/advanced_operations/add_bidding_seasonality_adjustment.py
- examples/advanced_operations/add_call_ad.py
- examples/advanced_operations/add_demand_gen_campaign.py
- examples/advanced_operations/add_display_upload_ad.py

Changes include adding type hints for function arguments, return
values, and relevant local variables. Necessary types were imported
from the `typing` module and `google.ads.googleads.client`.

In `add_display_upload_ad.py`, an `argparse` type for `ad_group_id`
was corrected from `int` to `str` to match its usage.
@bobhancockg bobhancockg requested a review from a team as a code owner May 29, 2025 13:59
AnashOommen
AnashOommen previously approved these changes May 29, 2025
sundquist
sundquist previously approved these changes May 29, 2025
Copy link

@sundquist sundquist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Minor comment.

@@ -162,15 +174,17 @@ def create_display_upload_ad_group_ad(
parser.add_argument(
"-a",
"--ad_group_id",
type=int,
type=str, # Changed to str to match main function signature

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment is no longer necessary.

@BenRKarl BenRKarl added the kokoro:run This label is required to run a kokoro presubmit if an external contributor sends a PR. label Jun 5, 2025
@kokoro-team kokoro-team removed the kokoro:run This label is required to run a kokoro presubmit if an external contributor sends a PR. label Jun 5, 2025
@BenRKarl BenRKarl added the kokoro:force-run This label is required to run a kokoro presubmit if an external contributor sends a PR. label Jun 5, 2025
@kokoro-team kokoro-team removed the kokoro:force-run This label is required to run a kokoro presubmit if an external contributor sends a PR. label Jun 5, 2025
@BenRKarl BenRKarl dismissed stale reviews from sundquist and AnashOommen via 6a82ec2 June 5, 2025 16:25
@BenRKarl BenRKarl added the kokoro:force-run This label is required to run a kokoro presubmit if an external contributor sends a PR. label Jun 5, 2025
@kokoro-team kokoro-team removed the kokoro:force-run This label is required to run a kokoro presubmit if an external contributor sends a PR. label Jun 5, 2025
@@ -73,22 +76,22 @@ def create_text_customizer_attribute(client, customer_id, customizer_name):
Returns:
a resource name for a text customizer attribute.
"""
customizer_attribute_service = client.get_service(
customizer_attribute_service: Any = client.get_service(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can actually specify the type here, it's google.ads.googleads.v20.services.services.customizer_attribute_service.CustomizerAttributeService

We'd need to import it directly.

Looks like this is the case for a few of the API-specific types below too. If we are specific about these types, then there's a slight maintenance overhead as we'll need to ensure the import paths match the API version. What are your thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to import them to use annotations. Would existing types change import paths with any regularity.

This sounds like a verification task that we could hand off to Jules.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure that 99.9% of the time the only change to import paths will be for new version releases, which could easily be handled by Jules or with a basic sed command.

operation = client.get_type("CustomizerAttributeOperation")
price_attribute = operation.create
operation: Any = client.get_type("CustomizerAttributeOperation")
price_attribute: Any = operation.create
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be the type google.ads.googleads.v20.resources.types.CustomizerAttribute

Even though its more overheard, I think it kind of makes sense to specify this. Do you think Jules would be able to figure that out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy