99from collections import defaultdict
1010from contextlib import ExitStack , contextmanager
1111from json import JSONEncoder
12- from typing import Iterable , List , Optional , Protocol , TextIO
12+ from typing import Any , DefaultDict , Iterable , List , Optional , Protocol , TextIO
1313
1414from extract_utils .bp_builder import BpBuilder , FileBpBuilder
1515from extract_utils .bp_encoder import BpJSONEncoder
@@ -98,8 +98,8 @@ def __call__(
9898 self ,
9999 file : File ,
100100 builder : FileBpBuilder ,
101- * args ,
102- ** kwargs ,
101+ * args : Any ,
102+ ** kwargs : Any ,
103103 ) -> str : ...
104104
105105
@@ -108,8 +108,8 @@ def __call__(
108108 self ,
109109 files : List [File ],
110110 builder : FileBpBuilder ,
111- * args ,
112- ** kwargs ,
111+ * args : Any ,
112+ ** kwargs : Any ,
113113 ) -> str : ...
114114
115115
@@ -133,8 +133,8 @@ def file_gen_deps_check_elf(global_check_elf: bool, file: File):
133133
134134def file_stem_package_name (
135135 file : File ,
136- can_have_stem = False ,
137- any_extension = False ,
136+ can_have_stem : bool = False ,
137+ any_extension : bool = False ,
138138):
139139 package_name = file .root
140140 stem = None
@@ -165,7 +165,11 @@ def file_subtree_rel_path(file: File, subtree_prefix_len: int) -> Optional[str]:
165165 return remaining
166166
167167
168- def write_sh_package (file : File , builder : FileBpBuilder , any_extension = False ):
168+ def write_sh_package (
169+ file : File ,
170+ builder : FileBpBuilder ,
171+ any_extension : bool = False ,
172+ ):
169173 stem , package_name = file_stem_package_name (
170174 file ,
171175 any_extension = any_extension ,
@@ -190,15 +194,15 @@ def write_elfs_package(
190194 files : List [File ],
191195 builder : FileBpBuilder ,
192196 ctx : ProductPackagesCtx ,
193- is_bin = False ,
197+ is_bin : bool = False ,
194198):
195199 file = files [0 ]
196200
197201 gen_deps , enable_check_elf = file_gen_deps_check_elf (ctx .check_elf , file )
198202
199- machines = []
200- bitses = []
201- depses = []
203+ machines : List [ EM ] = []
204+ bitses : List [ int ] = []
205+ depses : List [ Optional [ List [ str ]]] = []
202206
203207 for f in files :
204208 f_path = f'{ ctx .vendor_prop_path } /{ f .dst } '
@@ -207,6 +211,9 @@ def write_elfs_package(
207211 if is_bin and (machine is None or bits is None ):
208212 return write_sh_package (files [0 ], builder , any_extension = True )
209213
214+ assert machine is not None
215+ assert bits is not None
216+
210217 if machine == EM .QDSP6 :
211218 libs = None
212219 enable_check_elf = False
@@ -219,7 +226,9 @@ def write_elfs_package(
219226 depses .append (deps )
220227
221228 stem , package_name = file_stem_package_name (
222- file , can_have_stem = True , any_extension = is_bin
229+ file ,
230+ can_have_stem = True ,
231+ any_extension = is_bin ,
223232 )
224233
225234 if is_bin :
@@ -408,8 +417,8 @@ def write_common_packages_group(
408417 package_names : List [str ],
409418 out : TextIO ,
410419 encoder : JSONEncoder ,
411- * args ,
412- ** kwargs ,
420+ * args : Any ,
421+ ** kwargs : Any ,
413422):
414423 for files in file_tree .common_files_iter ():
415424 builder = create_builder (ctx , file_tree , files [0 ], encoder )
@@ -425,8 +434,8 @@ def write_packages_group(
425434 package_names : List [str ],
426435 out : TextIO ,
427436 encoder : JSONEncoder ,
428- * args ,
429- ** kwargs ,
437+ * args : Any ,
438+ ** kwargs : Any ,
430439):
431440 for file in file_tree :
432441 builder = create_builder (ctx , file_tree , file , encoder )
@@ -475,7 +484,12 @@ def write_product_packages(
475484 encoder = BpJSONEncoder (legacy = ctx .legacy )
476485 package_names : List [str ] = []
477486
478- def w (fn : write_package_fn , file_tree : FileTree , * args , ** kwargs ):
487+ def w (
488+ fn : write_package_fn ,
489+ file_tree : FileTree ,
490+ * args : Any ,
491+ ** kwargs : Any ,
492+ ):
479493 return write_packages_group (
480494 packages_ctx ,
481495 file_tree ,
@@ -487,7 +501,13 @@ def w(fn: write_package_fn, file_tree: FileTree, *args, **kwargs):
487501 ** kwargs ,
488502 )
489503
490- def wp (fn : write_package_fn , partition : str , sub_dir : str , * args , ** kwargs ):
504+ def wp (
505+ fn : write_package_fn ,
506+ partition : str ,
507+ sub_dir : str ,
508+ * args : Any ,
509+ ** kwargs : Any ,
510+ ):
491511 file_tree = base_file_tree .filter_prefixed ([partition , sub_dir ])
492512
493513 return w (fn , file_tree , * args , ** kwargs )
@@ -617,7 +637,7 @@ def write_dummy_shared_libs_packages(
617637 file = files [0 ]
618638 stem , package_name = file_stem_package_name (file , can_have_stem = True )
619639
620- bitses = []
640+ bitses : List [ int ] = []
621641 for f in files :
622642 dst_dir = f .parts [1 ]
623643 if dst_dir == 'lib' :
@@ -645,7 +665,12 @@ def write_dummy_shared_libs(
645665 encoder = BpJSONEncoder (legacy = ctx .legacy )
646666 package_names : List [str ] = []
647667
648- def w (fn : write_package_fn , file_tree : FileTree , * args , ** kwargs ):
668+ def w (
669+ fn : write_package_fn ,
670+ file_tree : FileTree ,
671+ * args : Any ,
672+ ** kwargs : Any ,
673+ ):
649674 return write_packages_group (
650675 packages_ctx ,
651676 file_tree ,
@@ -706,7 +731,7 @@ def write_filegroups(
706731 files : Iterable [File ],
707732):
708733 encoder = BpJSONEncoder (legacy = ctx .legacy )
709- filegroup_to_files = defaultdict (list )
734+ filegroup_to_files : DefaultDict [ str , List [ File ]] = defaultdict (list )
710735
711736 for file in files :
712737 filegroups = file .filegroups
@@ -917,7 +942,12 @@ def write_rro_package(
917942 write_packages_inclusion ([package_name ], ctx .product_mk_out )
918943
919944
920- def write_mk_guard_begin (name : str , value : str , mk_out : TextIO , invert = False ):
945+ def write_mk_guard_begin (
946+ name : str ,
947+ value : str ,
948+ mk_out : TextIO ,
949+ invert : bool = False ,
950+ ):
921951 rule = 'ifeq' if not invert else 'ifneq'
922952 mk_out .write (f'\n { rule } ($({ name } ),{ value } )\n ' )
923953
0 commit comments