Use from __future__ import annotations
Allows us to use more modern typing.
This commit is contained in:
@@ -7,11 +7,12 @@ processes) otherwise changes to source code can crash
|
||||
the controlling process which should best never happen.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import time
|
||||
from typing import Dict
|
||||
from typing import Sequence
|
||||
|
||||
from _pytest._io import TerminalWriter
|
||||
@@ -45,7 +46,7 @@ def pytest_cmdline_main(config):
|
||||
return 2 # looponfail only can get stop with ctrl-C anyway
|
||||
|
||||
|
||||
def looponfail_main(config: "pytest.Config") -> None:
|
||||
def looponfail_main(config: pytest.Config) -> None:
|
||||
remotecontrol = RemoteControl(config)
|
||||
config_roots = config.getini("looponfailroots")
|
||||
if not config_roots:
|
||||
@@ -238,7 +239,7 @@ class WorkerFailSession:
|
||||
class StatRecorder:
|
||||
def __init__(self, rootdirlist: Sequence[Path]) -> None:
|
||||
self.rootdirlist = rootdirlist
|
||||
self.statcache: Dict[Path, os.stat_result] = {}
|
||||
self.statcache: dict[Path, os.stat_result] = {}
|
||||
self.check() # snapshot state
|
||||
|
||||
def fil(self, p: Path) -> bool:
|
||||
@@ -256,7 +257,7 @@ class StatRecorder:
|
||||
|
||||
def check(self, removepycfiles: bool = True) -> bool:
|
||||
changed = False
|
||||
newstat: Dict[Path, os.stat_result] = {}
|
||||
newstat: dict[Path, os.stat_result] = {}
|
||||
for rootdir in self.rootdirlist:
|
||||
for path in visit_path(rootdir, filter=self.fil, recurse=self.rec):
|
||||
oldstat = self.statcache.pop(path, None)
|
||||
|
||||
@@ -7,11 +7,7 @@ from pathlib import Path
|
||||
import re
|
||||
import sys
|
||||
from typing import Any
|
||||
from typing import List
|
||||
from typing import Optional
|
||||
from typing import Sequence
|
||||
from typing import Set
|
||||
from typing import Tuple
|
||||
from typing import Union
|
||||
import uuid
|
||||
|
||||
@@ -63,7 +59,7 @@ class NodeManager:
|
||||
self.specs.append(spec)
|
||||
self.roots = self._getrsyncdirs()
|
||||
self.rsyncoptions = self._getrsyncoptions()
|
||||
self._rsynced_specs: Set[Tuple[Any, Any]] = set()
|
||||
self._rsynced_specs: set[tuple[Any, Any]] = set()
|
||||
|
||||
def rsync_roots(self, gateway):
|
||||
"""Rsync the set of roots to the node's gateway cwd."""
|
||||
@@ -92,7 +88,7 @@ class NodeManager:
|
||||
def _getxspecs(self):
|
||||
return [execnet.XSpec(x) for x in parse_spec_config(self.config)]
|
||||
|
||||
def _getrsyncdirs(self) -> List[Path]:
|
||||
def _getrsyncdirs(self) -> list[Path]:
|
||||
for spec in self.specs:
|
||||
if not spec.popen or spec.chdir:
|
||||
break
|
||||
@@ -177,7 +173,7 @@ class HostRSync(execnet.RSync):
|
||||
self,
|
||||
sourcedir: PathLike,
|
||||
*,
|
||||
ignores: Optional[Sequence[PathLike]] = None,
|
||||
ignores: Sequence[PathLike] | None = None,
|
||||
verbose: bool = True,
|
||||
) -> None:
|
||||
if ignores is None:
|
||||
@@ -204,7 +200,7 @@ class HostRSync(execnet.RSync):
|
||||
print(f"{gateway.spec}:{remotepath} <= {path}")
|
||||
|
||||
|
||||
def make_reltoroot(roots: Sequence[Path], args: List[str]) -> List[str]:
|
||||
def make_reltoroot(roots: Sequence[Path], args: list[str]) -> list[str]:
|
||||
# XXX introduce/use public API for splitting pytest args
|
||||
splitcode = "::"
|
||||
result = []
|
||||
@@ -219,7 +215,7 @@ def make_reltoroot(roots: Sequence[Path], args: List[str]) -> List[str]:
|
||||
result.append(arg)
|
||||
continue
|
||||
for root in roots:
|
||||
x: Optional[Path]
|
||||
x: Path | None
|
||||
try:
|
||||
x = fspath.relative_to(root)
|
||||
except ValueError:
|
||||
|
||||
Reference in New Issue
Block a user