aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2023-03-12 23:14:01 -0400
committerEli Schwartz <eschwartz@archlinux.org>2023-08-10 13:56:39 -0400
commit169cd7e61934a9c852d109d65226b10b332283a0 (patch)
tree317101487436b8f5b41a41c3705974b0420aa003
parent277151450a8eaf48f7038b21fdbf39b85f339e8b (diff)
downloadmeson-169cd7e61934a9c852d109d65226b10b332283a0.zip
meson-169cd7e61934a9c852d109d65226b10b332283a0.tar.gz
meson-169cd7e61934a9c852d109d65226b10b332283a0.tar.bz2
python module: add a few more type annotations
-rw-r--r--mesonbuild/modules/python.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py
index 470f7b3..d0067db 100644
--- a/mesonbuild/modules/python.py
+++ b/mesonbuild/modules/python.py
@@ -62,6 +62,8 @@ if T.TYPE_CHECKING:
subdir: NotRequired[T.Optional[str]]
+ MaybePythonProg = T.Union[NonExistingExternalProgram, 'PythonExternalProgram']
+
mod_kwargs = {'subdir'}
mod_kwargs.update(known_shmod_kwargs)
@@ -84,12 +86,12 @@ class PythonExternalProgram(BasicPythonExternalProgram):
self.purelib = self._get_path(state, 'purelib')
return ret
- def _get_path(self, state: T.Optional['ModuleState'], key: str) -> None:
+ def _get_path(self, state: T.Optional['ModuleState'], key: str) -> str:
rel_path = self.info['install_paths'][key][1:]
if not state:
# This happens only from run_project_tests.py
return rel_path
- value = state.get_option(f'{key}dir', module='python')
+ value = T.cast('str', state.get_option(f'{key}dir', module='python'))
if value:
if state.is_user_defined_option('install_env', module='python'):
raise mesonlib.MesonException(f'python.{key}dir and python.install_env are mutually exclusive')
@@ -303,7 +305,7 @@ class PythonModule(ExtensionModule):
def __init__(self, interpreter: 'Interpreter') -> None:
super().__init__(interpreter)
- self.installations: T.Dict[str, ExternalProgram] = {}
+ self.installations: T.Dict[str, MaybePythonProg] = {}
self.methods.update({
'find_installation': self.find_installation,
})
@@ -377,7 +379,7 @@ class PythonModule(ExtensionModule):
else:
return None
- def _find_installation_impl(self, state: 'ModuleState', display_name: str, name_or_path: str, required: bool) -> ExternalProgram:
+ def _find_installation_impl(self, state: 'ModuleState', display_name: str, name_or_path: str, required: bool) -> MaybePythonProg:
if not name_or_path:
python = PythonExternalProgram('python3', mesonlib.python_command)
else:
@@ -420,7 +422,7 @@ class PythonModule(ExtensionModule):
_PURE_KW.evolve(default=True, since='0.64.0'),
)
def find_installation(self, state: 'ModuleState', args: T.Tuple[T.Optional[str]],
- kwargs: 'FindInstallationKw') -> ExternalProgram:
+ kwargs: 'FindInstallationKw') -> MaybePythonProg:
feature_check = FeatureNew('Passing "feature" option to find_installation', '0.48.0')
disabled, required, feature = extract_required_kwarg(kwargs, state.subproject, feature_check)
@@ -482,6 +484,7 @@ class PythonModule(ExtensionModule):
raise mesonlib.MesonException('{} is missing modules: {}'.format(name_or_path or 'python', ', '.join(missing_modules)))
return NonExistingExternalProgram(python.name)
else:
+ assert isinstance(python, PythonExternalProgram), 'for mypy'
python = copy.copy(python)
python.pure = kwargs['pure']
python.run_bytecompile.setdefault(python.info['version'], False)