Skip to content

Commit bbd5d16

Browse files
LukaszMrugalacarlescufi
authored andcommitted
scripts: Fix twisterlib for ruff - UP007
This fixes ruff linting error UP007, where one would use Optional or Union instead of X | Y notation. Signed-off-by: Lukasz Mrugala <[email protected]>
1 parent 9b4397a commit bbd5d16

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

.ruff-excludes.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -759,9 +759,6 @@
759759
"./scripts/pylib/twister/twisterlib/cmakecache.py" = [
760760
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
761761
]
762-
"./scripts/pylib/twister/twisterlib/config_parser.py" = [
763-
"UP007", # https://docs.astral.sh/ruff/rules/non-pep604-annotation
764-
]
765762
"./scripts/pylib/twister/twisterlib/coverage.py" = [
766763
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
767764
]
@@ -770,7 +767,6 @@
770767
]
771768
"./scripts/pylib/twister/twisterlib/handlers.py" = [
772769
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
773-
"UP007", # https://docs.astral.sh/ruff/rules/non-pep604-annotation
774770
]
775771
"./scripts/pylib/twister/twisterlib/hardwaremap.py" = [
776772
"E501", # https://docs.astral.sh/ruff/rules/line-too-long

scripts/pylib/twister/twisterlib/config_parser.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55

66
import copy
77
import warnings
8-
from typing import Union
98

109
import scl
1110
from twisterlib.error import ConfigurationError
1211

1312

14-
def extract_fields_from_arg_list(target_fields: set, arg_list: Union[str, list]):
13+
def extract_fields_from_arg_list(target_fields: set, arg_list: str | list):
1514
"""
1615
Given a list of "FIELD=VALUE" args, extract values of args with a
1716
given field name and return the remaining args separately.

scripts/pylib/twister/twisterlib/handlers.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from contextlib import contextmanager
2424
from pathlib import Path
2525
from queue import Empty, Queue
26-
from typing import Optional
2726

2827
import psutil
2928
from twisterlib.environment import ZEPHYR_BASE, strip_ansi_sequences
@@ -71,7 +70,7 @@ def terminate_process(proc):
7170

7271
class Handler:
7372
def __init__(self, instance, type_str: str, options: argparse.Namespace,
74-
generator_cmd: Optional[str] = None, suite_name_check: bool = True):
73+
generator_cmd: str | None = None, suite_name_check: bool = True):
7574
"""Constructor
7675
7776
"""
@@ -175,7 +174,7 @@ def get_default_domain_build_dir(self):
175174

176175

177176
class BinaryHandler(Handler):
178-
def __init__(self, instance, type_str: str, options: argparse.Namespace, generator_cmd: Optional[str] = None,
177+
def __init__(self, instance, type_str: str, options: argparse.Namespace, generator_cmd: str | None = None,
179178
suite_name_check: bool = True):
180179
"""Constructor
181180
@@ -186,7 +185,7 @@ def __init__(self, instance, type_str: str, options: argparse.Namespace, generat
186185
self.seed = None
187186
self.extra_test_args = None
188187
self.line = b""
189-
self.binary: Optional[str] = None
188+
self.binary: str | None = None
190189

191190
def try_kill_process_by_pid(self):
192191
if self.pid_fn:
@@ -374,7 +373,7 @@ def handle(self, harness):
374373

375374

376375
class SimulationHandler(BinaryHandler):
377-
def __init__(self, instance, type_str: str, options: argparse.Namespace, generator_cmd: Optional[str] = None,
376+
def __init__(self, instance, type_str: str, options: argparse.Namespace, generator_cmd: str | None = None,
378377
suite_name_check: bool = True):
379378
"""Constructor
380379
@@ -827,7 +826,7 @@ class QEMUHandler(Handler):
827826
for these to collect whether the test passed or failed.
828827
"""
829828

830-
def __init__(self, instance, type_str: str, options: argparse.Namespace, generator_cmd: Optional[str] = None,
829+
def __init__(self, instance, type_str: str, options: argparse.Namespace, generator_cmd: str | None = None,
831830
suite_name_check: bool = True):
832831
"""Constructor
833832
@@ -1117,7 +1116,7 @@ class QEMUWinHandler(Handler):
11171116
for these to collect whether the test passed or failed.
11181117
"""
11191118

1120-
def __init__(self, instance, type_str: str, options: argparse.Namespace, generator_cmd: Optional[str] = None,
1119+
def __init__(self, instance, type_str: str, options: argparse.Namespace, generator_cmd: str | None = None,
11211120
suite_name_check: bool = True):
11221121
"""Constructor
11231122

0 commit comments

Comments
 (0)