Skip to content

Commit c0f700e

Browse files
committed
Use List and Tuple from typing when specifying these types with subscripts to work around "TypeError: 'type' object is not subscriptable" in py38
1 parent f87e521 commit c0f700e

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/xdist/scheduler/isoscope.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import enum
4848
from math import ceil
4949
import random
50-
from typing import cast
50+
from typing import cast, List, Tuple
5151
from typing import TYPE_CHECKING
5252

5353
import pytest
@@ -142,7 +142,7 @@ def __init__(self, config: pytest.Config, log: xdist.remote.Producer):
142142
# is performed once the number of registered node collections reaches
143143
# `_expected_num_workers`. It is initialized to None and then updated
144144
# after validation succeeds.
145-
self._official_test_collection: tuple[str, ...] | None = None
145+
self._official_test_collection: Tuple[str, ...] | None = None
146146
# Remote worker node having `_official_test_collection` as its test
147147
# collection (for reporting failed collection validations)
148148
self._official_test_collection_node: WorkerController | None = None
@@ -182,7 +182,7 @@ def __init__(self, config: pytest.Config, log: xdist.remote.Producer):
182182
)
183183

184184
@property
185-
def nodes(self) -> list[WorkerController]:
185+
def nodes(self) -> List[WorkerController]:
186186
"""A new list of all active `WorkerController` nodes.
187187
188188
Called by xdist `DSession`.
@@ -371,7 +371,7 @@ def add_node_collection(
371371
WorkerController, self._official_test_collection_node
372372
),
373373
reference_collection=cast(
374-
tuple[str, ...], self._official_test_collection
374+
Tuple[str, ...], self._official_test_collection
375375
),
376376
node=node,
377377
collection=collection,
@@ -404,9 +404,9 @@ def add_node_collection(
404404
for pending_worker in workers_with_collection[1:]:
405405
if not self._do_two_nodes_have_same_collection(
406406
reference_node=reference_worker.node,
407-
reference_collection=cast(tuple[str, ...], reference_worker.collection),
407+
reference_collection=cast(Tuple[str, ...], reference_worker.collection),
408408
node=pending_worker.node,
409-
collection=cast(tuple[str, ...], pending_worker.collection),
409+
collection=cast(Tuple[str, ...], pending_worker.collection),
410410
):
411411
same_collection = False
412412

@@ -433,7 +433,7 @@ def add_node_collection(
433433
all_tests = [
434434
_TestProxy(test_id=test_id, test_index=test_index)
435435
for test_index, test_id in enumerate(
436-
cast(tuple[str, ...], self._official_test_collection)
436+
cast(Tuple[str, ...], self._official_test_collection)
437437
)
438438
]
439439
shuffled_test_collection = random.sample(all_tests, k=len(all_tests))
@@ -460,7 +460,7 @@ def mark_test_complete(
460460
if self._log.enabled:
461461
self._log(
462462
f"Marking test complete: "
463-
f"test_id={cast(tuple[str, ...], self._official_test_collection)[item_index]}; "
463+
f"test_id={cast(Tuple[str, ...], self._official_test_collection)[item_index]}; "
464464
f"{item_index=}; {worker}"
465465
)
466466

@@ -534,7 +534,7 @@ def _reschedule_workers(self) -> None:
534534
"""Distribute work to workers if needed at this time."""
535535
assert self._state is not None
536536

537-
traversed_states: list[IsoScopeScheduling._State] = []
537+
traversed_states: List[IsoScopeScheduling._State] = []
538538
previous_state = None
539539
while self._state != previous_state:
540540
# NOTE: This loop will terminate because completion of tests and
@@ -762,7 +762,7 @@ def _handle_state_fence(self) -> None:
762762
self._log(f"Transitioned from {previous_state!s} to " f"{self._state!s}")
763763

764764
def _distribute_workset(
765-
self, workset: _ScopeWorkset, workers: list[_WorkerProxy]
765+
self, workset: _ScopeWorkset, workers: List[_WorkerProxy]
766766
) -> None:
767767
"""Distribute the tests in the given workset to the given workers.
768768
@@ -977,7 +977,7 @@ def _get_max_workers_for_num_tests(num_tests: int) -> int:
977977

978978
def _get_workers_available_for_distribution(
979979
self, scope_id: str
980-
) -> list[_WorkerProxy]:
980+
) -> List[_WorkerProxy]:
981981
"""Return workers available for distribution of the given Scope.
982982
983983
Available workers are non-shutting-down workers that either
@@ -1001,7 +1001,7 @@ def _get_workers_available_for_distribution(
10011001
)
10021002
]
10031003

1004-
def _get_workers_ready_for_fencing(self, scope_id: str) -> list[_WorkerProxy]:
1004+
def _get_workers_ready_for_fencing(self, scope_id: str) -> List[_WorkerProxy]:
10051005
"""Return workers that are ready to be Fenced for the given test Scope.
10061006
10071007
A worker that needs to be Fenced satisfies all the following conditions:
@@ -1026,9 +1026,9 @@ def _get_workers_ready_for_fencing(self, scope_id: str) -> list[_WorkerProxy]:
10261026
def _do_two_nodes_have_same_collection(
10271027
self,
10281028
reference_node: WorkerController,
1029-
reference_collection: tuple[str, ...],
1029+
reference_collection: Tuple[str, ...],
10301030
node: WorkerController,
1031-
collection: tuple[str, ...],
1031+
collection: Tuple[str, ...],
10321032
) -> bool:
10331033
"""
10341034
If collections differ, this method returns False while logging
@@ -1079,7 +1079,7 @@ def __init__(self, node: WorkerController):
10791079

10801080
# An ordered collection of test IDs collected by the remote worker.
10811081
# Initially None, until assigned by the Scheduler
1082-
self._collection: tuple[str, ...] | None = None
1082+
self._collection: Tuple[str, ...] | None = None
10831083

10841084
self._pending_test_by_index: OrderedDict[int, _TestProxy] = OrderedDict()
10851085

@@ -1092,15 +1092,15 @@ def node(self) -> WorkerController:
10921092
return self._node
10931093

10941094
@property
1095-
def collection(self) -> tuple[str, ...] | None:
1095+
def collection(self) -> Tuple[str, ...] | None:
10961096
"""
10971097
:return: An ordered collection of test IDs collected by the remote
10981098
worker; `None` if the collection is not available yet.
10991099
"""
11001100
return self._collection
11011101

11021102
@collection.setter
1103-
def collection(self, collection: tuple[str, ...]) -> None:
1103+
def collection(self, collection: Tuple[str, ...]) -> None:
11041104
"""
11051105
:param collection: An ordered collection of test IDs collected by the
11061106
remote worker. Must not be `None`. Also, MUST NOT be set already.
@@ -1209,7 +1209,7 @@ def handle_test_completion(self, test_index: int) -> None:
12091209
# Remove the test from the worker's pending queue
12101210
self._pending_test_by_index.pop(test_index)
12111211

1212-
def release_pending_tests(self) -> list[_TestProxy]:
1212+
def release_pending_tests(self) -> List[_TestProxy]:
12131213
"""Reset the worker's pending tests, returning those pending tests.
12141214
12151215
:return: A (possibly empty) list of pending tests.
@@ -1314,7 +1314,7 @@ def enqueue_test(self, test: _TestProxy) -> None:
13141314
# Update high watermark
13151315
self._high_water = max(self._high_water, len(self._test_by_index))
13161316

1317-
def dequeue_tests(self, num_tests: int) -> list[_TestProxy]:
1317+
def dequeue_tests(self, num_tests: int) -> List[_TestProxy]:
13181318
"""
13191319
Remove and return the given number of tests from the head of the
13201320
collection.

0 commit comments

Comments
 (0)