From 86203a4b86029230044def90e85856ff1907bc66 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 29 Jun 2023 13:48:34 -0600 Subject: [PATCH] Use slots for all dataclasses The minimum Python version was bumped to 3.10 so this is now safe. --- scripts/wk/cfg/__init__.py | 1 - scripts/wk/cfg/python.py | 14 -------------- scripts/wk/hw/disk.py | 3 +-- scripts/wk/hw/system.py | 3 +-- scripts/wk/hw/test.py | 6 ++---- 5 files changed, 4 insertions(+), 23 deletions(-) delete mode 100644 scripts/wk/cfg/python.py diff --git a/scripts/wk/cfg/__init__.py b/scripts/wk/cfg/__init__.py index 81b0cdd4..d79a6eb6 100644 --- a/scripts/wk/cfg/__init__.py +++ b/scripts/wk/cfg/__init__.py @@ -7,7 +7,6 @@ from . import log from . import main from . import music from . import net -from . import python from . import repairs from . import setup from . import sources diff --git a/scripts/wk/cfg/python.py b/scripts/wk/cfg/python.py deleted file mode 100644 index c02e51b6..00000000 --- a/scripts/wk/cfg/python.py +++ /dev/null @@ -1,14 +0,0 @@ -"""WizardKit: Config - Python""" -# vim: sts=2 sw=2 ts=2 - -from sys import version_info - -DATACLASS_DECORATOR_KWARGS = {} -if version_info.major >= 3 and version_info.minor >= 10: - DATACLASS_DECORATOR_KWARGS['slots'] = True - - -if __name__ == '__main__': - print("This file is not meant to be called directly.") - -# vim: sts=2 sw=2 ts=2 diff --git a/scripts/wk/hw/disk.py b/scripts/wk/hw/disk.py index 4530132f..5c50f476 100644 --- a/scripts/wk/hw/disk.py +++ b/scripts/wk/hw/disk.py @@ -12,7 +12,6 @@ from dataclasses import dataclass, field from typing import Any from wk.cfg.main import KIT_NAME_SHORT -from wk.cfg.python import DATACLASS_DECORATOR_KWARGS from wk.exe import get_json_from_command, run_program from wk.hw.test import Test from wk.hw.smart import ( @@ -32,7 +31,7 @@ WK_LABEL_REGEX = re.compile( # Classes -@dataclass(**DATACLASS_DECORATOR_KWARGS) +@dataclass(slots=True) class Disk: """Object for tracking disk specific data.""" attributes: dict[Any, dict] = field(init=False, default_factory=dict) diff --git a/scripts/wk/hw/system.py b/scripts/wk/hw/system.py index 4309c3df..48d6a433 100644 --- a/scripts/wk/hw/system.py +++ b/scripts/wk/hw/system.py @@ -9,7 +9,6 @@ from dataclasses import dataclass, field from typing import Any from wk.cfg.hw import KNOWN_RAM_VENDOR_IDS -from wk.cfg.python import DATACLASS_DECORATOR_KWARGS from wk.exe import get_json_from_command, run_program from wk.hw.test import Test from wk.std import PLATFORM, bytes_to_string, string_to_bytes @@ -20,7 +19,7 @@ from wk.ui import ansi LOG = logging.getLogger(__name__) -@dataclass(**DATACLASS_DECORATOR_KWARGS) +@dataclass(slots=True) class System: """Object for tracking system specific hardware data.""" cpu_description: str = field(init=False) diff --git a/scripts/wk/hw/test.py b/scripts/wk/hw/test.py index 628ada11..78d948f3 100644 --- a/scripts/wk/hw/test.py +++ b/scripts/wk/hw/test.py @@ -4,9 +4,7 @@ from dataclasses import dataclass, field from typing import Any, Callable -from wk.cfg.python import DATACLASS_DECORATOR_KWARGS - -@dataclass(**DATACLASS_DECORATOR_KWARGS) +@dataclass(slots=True) class Test: """Object for tracking test specific data.""" dev: Any @@ -28,7 +26,7 @@ class Test: self.status = status -@dataclass(**DATACLASS_DECORATOR_KWARGS) +@dataclass(slots=True) class TestGroup: """Object for tracking groups of tests.""" name: str