1111import tarfile
1212import tempfile
1313import textwrap
14- import typing
14+ from collections . abc import Iterable , Iterator , Mapping , Sequence
1515from datetime import datetime , timezone
1616
1717import click
3333
3434def download_tzdb_tarballs (
3535 version : str , base_url : str = SOURCE , working_dir : pathlib .Path = WORKING_DIR
36- ) -> typing . List [pathlib .Path ]:
36+ ) -> Sequence [pathlib .Path ]:
3737 """Download the tzdata and tzcode tarballs."""
3838 tzdata_file = f"tzdata{ version } .tar.gz"
3939 tzcode_file = f"tzcode{ version } .tar.gz"
@@ -63,7 +63,7 @@ def download_tzdb_tarballs(
6363
6464def retrieve_local_tarballs (
6565 version : str , source_dir : pathlib .Path , working_dir : pathlib .Path = WORKING_DIR
66- ) -> typing . List [pathlib .Path ]:
66+ ) -> Sequence [pathlib .Path ]:
6767 """Retrieve the tzdata and tzcode tarballs from a folder.
6868
6969 This is useful when building against a local, patched version of tzdb.
@@ -92,7 +92,9 @@ def retrieve_local_tarballs(
9292 return dest_locations
9393
9494
95- def unpack_tzdb_tarballs (download_locations : typing .List [pathlib .Path ]) -> pathlib .Path :
95+ def unpack_tzdb_tarballs (
96+ download_locations : Sequence [pathlib .Path ],
97+ ) -> pathlib .Path :
9698 assert len (download_locations ) == 2
9799 assert download_locations [0 ].parent == download_locations [1 ].parent
98100 base_dir = download_locations [0 ].parent .parent
@@ -117,7 +119,7 @@ def unpack_tzdb_tarballs(download_locations: typing.List[pathlib.Path]) -> pathl
117119
118120def load_zonefiles (
119121 base_dir : pathlib .Path ,
120- ) -> typing . Tuple [ typing . List [str ], pathlib .Path ]:
122+ ) -> tuple [ Sequence [str ], pathlib .Path ]:
121123 target_dir = base_dir .parent / "zoneinfo"
122124 if target_dir .exists ():
123125 shutil .rmtree (target_dir )
@@ -144,9 +146,7 @@ def load_zonefiles(
144146 return zonenames , target_dir
145147
146148
147- def create_package (
148- version : str , zonenames : typing .List [str ], zoneinfo_dir : pathlib .Path
149- ):
149+ def create_package (version : str , zonenames : Sequence [str ], zoneinfo_dir : pathlib .Path ):
150150 """Creates the tzdata package."""
151151 # Start out at rc0
152152 base_version = parver .Version .parse (translate_version (version ))
@@ -249,7 +249,7 @@ def translate_version(iana_version: str) -> str:
249249class NewsEntry :
250250 version : str
251251 release_date : datetime
252- categories : typing . Mapping [str , str ]
252+ categories : Mapping [str , str ]
253253
254254 def to_file (self ) -> None :
255255 fpath = pathlib .Path ("news.d" ) / (self .version + ".md" )
@@ -286,8 +286,8 @@ def get_indent(s: str) -> int:
286286
287287
288288def read_block (
289- lines : typing . Iterator [str ],
290- ) -> typing . Tuple [ typing . Sequence [str ], typing . Iterator [str ]]:
289+ lines : Iterator [str ],
290+ ) -> tuple [ Sequence [str ], Iterator [str ]]:
291291 lines , peek = itertools .tee (lines )
292292 while not (first_line := next (peek )):
293293 next (lines )
@@ -322,7 +322,7 @@ def read_block(
322322 return block , lines
323323
324324
325- def parse_categories (news_block : typing . Sequence [str ]) -> typing . Mapping [str , str ]:
325+ def parse_categories (news_block : Sequence [str ]) -> Mapping [str , str ]:
326326 blocks = iter (news_block )
327327
328328 output = {}
@@ -341,7 +341,7 @@ def parse_categories(news_block: typing.Sequence[str]) -> typing.Mapping[str, st
341341
342342 # Merge the contents into paragraphs by grouping into consecutive blocks
343343 # of non-empty lines, then joining those lines on a newline.
344- content_paragraphs : typing . Iterable [str ] = (
344+ content_paragraphs : Iterable [str ] = (
345345 "\n " .join (paragraph )
346346 for _ , paragraph in itertools .groupby (content_lines , key = bool )
347347 )
@@ -365,7 +365,7 @@ def parse_categories(news_block: typing.Sequence[str]) -> typing.Mapping[str, st
365365 return output
366366
367367
368- def read_news (tzdb_loc : pathlib .Path , version : str = None ) -> NewsEntry :
368+ def read_news (tzdb_loc : pathlib .Path , version : str | None = None ) -> NewsEntry :
369369 release_re = re .compile ("^Release (?P<version>\d{4}[a-z]) - (?P<date>.*$)" )
370370 with open (tzdb_loc / "NEWS" , "rt" ) as f :
371371 f_lines = map (str .rstrip , f )
@@ -427,9 +427,9 @@ def update_news(news_entry: NewsEntry):
427427 help = "Flag to disable data updates and only update the news entry" ,
428428)
429429def main (
430- version : typing . Optional [ str ] ,
430+ version : str | None ,
431431 news_only : bool ,
432- source_dir : typing . Optional [ pathlib .Path ] ,
432+ source_dir : pathlib .Path | None ,
433433):
434434 logging .basicConfig (level = logging .INFO )
435435
0 commit comments