Commit e6f61920 authored by Daniel Latypov's avatar Daniel Latypov Committed by Shuah Khan

kunit: tool: drop last uses of collections.namedtuple

Since we formally require python3.7+ since commit df4b0807
("kunit: tool: Assert the version requirement"), we can just use
@dataclasses.dataclass instead.

In kunit_config.py, we used namedtuple to create a hashable type that
had `name` and `value` fields and had to subclass it to define a custom
`__str__()`.
@datalcass lets us just define one type instead.

In qemu_config.py, we use namedtuple to allow modules to define various
parameters. Using @dataclass, we can add type-annotations for all these
fields, making our code more typesafe and making it easier for users to
figure out how to define new configs.
Signed-off-by: default avatarDaniel Latypov <dlatypov@google.com>
Reviewed-by: default avatarDavid Gow <davidgow@google.com>
Reviewed-by: default avatarBrendan Higgins <brendanhiggins@google.com>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent 89aa72cd
...@@ -6,16 +6,17 @@ ...@@ -6,16 +6,17 @@
# Author: Felix Guo <felixguoxiuping@gmail.com> # Author: Felix Guo <felixguoxiuping@gmail.com>
# Author: Brendan Higgins <brendanhiggins@google.com> # Author: Brendan Higgins <brendanhiggins@google.com>
import collections from dataclasses import dataclass
import re import re
from typing import List, Set from typing import List, Set
CONFIG_IS_NOT_SET_PATTERN = r'^# CONFIG_(\w+) is not set$' CONFIG_IS_NOT_SET_PATTERN = r'^# CONFIG_(\w+) is not set$'
CONFIG_PATTERN = r'^CONFIG_(\w+)=(\S+|".*")$' CONFIG_PATTERN = r'^CONFIG_(\w+)=(\S+|".*")$'
KconfigEntryBase = collections.namedtuple('KconfigEntryBase', ['name', 'value']) @dataclass(frozen=True)
class KconfigEntry:
class KconfigEntry(KconfigEntryBase): name: str
value: str
def __str__(self) -> str: def __str__(self) -> str:
if self.value == 'n': if self.value == 'n':
......
...@@ -5,12 +5,15 @@ ...@@ -5,12 +5,15 @@
# Copyright (C) 2021, Google LLC. # Copyright (C) 2021, Google LLC.
# Author: Brendan Higgins <brendanhiggins@google.com> # Author: Brendan Higgins <brendanhiggins@google.com>
from collections import namedtuple from dataclasses import dataclass
from typing import List
QemuArchParams = namedtuple('QemuArchParams', ['linux_arch', @dataclass(frozen=True)
'kconfig', class QemuArchParams:
'qemu_arch', linux_arch: str
'kernel_path', kconfig: str
'kernel_command_line', qemu_arch: str
'extra_qemu_params']) kernel_path: str
kernel_command_line: str
extra_qemu_params: List[str]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment