summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2024-12-17 11:48:43 -0800
committerDylan Baker <dylan@pnwbakers.com>2025-01-31 07:49:26 -0800
commit42c4f746321b19c8295d153ca281b9b5249e5fb4 (patch)
tree28f24ddc6144a4024f32863402c5e8f631cee055
parentc616f1ed50ffcd8f513d888c2dace105476a9168 (diff)
downloadmeson-42c4f746321b19c8295d153ca281b9b5249e5fb4.tar.gz
utils: Fix nullability of PerMachine from default_missing
A Defaultable PerMachine has a type of `None | T`, in other words, they have a base type of `PerMachine[None | T]`, but the purpose of `PerMachine.default_missing()` is to get a `PerMachine[T]` from that `PerMachine[None | T]`, therefore we should ensure that and annotate that.
-rw-r--r--mesonbuild/utils/universal.py20
1 files changed, 8 insertions, 12 deletions
diff --git a/mesonbuild/utils/universal.py b/mesonbuild/utils/universal.py
index edc7e3a24..c5ed23bd2 100644
--- a/mesonbuild/utils/universal.py
+++ b/mesonbuild/utils/universal.py
@@ -576,16 +576,14 @@ class PerMachineDefaultable(PerMachine[T.Optional[_T]]):
def __init__(self, build: T.Optional[_T] = None, host: T.Optional[_T] = None) -> None:
super().__init__(build, host)
- def default_missing(self) -> "PerMachine[_T]":
+ def default_missing(self) -> PerMachine[_T]:
"""Default host to build
This allows just specifying nothing in the native case, and just host in the
cross non-compiler case.
"""
- freeze = PerMachine(self.build, self.host)
- if freeze.host is None:
- freeze.host = freeze.build
- return freeze
+ assert self.build is not None, 'Cannot fill in missing when all fields are empty'
+ return PerMachine(self.build, self.host if self.host is not None else self.build)
def __repr__(self) -> str:
return f'PerMachineDefaultable({self.build!r}, {self.host!r})'
@@ -611,19 +609,17 @@ class PerThreeMachineDefaultable(PerMachineDefaultable[T.Optional[_T]], PerThree
def __init__(self) -> None:
PerThreeMachine.__init__(self, None, None, None)
- def default_missing(self) -> "PerThreeMachine[T.Optional[_T]]":
+ def default_missing(self) -> PerThreeMachine[_T]:
"""Default host to build and target to host.
This allows just specifying nothing in the native case, just host in the
cross non-compiler case, and just target in the native-built
cross-compiler case.
"""
- freeze = PerThreeMachine(self.build, self.host, self.target)
- if freeze.host is None:
- freeze.host = freeze.build
- if freeze.target is None:
- freeze.target = freeze.host
- return freeze
+ assert self.build is not None, 'Cannot default a PerMachine when all values are None'
+ host = self.host if self.host is not None else self.build
+ target = self.target if self.target is not None else host
+ return PerThreeMachine(self.build, host, target)
def __repr__(self) -> str:
return f'PerThreeMachineDefaultable({self.build!r}, {self.host!r}, {self.target!r})'