Skip to content

Commit e7a971b

Browse files
committed
Use from __future__ import annotations
Allows us to use more modern typing.
1 parent 059c1bc commit e7a971b

File tree

6 files changed

+23
-24
lines changed

6 files changed

+23
-24
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ select = [
8585
"W", # pycodestyle
8686
"T10", # flake8-debugger
8787
"PIE", # flake8-pie
88+
"FA", # flake8-future-annotations
8889
"PGH", # pygrep-hooks
8990
"PLE", # pylint error
9091
"PLW", # pylint warning

src/xdist/looponfail.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
the controlling process which should best never happen.
88
"""
99

10+
from __future__ import annotations
11+
1012
import os
1113
from pathlib import Path
1214
import sys
1315
import time
14-
from typing import Dict
1516
from typing import Sequence
1617

1718
from _pytest._io import TerminalWriter
@@ -45,7 +46,7 @@ def pytest_cmdline_main(config):
4546
return 2 # looponfail only can get stop with ctrl-C anyway
4647

4748

48-
def looponfail_main(config: "pytest.Config") -> None:
49+
def looponfail_main(config: pytest.Config) -> None:
4950
remotecontrol = RemoteControl(config)
5051
config_roots = config.getini("looponfailroots")
5152
if not config_roots:
@@ -238,7 +239,7 @@ def main(self):
238239
class StatRecorder:
239240
def __init__(self, rootdirlist: Sequence[Path]) -> None:
240241
self.rootdirlist = rootdirlist
241-
self.statcache: Dict[Path, os.stat_result] = {}
242+
self.statcache: dict[Path, os.stat_result] = {}
242243
self.check() # snapshot state
243244

244245
def fil(self, p: Path) -> bool:
@@ -256,7 +257,7 @@ def waitonchange(self, checkinterval=1.0):
256257

257258
def check(self, removepycfiles: bool = True) -> bool:
258259
changed = False
259-
newstat: Dict[Path, os.stat_result] = {}
260+
newstat: dict[Path, os.stat_result] = {}
260261
for rootdir in self.rootdirlist:
261262
for path in visit_path(rootdir, filter=self.fil, recurse=self.rec):
262263
oldstat = self.statcache.pop(path, None)

src/xdist/workermanage.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
import re
88
import sys
99
from typing import Any
10-
from typing import List
11-
from typing import Optional
1210
from typing import Sequence
13-
from typing import Set
14-
from typing import Tuple
1511
from typing import Union
1612
import uuid
1713

@@ -63,7 +59,7 @@ def __init__(self, config, specs=None, defaultchdir="pyexecnetcache") -> None:
6359
self.specs.append(spec)
6460
self.roots = self._getrsyncdirs()
6561
self.rsyncoptions = self._getrsyncoptions()
66-
self._rsynced_specs: Set[Tuple[Any, Any]] = set()
62+
self._rsynced_specs: set[tuple[Any, Any]] = set()
6763

6864
def rsync_roots(self, gateway):
6965
"""Rsync the set of roots to the node's gateway cwd."""
@@ -92,7 +88,7 @@ def teardown_nodes(self):
9288
def _getxspecs(self):
9389
return [execnet.XSpec(x) for x in parse_spec_config(self.config)]
9490

95-
def _getrsyncdirs(self) -> List[Path]:
91+
def _getrsyncdirs(self) -> list[Path]:
9692
for spec in self.specs:
9793
if not spec.popen or spec.chdir:
9894
break
@@ -177,7 +173,7 @@ def __init__(
177173
self,
178174
sourcedir: PathLike,
179175
*,
180-
ignores: Optional[Sequence[PathLike]] = None,
176+
ignores: Sequence[PathLike] | None = None,
181177
verbose: bool = True,
182178
) -> None:
183179
if ignores is None:
@@ -204,7 +200,7 @@ def _report_send_file(self, gateway, modified_rel_path):
204200
print(f"{gateway.spec}:{remotepath} <= {path}")
205201

206202

207-
def make_reltoroot(roots: Sequence[Path], args: List[str]) -> List[str]:
203+
def make_reltoroot(roots: Sequence[Path], args: list[str]) -> list[str]:
208204
# XXX introduce/use public API for splitting pytest args
209205
splitcode = "::"
210206
result = []
@@ -219,7 +215,7 @@ def make_reltoroot(roots: Sequence[Path], args: List[str]) -> List[str]:
219215
result.append(arg)
220216
continue
221217
for root in roots:
222-
x: Optional[Path]
218+
x: Path | None
223219
try:
224220
x = fspath.relative_to(root)
225221
except ValueError:

testing/acceptance_test.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
from __future__ import annotations
2+
13
import os
24
import re
35
import shutil
4-
from typing import Dict
5-
from typing import List
6-
from typing import Tuple
76

87
import pytest
98

@@ -1528,7 +1527,7 @@ def test_multi_file(self, pytester, scope) -> None:
15281527
result.assert_outcomes(passed=(48 if scope != "each" else 48 * 2))
15291528

15301529

1531-
def parse_tests_and_workers_from_output(lines: List[str]) -> List[Tuple[str, str, str]]:
1530+
def parse_tests_and_workers_from_output(lines: list[str]) -> list[tuple[str, str, str]]:
15321531
result = []
15331532
for line in lines:
15341533
# example match: "[gw0] PASSED test_a.py::test[7]"
@@ -1550,9 +1549,9 @@ def parse_tests_and_workers_from_output(lines: List[str]) -> List[Tuple[str, str
15501549

15511550

15521551
def get_workers_and_test_count_by_prefix(
1553-
prefix: str, lines: List[str], expected_status: str = "PASSED"
1554-
) -> Dict[str, int]:
1555-
result: Dict[str, int] = {}
1552+
prefix: str, lines: list[str], expected_status: str = "PASSED"
1553+
) -> dict[str, int]:
1554+
result: dict[str, int] = {}
15561555
for worker, status, nodeid in parse_tests_and_workers_from_output(lines):
15571556
if expected_status == status and nodeid.startswith(prefix):
15581557
result[worker] = result.get(worker, 0) + 1

testing/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from __future__ import annotations
2+
13
import shutil
2-
from typing import List
34

45
import execnet
56
import pytest
@@ -41,7 +42,7 @@ def specssh(request) -> str:
4142

4243

4344
# configuration information for tests
44-
def getgspecs(config) -> List[execnet.XSpec]:
45+
def getgspecs(config) -> list[execnet.XSpec]:
4546
return [execnet.XSpec(spec) for spec in config.getvalueorskip("gspecs")]
4647

4748

testing/test_looponfail.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
from __future__ import annotations
2+
13
import pathlib
24
from pathlib import Path
35
import shutil
46
import tempfile
57
import textwrap
6-
from typing import List
78
import unittest.mock
89

910
import pytest
@@ -75,7 +76,7 @@ def test_filechange_deletion_race(self, tmp_path: Path) -> None:
7576
# make check()'s visit() call return our just removed
7677
# path as if we were in a race condition
7778
dirname = str(tmp)
78-
dirnames: List[str] = []
79+
dirnames: list[str] = []
7980
filenames = [str(p)]
8081
with unittest.mock.patch(
8182
"os.walk", return_value=[(dirname, dirnames, filenames)], autospec=True

0 commit comments

Comments
 (0)