1+ from __future__ import annotations
2+
13import glob
24import hashlib
35import json
810import uuid
911import zipfile
1012from datetime import datetime
11- from typing import Any , Callable , Generator , Iterable , List , Optional , Tuple , Union
13+ from typing import Any , Callable , Generator , Iterable , Union
1214from urllib .parse import urlsplit
1315
1416try :
@@ -236,7 +238,7 @@ def convert_size_bytes_to_string(size: int) -> str:
236238 return size_str
237239
238240
239- def convert_size_string_to_bytes (size : str ) -> Union [ float , int ] :
241+ def convert_size_string_to_bytes (size : str ) -> float | int :
240242 """
241243 Convert the given size string to bytes.
242244 """
@@ -330,7 +332,7 @@ def create_file(path: PathIn, content: str = "", *, overwrite: bool = False) ->
330332
331333def create_zip_file (
332334 path : PathIn ,
333- content_paths : List [PathIn ],
335+ content_paths : list [PathIn ],
334336 * ,
335337 overwrite : bool = True ,
336338 compression : int = zipfile .ZIP_DEFLATED ,
@@ -407,8 +409,8 @@ def delete_files(*paths: PathIn) -> None:
407409def download_file (
408410 url : str ,
409411 * ,
410- dirpath : Optional [ PathIn ] = None ,
411- filename : Optional [ str ] = None ,
412+ dirpath : PathIn | None = None ,
413+ filename : str | None = None ,
412414 chunk_size : int = 8192 ,
413415 ** kwargs : Any ,
414416) -> str :
@@ -448,7 +450,7 @@ def extract_zip_file(
448450 dest : PathIn ,
449451 * ,
450452 autodelete : bool = False ,
451- content_paths : Optional [ Iterable [Union [ str , zipfile .ZipInfo ]]] = None ,
453+ content_paths : Iterable [str | zipfile .ZipInfo ] | None = None ,
452454) -> None :
453455 """
454456 Extract zip file at path to dest path.
@@ -468,10 +470,10 @@ def extract_zip_file(
468470
469471def _filter_paths (
470472 basepath : str ,
471- relpaths : List [str ],
473+ relpaths : list [str ],
472474 * ,
473- predicate : Optional [ Callable [[str ], bool ]] = None ,
474- ) -> List [str ]:
475+ predicate : Callable [[str ], bool ] | None = None ,
476+ ) -> list [str ]:
475477 """
476478 Filter paths relative to basepath according to the optional predicate function.
477479 If predicate is defined, paths are filtered using it, otherwise all paths will be listed.
@@ -803,15 +805,15 @@ def join_path(path: PathIn, *paths: PathIn) -> str:
803805 return os .path .normpath (os .path .join (basepath , * paths_str ))
804806
805807
806- def list_dirs (path : PathIn ) -> List [str ]:
808+ def list_dirs (path : PathIn ) -> list [str ]:
807809 """
808810 List all directories contained at the given directory path.
809811 """
810812 path = _get_path (path )
811813 return _filter_paths (path , os .listdir (path ), predicate = is_dir )
812814
813815
814- def list_files (path : PathIn ) -> List [str ]:
816+ def list_files (path : PathIn ) -> list [str ]:
815817 """
816818 List all files contained at the given directory path.
817819 """
@@ -953,7 +955,7 @@ def read_file_lines(
953955 strip_white : bool = True ,
954956 skip_empty : bool = True ,
955957 encoding : str = "utf-8" ,
956- ) -> List [str ]:
958+ ) -> list [str ]:
957959 """
958960 Read file content lines.
959961 It is possible to specify the line indexes (negative indexes too),
@@ -1164,7 +1166,7 @@ def replace_file(path: PathIn, src: PathIn, *, autodelete: bool = False) -> None
11641166 remove_file (path = src )
11651167
11661168
1167- def _search_paths (path : PathIn , pattern : str ) -> List [str ]:
1169+ def _search_paths (path : PathIn , pattern : str ) -> list [str ]:
11681170 """
11691171 Search all paths relative to path matching the given pattern.
11701172 """
@@ -1175,23 +1177,23 @@ def _search_paths(path: PathIn, pattern: str) -> List[str]:
11751177 return paths
11761178
11771179
1178- def search_dirs (path : PathIn , pattern : str = "**/*" ) -> List [str ]:
1180+ def search_dirs (path : PathIn , pattern : str = "**/*" ) -> list [str ]:
11791181 """
11801182 Search for directories at path matching the given pattern.
11811183 """
11821184 path = _get_path (path )
11831185 return _filter_paths (path , _search_paths (path , pattern ), predicate = is_dir )
11841186
11851187
1186- def search_files (path : PathIn , pattern : str = "**/*.*" ) -> List [str ]:
1188+ def search_files (path : PathIn , pattern : str = "**/*.*" ) -> list [str ]:
11871189 """
11881190 Search for files at path matching the given pattern.
11891191 """
11901192 path = _get_path (path )
11911193 return _filter_paths (path , _search_paths (path , pattern ), predicate = is_file )
11921194
11931195
1194- def split_filename (path : PathIn ) -> Tuple [str , str ]:
1196+ def split_filename (path : PathIn ) -> tuple [str , str ]:
11951197 """
11961198 Split a filename and returns its basename and extension.
11971199 """
@@ -1202,7 +1204,7 @@ def split_filename(path: PathIn) -> Tuple[str, str]:
12021204 return (basename , extension )
12031205
12041206
1205- def split_filepath (path : PathIn ) -> Tuple [str , str ]:
1207+ def split_filepath (path : PathIn ) -> tuple [str , str ]:
12061208 """
12071209 Split a filepath and returns its directory-path and filename.
12081210 """
@@ -1212,7 +1214,7 @@ def split_filepath(path: PathIn) -> Tuple[str, str]:
12121214 return (dirpath , filename )
12131215
12141216
1215- def split_path (path : PathIn ) -> List [str ]:
1217+ def split_path (path : PathIn ) -> list [str ]:
12161218 """
12171219 Split a path and returns its path-names.
12181220 """
0 commit comments