20
20
import logging
21
21
import os
22
22
from pathlib import Path
23
- from typing import Any , Dict , List , Optional
23
+ from typing import Any
24
24
25
25
from elftools .elf .elffile import ELFFile
26
26
@@ -76,7 +76,7 @@ def readlink(path: str, root: str, prefixed: bool = False) -> str:
76
76
77
77
def dedupe (items : list [str ]) -> list [str ]:
78
78
"""Remove all duplicates from ``items`` (keeping order)"""
79
- seen = {} # type: Dict [str, str]
79
+ seen : dict [str , str ] = {}
80
80
return [seen .setdefault (x , x ) for x in items if x not in seen ]
81
81
82
82
@@ -101,7 +101,7 @@ def parse_ld_paths(str_ldpaths: str, path: str, root: str = "") -> list[str]:
101
101
-------
102
102
list of processed paths
103
103
"""
104
- ldpaths = [] # type: List[str ]
104
+ ldpaths : list [ str ] = [ ]
105
105
for ldpath in str_ldpaths .split (":" ):
106
106
if ldpath == "" :
107
107
# The ldso treats "" paths as $PWD.
@@ -133,7 +133,7 @@ def parse_ld_so_conf(ldso_conf: str, root: str = "/", _first: bool = True) -> li
133
133
-------
134
134
list of paths found
135
135
"""
136
- paths = [] # type: List[str ]
136
+ paths : list [ str ] = [ ]
137
137
138
138
dbg_pfx = "" if _first else " "
139
139
try :
@@ -183,7 +183,7 @@ def load_ld_paths(root: str = "/", prefix: str = "") -> dict[str, list[str]]:
183
183
-------
184
184
dict containing library paths to search
185
185
"""
186
- ldpaths = {"conf" : [], "env" : [], "interp" : []} # type: Dict
186
+ ldpaths : dict = {"conf" : [], "env" : [], "interp" : []}
187
187
188
188
# Load up $LD_LIBRARY_PATH.
189
189
env_ldpath = os .environ .get ("LD_LIBRARY_PATH" )
@@ -271,7 +271,7 @@ def find_lib(
271
271
The elf which the library should be compatible with (ELF wise)
272
272
lib : str
273
273
The library (basename) to search for
274
- ldpaths : List [str]
274
+ ldpaths : list [str]
275
275
A list of paths to search
276
276
root : str
277
277
The root path to resolve symlinks
@@ -349,15 +349,15 @@ def lddtree(
349
349
if _first :
350
350
_all_libs = {}
351
351
352
- ret = {
352
+ ret : dict [ str , Any ] = {
353
353
"interp" : None ,
354
354
"path" : path if display is None else display ,
355
355
"realpath" : path ,
356
356
"needed" : [],
357
357
"rpath" : [],
358
358
"runpath" : [],
359
359
"libs" : _all_libs ,
360
- } # type: Dict[str, Any]
360
+ }
361
361
362
362
log .debug ("lddtree(%s)" % path )
363
363
@@ -389,9 +389,9 @@ def lddtree(
389
389
break
390
390
391
391
# Parse the ELF's dynamic tags.
392
- libs = [] # type: List[str ]
393
- rpaths = [] # type: List[str ]
394
- runpaths = [] # type: List[str ]
392
+ libs : list [ str ] = [ ]
393
+ rpaths : list [ str ] = [ ]
394
+ runpaths : list [ str ] = [ ]
395
395
for segment in elf .iter_segments ():
396
396
if segment .header .p_type != "PT_DYNAMIC" :
397
397
continue
@@ -422,7 +422,7 @@ def lddtree(
422
422
ret ["needed" ] = libs
423
423
424
424
# Search for the libs this ELF uses.
425
- all_ldpaths = None # type: Optional[List[ str]]
425
+ all_ldpaths : list [ str ] | None = None
426
426
for lib in libs :
427
427
if lib in _all_libs :
428
428
continue
0 commit comments