aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/envconfig.py
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2021-12-04 21:11:51 -0500
committerEli Schwartz <eschwartz@archlinux.org>2022-01-10 18:36:57 -0500
commit4b351aef26a19b4c73f6ef295f64da1c74bc713d (patch)
tree44f0b5c34c6bfb06360ffc22870ff423fc9305e2 /mesonbuild/envconfig.py
parent98a41ec24e77d7670ea83fd986853d0fe7cb2f5b (diff)
downloadmeson-4b351aef26a19b4c73f6ef295f64da1c74bc713d.zip
meson-4b351aef26a19b4c73f6ef295f64da1c74bc713d.tar.gz
meson-4b351aef26a19b4c73f6ef295f64da1c74bc713d.tar.bz2
first pass at migrating to dataclasses
In some cases, init variables that accept None as a sentinel and immediately overwrite with [], are migrated to dataclass field factories. \o/ Note: dataclasses by default cannot provide eq methods, as they then become unhashable. In the future we may wish to opt into declaring them frozen, instead/additionally.
Diffstat (limited to 'mesonbuild/envconfig.py')
-rw-r--r--mesonbuild/envconfig.py27
1 files changed, 8 insertions, 19 deletions
diff --git a/mesonbuild/envconfig.py b/mesonbuild/envconfig.py
index 3a2923b..1b5f728 100644
--- a/mesonbuild/envconfig.py
+++ b/mesonbuild/envconfig.py
@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from dataclasses import dataclass
import subprocess
import typing as T
from enum import Enum
@@ -234,27 +235,15 @@ class Properties:
def get(self, key: str, default: T.Optional[T.Union[str, bool, int, T.List[str]]] = None) -> T.Optional[T.Union[str, bool, int, T.List[str]]]:
return self.properties.get(key, default)
+@dataclass(unsafe_hash=True)
class MachineInfo(HoldableObject):
- def __init__(self, system: str, cpu_family: str, cpu: str, endian: str):
- self.system = system
- self.cpu_family = cpu_family
- self.cpu = cpu
- self.endian = endian
- self.is_64_bit = cpu_family in CPU_FAMILIES_64_BIT # type: bool
+ system: str
+ cpu_family: str
+ cpu: str
+ endian: str
- def __eq__(self, other: object) -> bool:
- if not isinstance(other, MachineInfo):
- return NotImplemented
- return \
- self.system == other.system and \
- self.cpu_family == other.cpu_family and \
- self.cpu == other.cpu and \
- self.endian == other.endian
-
- def __ne__(self, other: object) -> bool:
- if not isinstance(other, MachineInfo):
- return NotImplemented
- return not self.__eq__(other)
+ def __post_init__(self) -> None:
+ self.is_64_bit: bool = self.cpu_family in CPU_FAMILIES_64_BIT
def __repr__(self) -> str:
return f'<MachineInfo: {self.system} {self.cpu_family} ({self.cpu})>'