Skip to content

Commit

Permalink
squash: tackle remaining @DataClass
Browse files Browse the repository at this point in the history
  • Loading branch information
happz committed Jan 30, 2025
1 parent 5e3a6ca commit 791169c
Show file tree
Hide file tree
Showing 19 changed files with 50 additions and 50 deletions.
4 changes: 2 additions & 2 deletions tests/unit/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import dataclasses
import os
import shutil
import sys
Expand All @@ -10,6 +9,7 @@
import tmt.cli._root
import tmt.log
from tests import CliRunner
from tmt.container import container
from tmt.utils import Path

# Prepare path to examples
Expand Down Expand Up @@ -133,7 +133,7 @@ def test_systemd():
assert 'Tier two functional tests' in result.output


@dataclasses.dataclass # noqa: TID251
@container
class DecideColorizationTestcase:
""" A single test case for :py:func:`tmt.log.decide_colorization` """

Expand Down
5 changes: 2 additions & 3 deletions tmt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import collections
import copy
import dataclasses
import enum
import functools
import itertools
Expand Down Expand Up @@ -1601,7 +1600,7 @@ def lint_require_type_field(self) -> LinterReturn:
yield LinterOutcome.FIXED, 'added type to requirements'


@dataclasses.dataclass(repr=False) # noqa: TID251
@container(repr=False)
class LintableCollection(tmt.lint.Lintable['LintableCollection']):
""" Linting rules applied to a collection of Tests, Plans or Stories """

Expand Down Expand Up @@ -4114,7 +4113,7 @@ def runs(self, id_: tuple[str, ...], keep: Optional[int]) -> bool:
return successful


@dataclasses.dataclass # noqa: TID251
@container
class LinkNeedle:
"""
A container to use for searching links.
Expand Down
3 changes: 1 addition & 2 deletions tmt/checks/watchdog.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import dataclasses
import datetime
import re
import threading
Expand Down Expand Up @@ -85,7 +84,7 @@ def report_progress(
f.write('\n')


@dataclasses.dataclass # noqa: TID251
@container
class GuestContext:
""" Per-guest watchdog context """

Expand Down
5 changes: 3 additions & 2 deletions tmt/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import tmt.plugins
import tmt.utils
import tmt.utils.rest
from tmt.container import container

if TYPE_CHECKING:
from tmt._compat.typing import Concatenate, ParamSpec
Expand Down Expand Up @@ -76,7 +77,7 @@ class TmtExitCode(enum.IntEnum):
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


@dataclasses.dataclass # noqa: TID251
@container
class ContextObject:
"""
Click Context Object container.
Expand Down Expand Up @@ -139,7 +140,7 @@ def pass_context(fn: 'Callable[Concatenate[Context, P], R]') -> 'Callable[P, R]'
return click.pass_context(fn) # type: ignore[arg-type]


@dataclasses.dataclass # noqa: TID251
@container
class CliInvocation:
"""
A single CLI invocation of a tmt subcommand.
Expand Down
8 changes: 4 additions & 4 deletions tmt/container/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
if TYPE_CHECKING:
from _typeshed import DataclassInstance

import tmt.log
import tmt.options
from tmt._compat.typing import TypeAlias

import tmt.log

# A stand-in variable for generic use.
T = TypeVar('T')
Expand All @@ -30,7 +30,7 @@
from dataclasses import dataclass as container # noqa: TID251,E402

#: Type of field's normalization callback.
NormalizeCallback: 'TypeAlias' = Callable[[str, Any, tmt.log.Logger], T]
NormalizeCallback: 'TypeAlias' = Callable[[str, Any, 'tmt.log.Logger'], T]

#: Type of field's exporter callback.
FieldExporter: 'TypeAlias' = Callable[[T], Any]
Expand Down Expand Up @@ -65,7 +65,7 @@ def option_to_key(option: str) -> str:
return option.replace('-', '_')


@dataclasses.dataclass # noqa: TID251
@container
class FieldMetadata(Generic[T]):
"""
A dataclass metadata container used by our custom dataclass field management.
Expand Down Expand Up @@ -559,7 +559,7 @@ def _produce_unserialized() -> Iterator[tuple[str, Any]]:
@staticmethod
def unserialize(
serialized: dict[str, Any],
logger: tmt.log.Logger
logger: 'tmt.log.Logger'
) -> SerializableContainerDerivedType: # type: ignore[misc,type-var]
"""
Convert from a serialized form loaded from a file.
Expand Down
3 changes: 1 addition & 2 deletions tmt/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
[1] https://tmt.readthedocs.io/en/stable/spec/hardware.html
"""

import dataclasses
import enum
import functools
import itertools
Expand Down Expand Up @@ -203,7 +202,7 @@ class ConstraintNameComponents(NamedTuple):
child_name: Optional[str]


@dataclasses.dataclass # noqa: TID251
@container
class ConstraintComponents:
""" Components of a constraint """

Expand Down
4 changes: 2 additions & 2 deletions tmt/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def lint_manual_valid_markdown(self) -> LinterReturn:
...
"""

import dataclasses
import enum
import re
import textwrap
Expand All @@ -82,6 +81,7 @@ def lint_manual_valid_markdown(self) -> LinterReturn:

import tmt
import tmt.utils
from tmt.container import container

if TYPE_CHECKING:
import tmt.base
Expand Down Expand Up @@ -146,7 +146,7 @@ class LinterOutcome(enum.Enum):
""", re.VERBOSE)


@dataclasses.dataclass(init=False) # noqa: TID251
@container(init=False)
class Linter:
""" A single linter """

Expand Down
3 changes: 2 additions & 1 deletion tmt/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

from tmt._compat.pathlib import Path
from tmt._compat.warnings import deprecated
from tmt.container import container

if TYPE_CHECKING:
import tmt.cli
Expand Down Expand Up @@ -254,7 +255,7 @@ def indent(
+ '\n'.join(f'{prefix}{indent}{deeper}{line}' for line in lines)


@dataclasses.dataclass # noqa: TID251
@container
class LogRecordDetails:
""" tmt's log message components attached to log records """

Expand Down
4 changes: 2 additions & 2 deletions tmt/options.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
""" Common options and the MethodCommand class """

import contextlib
import dataclasses
import re
import textwrap
from collections.abc import Sequence
Expand All @@ -12,6 +11,7 @@
import tmt.lint
import tmt.log
import tmt.utils
from tmt.container import container

# When dealing with older Click packages (I'm looking at you, Python 3.6),
# we need to define FC on our own.
Expand All @@ -29,7 +29,7 @@
import tmt.utils


@dataclasses.dataclass(frozen=True) # noqa: TID251
@container(frozen=True)
class Deprecated:
""" Version information and hint for obsolete options """

Expand Down
3 changes: 2 additions & 1 deletion tmt/package_managers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import tmt.log
import tmt.plugins
import tmt.utils
from tmt.container import container
from tmt.utils import Command, CommandOutput, Path

if TYPE_CHECKING:
Expand Down Expand Up @@ -112,7 +113,7 @@ def escape_installables(*installables: Installable) -> Iterator[str]:


# TODO: find a better name, "options" is soooo overloaded...
@dataclasses.dataclass(frozen=True) # noqa: TID251
@container(frozen=True)
class Options:
#: A list of packages to exclude from installation.
excluded_packages: list[Package] = dataclasses.field(default_factory=list) # noqa: TID251
Expand Down
7 changes: 4 additions & 3 deletions tmt/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from concurrent.futures import Future, ThreadPoolExecutor, as_completed
from typing import TYPE_CHECKING, Any, Generic, Optional, TypeVar

from tmt.container import container
from tmt.log import Logger

if TYPE_CHECKING:
Expand All @@ -14,7 +15,7 @@
TaskResultT = TypeVar('TaskResultT')


@dataclasses.dataclass # noqa: TID251
@container
class Task(Generic[TaskResultT]):
"""
A base class for queueable actions.
Expand Down Expand Up @@ -119,7 +120,7 @@ def prepare_loggers(logger: Logger, labels: list[str]) -> dict[str, Logger]:
return loggers


@dataclasses.dataclass # noqa: TID251
@container
class GuestlessTask(Task[TaskResultT]):
"""
A task not assigned to a particular set of guests.
Expand Down Expand Up @@ -174,7 +175,7 @@ def go(self) -> Iterator['Self']:
yield self


@dataclasses.dataclass # noqa: TID251
@container
class MultiGuestTask(Task[TaskResultT]):
"""
A task assigned to a particular set of guests.
Expand Down
9 changes: 4 additions & 5 deletions tmt/steps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
""" Step Classes """

import collections
import dataclasses
import functools
import itertools
import re
Expand Down Expand Up @@ -2266,7 +2265,7 @@ def push(
return environment


@dataclasses.dataclass # noqa: TID251
@container
class ActionTask(tmt.queue.GuestlessTask[None]):
""" A task to run an action """

Expand All @@ -2290,7 +2289,7 @@ def run(self, logger: tmt.log.Logger) -> None:
self.phase.go()


@dataclasses.dataclass # noqa: TID251
@container
class PluginTask(tmt.queue.MultiGuestTask[PluginReturnValueT],
Generic[StepDataT, PluginReturnValueT]):
""" A task to run a phase on a given set of guests """
Expand Down Expand Up @@ -2356,7 +2355,7 @@ def enqueue_plugin(
))


@dataclasses.dataclass # noqa: TID251
@container
class PushTask(tmt.queue.MultiGuestTask[None]):
""" Task performing a workdir push to a guest """

Expand All @@ -2376,7 +2375,7 @@ def run_on_guest(self, guest: 'Guest', logger: tmt.log.Logger) -> None:
guest.push()


@dataclasses.dataclass # noqa: TID251
@container
class PullTask(tmt.queue.MultiGuestTask[None]):
""" Task performing a workdir pull from a guest """

Expand Down
10 changes: 5 additions & 5 deletions tmt/steps/execute/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
SCRIPTS_DEST_DIR_VARIABLE = 'TMT_SCRIPTS_DIR'


@dataclasses.dataclass # noqa: TID251
@container
class Script:
"""
Represents a script provided by the internal executor.
Expand Down Expand Up @@ -108,7 +108,7 @@ def __exit__(self, *args: object) -> None:
pass


@dataclasses.dataclass # noqa: TID251
@container
class ScriptCreatingFile(Script):
"""
Represents a script which creates a file.
Expand All @@ -119,7 +119,7 @@ class ScriptCreatingFile(Script):
created_file: str


@dataclasses.dataclass # noqa: TID251
@container
class ScriptTemplate(Script):
"""
Represents a Jinja2 templated script.
Expand Down Expand Up @@ -262,7 +262,7 @@ class ExecuteStepData(tmt.steps.WhereableStepData, tmt.steps.StepData):
ExecuteStepDataT = TypeVar('ExecuteStepDataT', bound=ExecuteStepData)


@dataclasses.dataclass # noqa: TID251
@container
class TestInvocation:
"""
A bundle describing one test invocation.
Expand Down Expand Up @@ -568,7 +568,7 @@ def terminate_process(
self.guest._cleanup_ssh_master_process(signal, logger)


@dataclasses.dataclass # noqa: TID251
@container
class ResultCollection:
""" Collection of raw results loaded from a file """

Expand Down
2 changes: 1 addition & 1 deletion tmt/steps/prepare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def go(
# same time.


@dataclasses.dataclass # noqa: TID251
@container
class DependencyCollection:
""" Bundle guests and packages to install on them """

Expand Down
2 changes: 1 addition & 1 deletion tmt/steps/provision/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2477,7 +2477,7 @@ def show(self, keys: Optional[list[str]] = None) -> None:
echo(tmt.utils.format('hardware', tmt.utils.dict_to_yaml(hardware.to_spec())))


@dataclasses.dataclass # noqa: TID251
@container
class ProvisionTask(tmt.queue.GuestlessTask[None]):
""" A task to run provisioning of multiple guests """

Expand Down
Loading

0 comments on commit 791169c

Please sign in to comment.