Skip to content

Commit 2e63777

Browse files
committed
refactor: enforce non-quoted type annotations
Enable ruff rules UP037 and FA to forbid quoted type annotations. Plain type annotations are cleaner, more readable, and enable better IDE support and type checking compared to string literals. Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
1 parent cb4e66b commit 2e63777

6 files changed

Lines changed: 15 additions & 6 deletions

File tree

lib/host.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def host_data(hostname_or_ip: str) -> dict[str, str]:
5555

5656
class Host:
5757
xe_prefix = "host"
58-
pool: "Pool"
58+
pool: Pool
5959

6060
# Data extraction is automatic, no conversion from str is done.
6161
@dataclass

lib/vdi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
wait_for,
1414
)
1515

16-
from typing import TYPE_CHECKING, Callable, Literal, TypeVar, overload
16+
from typing import TYPE_CHECKING, Callable, Literal, TypeAlias, TypeVar, overload
1717

1818
if TYPE_CHECKING:
1919
from lib.host import Host
2020
from lib.sr import SR
2121

2222
R = TypeVar("R")
2323

24-
ImageFormat = Literal['qcow2', 'raw', 'vhd']
24+
ImageFormat: TypeAlias = Literal['qcow2', 'raw', 'vhd']
2525

2626
class VDI:
2727
xe_prefix = "vdi"

lib/vm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ def create_cd_vbd(self, device: str, userdevice: str) -> VBD:
706706
logging.info("New VBD %s", vbd_uuid)
707707
return vbd
708708

709-
def clone(self, *, name: str | None = None) -> "VM":
709+
def clone(self, *, name: str | None = None) -> VM:
710710
if name is None:
711711
name = self.name() + '_clone_for_tests'
712712
logging.info("Clone VM")

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@ quote-style = "preserve"
5656
select = [
5757
"ANN", # flake8-annotations
5858
"D", # pydocstyle
59+
"FA", # future-annotations
5960
"F", # Pyflakes
6061
"I", # isort
6162
"SLF", # flake8-self
6263
"SIM", # flake8-simplify
6364
"UP006", # non-pep585-annotation
6465
"UP007", # non-pep604-annotation-union
66+
"UP037", # quoted-annotation
6567
"UP045", # non-pep604-annotation-optional
6668
]
6769
# don't use some of the default D and SIM rules
@@ -91,6 +93,9 @@ ignore = [
9193
# restrict to the PEP 257 rules
9294
pydocstyle.convention = "pep257"
9395

96+
# let ruff require future annotations where it can be useful
97+
future-annotations = true
98+
9499
[tool.ruff.lint.extend-per-file-ignores]
95100
# Pytest fixtures are often flagged as unused imports (F401) or
96101
# redefined variables (F811) because they are injected by name.

tests/storage/lvmohba/test_lvmohba_sr.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import pytest
24

35
from lib.commands import SSHCommandFailed
@@ -55,7 +57,7 @@ def test_snapshot(self, vm_on_lvmohba_sr: VM) -> None:
5557
@pytest.mark.small_vm
5658
@pytest.mark.parametrize("vdi_op", ["snapshot", "clone"])
5759
def test_coalesce(
58-
self, storage_test_vm: 'VM', vdi_on_lvmohba_sr: 'VDI', vdi_op: CoalesceOperation, defer: Defer
60+
self, storage_test_vm: VM, vdi_on_lvmohba_sr: VDI, vdi_op: CoalesceOperation, defer: Defer
5961
) -> None:
6062
coalesce_integrity(storage_test_vm, vdi_on_lvmohba_sr, vdi_op, defer)
6163

tests/storage/lvmoiscsi/test_lvmoiscsi_sr.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import pytest
24

35
from lib.commands import SSHCommandFailed
@@ -54,7 +56,7 @@ def test_snapshot(self, vm_on_lvmoiscsi_sr: VM) -> None:
5456

5557
@pytest.mark.small_vm
5658
@pytest.mark.parametrize("vdi_op", ["snapshot", "clone"])
57-
def test_coalesce(self, storage_test_vm: 'VM', vdi_on_lvmoiscsi_sr: 'VDI', vdi_op: CoalesceOperation,
59+
def test_coalesce(self, storage_test_vm: VM, vdi_on_lvmoiscsi_sr: VDI, vdi_op: CoalesceOperation,
5860
defer: Defer) -> None:
5961
coalesce_integrity(storage_test_vm, vdi_on_lvmoiscsi_sr, vdi_op, defer)
6062

0 commit comments

Comments
 (0)