22import json
33import os
44from datetime import date , datetime
5- from typing import Any , Dict , Iterable , List , Optional , Tuple
5+ from typing import Any , Optional
6+ from collections .abc import Iterable
67
78from google .cloud .bigquery import Client
89from google .cloud .bigquery .job import QueryJobConfig
2223END_DATE = '-1'
2324DEFAULT_LIMIT = 10
2425
25- Rows = List [ List [str ]]
26+ Rows = list [ list [str ]]
2627
2728
2829def create_config () -> QueryJobConfig :
@@ -31,7 +32,7 @@ def create_config() -> QueryJobConfig:
3132 return config
3233
3334
34- def normalize_dates (start_date : str , end_date : str ) -> Tuple [str , str ]:
35+ def normalize_dates (start_date : str , end_date : str ) -> tuple [str , str ]:
3536 """If a date is yyyy-mm, normalize as first or last yyyy-mm-dd of the month.
3637 Otherwise, return unchanged.
3738 """
@@ -85,7 +86,7 @@ def format_date(date: str, timestamp_format: str) -> str:
8586 return date
8687
8788
88- def month_ends (yyyy_mm : str ) -> Tuple [str , str ]:
89+ def month_ends (yyyy_mm : str ) -> tuple [str , str ]:
8990 """Helper to return start_date and end_date of a month as yyyy-mm-dd"""
9091 year , month = map (int , yyyy_mm .split ("-" ))
9192 first = date (year , month , 1 )
@@ -94,7 +95,7 @@ def month_ends(yyyy_mm: str) -> Tuple[str, str]:
9495 return str (first ), str (last )
9596
9697
97- def strip_trailing_zero (release : Tuple [int , ...]) -> Tuple [int , ...]:
98+ def strip_trailing_zero (release : tuple [int , ...]) -> tuple [int , ...]:
9899 """Helper to strip trailing 0 in a tuple of integers"""
99100 new_len = len (release )
100101 while new_len > 1 and release [new_len - 1 ] == 0 :
@@ -271,7 +272,7 @@ def add_percentages(rows: Rows, include_sign: bool = True) -> Rows:
271272 return rows
272273
273274
274- def get_download_total (rows : Rows ) -> Tuple [int , int ]:
275+ def get_download_total (rows : Rows ) -> tuple [int , int ]:
275276 """Return the total downloads, and the downloads column"""
276277 headers = rows .pop (0 )
277278 index = headers .index ('download_count' )
@@ -341,13 +342,13 @@ def tabulate(rows: Rows, markdown: bool = False) -> str:
341342 return tabulated
342343
343344
344- def format_json (rows : Rows , query_info : Dict [str , Any ], indent : Optional [int ]) -> str :
345+ def format_json (rows : Rows , query_info : dict [str , Any ], indent : Optional [int ]) -> str :
345346 headers , * _data = rows
346- data : List [Any ] = _data
347- items : List [ Dict [str , Any ]] = []
347+ data : list [Any ] = _data
348+ items : list [ dict [str , Any ]] = []
348349
349350 for d in data :
350- item : Dict [str , Any ] = {}
351+ item : dict [str , Any ] = {}
351352 for i in range (len (headers )):
352353 if d [i ].isdigit ():
353354 d [i ] = int (d [i ])
0 commit comments