Skip to content

Commit 3689139

Browse files
committed
Addressed additional pre-commit findings.
1 parent be0a561 commit 3689139

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

src/xdist/iso_scheduling_plugin.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,11 @@ def maybe_call_teardown(
353353
teardown_callback(self._teardown_context)
354354

355355

356-
def _map_file_lock_exception(f: Callable):
356+
def _map_file_lock_exception(f: Callable): # type: ignore[no-untyped-def, type-arg]
357357
"""Decorator: map `FileLock` exceptions of interest to our own exceptions."""
358358

359359
@functools.wraps(f)
360-
def wrapper(*args, **kwargs):
360+
def wrapper(*args, **kwargs): # type: ignore[no-untyped-def]
361361
try:
362362
return f(*args, **kwargs)
363363
except filelock.Timeout as err:
@@ -380,11 +380,11 @@ class _DistributedSetupCoordinationImpl:
380380
class DistributedState:
381381
"""State of the Distributed Setup-Teardown Coordination."""
382382

383-
def __init__(self, setup_count, teardown_count):
383+
def __init__(self, setup_count: int, teardown_count: int) -> None:
384384
self.setup_count = setup_count
385385
self.teardown_count = teardown_count
386386

387-
def __repr__(self):
387+
def __repr__(self) -> str:
388388
return (
389389
f"<{self.__class__.__qualname__}: "
390390
f"setup_count={self.setup_count}; "
@@ -404,7 +404,7 @@ def load_from_file_path(
404404
return cls(**json.loads(state_file_path.read_text()))
405405

406406
@property
407-
def as_json_kwargs_dict(self) -> dict:
407+
def as_json_kwargs_dict(self) -> dict[str, int]:
408408
"""
409409
:return: JSON-compatible representation of the instance that is also
410410
suitable for constructing the instance after fetching from file.

src/xdist/scheduler/isoscope.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import random
5050
from typing import TYPE_CHECKING
5151

52-
from _pytest.runner import CollectReport
5352
import pytest
5453

5554
from xdist.report import report_collection_diff
@@ -142,7 +141,7 @@ def __init__(self, config: pytest.Config, log: xdist.remote.Producer):
142141
# is performed once the number of registered node collections reaches
143142
# `_expected_num_workers`. It is initialized to None and then updated
144143
# after validation succeeds.
145-
self._official_test_collection: tuple[str] | None = None
144+
self._official_test_collection: tuple[str, ...] | None = None
146145
# Remote worker node having `_official_test_collection` as its test
147146
# collection (for reporting failed collection validations)
148147
self._official_test_collection_node: WorkerController | None = None
@@ -367,7 +366,7 @@ def add_node_collection(
367366

368367
# Check that the new collection matches the official collection
369368
if self._do_two_nodes_have_same_collection(
370-
reference_node=self._official_test_collection_node,
369+
reference_node=self._official_test_collection_node, # type: ignore[arg-type]
371370
reference_collection=self._official_test_collection,
372371
node=node,
373372
collection=collection,
@@ -528,7 +527,7 @@ def _reschedule_workers(self) -> None:
528527
"""Distribute work to workers if needed at this time."""
529528
assert self._state is not None
530529

531-
traversed_states = []
530+
traversed_states: list[IsoScopeScheduling._State] = []
532531
previous_state = None
533532
while self._state != previous_state:
534533
# NOTE: This loop will terminate because completion of tests and
@@ -815,12 +814,11 @@ def _distribute_workset(
815814
)
816815

817816
num_tests_remaining = workset.high_water
817+
worker: _WorkerProxy
818+
num_available_workers: int
818819
for worker, num_available_workers in zip(
819820
workers, range(num_workers_to_use, 0, -1)
820821
):
821-
worker: _WorkerProxy
822-
num_available_workers: int
823-
824822
# Workers ready for distribution must have no more than one pending
825823
# test
826824
assert (
@@ -1021,7 +1019,7 @@ def _get_workers_ready_for_fencing(self, scope_id: str) -> list[_WorkerProxy]:
10211019
def _do_two_nodes_have_same_collection(
10221020
self,
10231021
reference_node: WorkerController,
1024-
reference_collection: tuple[str],
1022+
reference_collection: tuple[str, ...],
10251023
node: WorkerController,
10261024
collection: tuple[str, ...],
10271025
) -> bool:
@@ -1050,7 +1048,7 @@ def _do_two_nodes_have_same_collection(
10501048
# NOTE: Not sure why/when `_config` would be `None`. Copied check
10511049
# from the `loadscope` scheduler.
10521050

1053-
report = CollectReport(node.gateway.id, "failed", longrepr=msg, result=[])
1051+
report = pytest.CollectReport(node.gateway.id, "failed", longrepr=msg, result=[])
10541052
self._config.hook.pytest_collectreport(report=report)
10551053

10561054
return False
@@ -1072,11 +1070,11 @@ def __init__(self, node: WorkerController):
10721070

10731071
# An ordered collection of test IDs collected by the remote worker.
10741072
# Initially None, until assigned by the Scheduler
1075-
self._collection: tuple[str] | None = None
1073+
self._collection: tuple[str, ...] | None = None
10761074

10771075
self._pending_test_by_index: OrderedDict[int, _TestProxy] = OrderedDict()
10781076

1079-
def __repr__(self):
1077+
def __repr__(self) -> str:
10801078
return self.verbose_repr(verbose=False)
10811079

10821080
@property
@@ -1085,15 +1083,15 @@ def node(self) -> WorkerController:
10851083
return self._node
10861084

10871085
@property
1088-
def collection(self) -> tuple[str] | None:
1086+
def collection(self) -> tuple[str, ...] | None:
10891087
"""
10901088
:return: An ordered collection of test IDs collected by the remote
10911089
worker; `None` if the collection is not available yet.
10921090
"""
10931091
return self._collection
10941092

10951093
@collection.setter
1096-
def collection(self, collection: tuple[str]):
1094+
def collection(self, collection: tuple[str, ...]):
10971095
"""
10981096
:param collection: An ordered collection of test IDs collected by the
10991097
remote worker. Must not be `None`. Also, MUST NOT be set already.
@@ -1243,7 +1241,7 @@ def __init__(self, test_id: str, test_index: int):
12431241
self.test_id: str = test_id
12441242
self.test_index: int = test_index
12451243

1246-
def __repr__(self):
1244+
def __repr__(self) -> str:
12471245
return (
12481246
f"<{self.__class__.__name__}: test_index={self.test_index} "
12491247
f"scope_id={self.scope_id} test_id={self.test_id}>"
@@ -1273,7 +1271,7 @@ def __init__(self, scope_id: str):
12731271

12741272
self._test_by_index: OrderedDict[int, _TestProxy] = OrderedDict()
12751273

1276-
def __repr__(self):
1274+
def __repr__(self) -> str:
12771275
return (
12781276
f"<{self.__class__.__name__}: scope_id={self.scope_id} "
12791277
f"num_tests={self.num_tests} high_water={self.high_water}>"
@@ -1333,10 +1331,10 @@ def dequeue_tests(self, num_tests: int) -> list[_TestProxy]:
13331331
class _WorksetQueue:
13341332
"""Ordered collection of Scope Worksets grouped by scope id."""
13351333

1336-
def __init__(self):
1334+
def __init__(self) -> None:
13371335
self._workset_by_scope: OrderedDict[str, _ScopeWorkset] = OrderedDict()
13381336

1339-
def __repr__(self):
1337+
def __repr__(self) -> str:
13401338
return (
13411339
f"<{self.__class__.__name__}: "
13421340
f"num_worksets={len(self._workset_by_scope)}>"

0 commit comments

Comments
 (0)