2626from ..options import OptionKey
2727from ..programs import ExternalProgram , NonExistingExternalProgram
2828
29+ _T = T .TypeVar ('_T' )
30+
2931if T .TYPE_CHECKING :
3032 from typing_extensions import TypedDict , NotRequired
3133
@@ -43,6 +45,7 @@ class PyInstallKw(TypedDict):
4345 pure : T .Optional [bool ]
4446 subdir : str
4547 install_tag : T .Optional [str ]
48+ preserve_path : bool
4649
4750 class FindInstallationKw (ExtractRequired ):
4851
@@ -118,12 +121,16 @@ def __init__(self, python: 'PythonExternalProgram', interpreter: 'Interpreter'):
118121 assert isinstance (prefix , str ), 'for mypy'
119122
120123 if python .build_config :
121- self .version = python .build_config ['language' ]['version' ]
122- self .platform = python .build_config ['platform' ]
123- self .suffix = python .build_config ['abi' ]['extension_suffix' ]
124- self .limited_api_suffix = python .build_config ['abi' ]['stable_abi_suffix' ]
125- self .link_libpython = python .build_config ['libpython' ]['link_extensions' ]
126- self .is_pypy = python .build_config ['implementation' ]['name' ] == 'pypy'
124+ def as_ (obj : object , type_ : T .Type [_T ]) -> _T :
125+ assert isinstance (obj , type_ ), 'for mypy'
126+ return obj
127+
128+ self .version = as_ (python .build_config ['language' ]['version' ], str )
129+ self .platform = as_ (python .build_config ['platform' ], str )
130+ self .suffix = as_ (python .build_config ['abi' ]['extension_suffix' ], str )
131+ self .limited_api_suffix = as_ (python .build_config ['abi' ]['stable_abi_suffix' ], str )
132+ self .link_libpython = as_ (python .build_config ['libpython' ]['link_extensions' ], bool )
133+ self .is_pypy = as_ (python .build_config ['implementation' ]['name' ], str ) == 'pypy'
127134 else :
128135 self .version = info ['version' ]
129136 self .platform = info ['platform' ]
@@ -268,6 +275,7 @@ def _dependency_method_impl(self, kwargs: DependencyObjectKWs) -> Dependency:
268275 return dep
269276
270277 build_config = self .interpreter .environment .coredata .optstore .get_value_for (OptionKey ('python.build_config' ))
278+ assert isinstance (build_config , str ), 'for mypy'
271279
272280 new_kwargs = kwargs .copy ()
273281 new_kwargs ['required' ] = False
@@ -402,7 +410,7 @@ def __init__(self, interpreter: 'Interpreter') -> None:
402410
403411 def _get_install_scripts (self ) -> T .List [mesonlib .ExecutableSerialisation ]:
404412 backend = self .interpreter .backend
405- ret = []
413+ ret : T . List [ mesonlib . ExecutableSerialisation ] = []
406414 optlevel = self .interpreter .environment .coredata .optstore .get_value_for (OptionKey ('python.bytecompile' ))
407415 if optlevel == - 1 :
408416 return ret
@@ -412,7 +420,7 @@ def _get_install_scripts(self) -> T.List[mesonlib.ExecutableSerialisation]:
412420 installdata = backend .create_install_data ()
413421 py_files = []
414422
415- def should_append (f , isdir : bool = False ):
423+ def should_append (f : str , isdir : bool = False ) -> bool :
416424 # This uses the install_plan decorated names to see if the original source was propagated via
417425 # install_sources() or get_install_dir().
418426 return f .startswith (('{py_platlib}' , '{py_purelib}' )) and (f .endswith ('.py' ) or isdir )
@@ -434,7 +442,6 @@ def should_append(f, isdir: bool = False):
434442
435443 for i in self .installations .values ():
436444 if isinstance (i , PythonExternalProgram ) and i .run_bytecompile [i .info ['version' ]]:
437- i = T .cast ('PythonExternalProgram' , i )
438445 manifest = f'python-{ i .info ["version" ]} -installed.json'
439446 manifest_json = []
440447 for name , f in py_files :
@@ -471,6 +478,7 @@ def _get_win_pythonpath(name_or_path: str) -> T.Optional[str]:
471478
472479 def _find_installation_impl (self , state : 'ModuleState' , display_name : str , name_or_path : str , required : bool ) -> MaybePythonProg :
473480 build_config = self .interpreter .environment .coredata .optstore .get_value_for (OptionKey ('python.build_config' ))
481+ assert isinstance (build_config , str ), 'for mypy'
474482
475483 if not name_or_path :
476484 python = PythonExternalProgram ('python3' , mesonlib .python_command , build_config_path = build_config )
0 commit comments