Skip to content

Commit ccfadf3

Browse files
Add type hints to analyzer.py
This change adds type annotations and necessary imports to the examples/google-ads-account-analyzer-demo/analyzer.py script. Type hints were added to the following functions: - account_hierarchy_module - print_account_hierarchy - get_users_module I verified the annotations, and one issue related to an untyped dictionary was fixed. Remaining errors originate from the google-ads library itself.
1 parent 4f350a8 commit ccfadf3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

examples/google-ads-account-analyzer-demo/analyzer.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717

1818
import argparse
1919
import sys
20+
from typing import Optional, Dict, List, Any
2021

2122
from google.ads.googleads.client import GoogleAdsClient
2223
from google.ads.googleads.errors import GoogleAdsException
2324

2425
_DEFAULT_LOG_SPACE_LENGTH = 4
2526

2627

27-
def account_hierarchy_module(google_ads_client, customer_id):
28+
def account_hierarchy_module(google_ads_client: GoogleAdsClient, customer_id: Optional[str]):
2829
"""Print the account hierarchy for the given login customer ID.
2930
3031
Args:
@@ -74,7 +75,7 @@ def account_hierarchy_module(google_ads_client, customer_id):
7475
# Performs a breadth-first search to build a Dictionary that maps
7576
# managers to their child accounts (customer_ids_to_child_accounts).
7677
unprocessed_customer_ids = [seed_customer_id]
77-
customer_ids_to_child_accounts = dict()
78+
customer_ids_to_child_accounts: Dict[str, List[Any]] = dict()
7879
root_customer_client = None
7980

8081
while unprocessed_customer_ids:
@@ -129,7 +130,7 @@ def account_hierarchy_module(google_ads_client, customer_id):
129130

130131

131132
def print_account_hierarchy(
132-
customer_client, customer_ids_to_child_accounts, depth
133+
customer_client: Any, customer_ids_to_child_accounts: Dict[str, List[Any]], depth: int
133134
):
134135
"""Prints the specified account's hierarchy using recursion.
135136
@@ -157,7 +158,7 @@ def print_account_hierarchy(
157158
)
158159

159160

160-
def get_users_module(google_ads_client, customer_id):
161+
def get_users_module(google_ads_client: GoogleAdsClient, customer_id: Optional[str]):
161162
"""Prints the user access information for the given customer_id.
162163
163164
Args:

0 commit comments

Comments
 (0)