Skip to content

Commit bc0c66d

Browse files
committed
Handled type hinting errors revealed by MyPy
1 parent c29bf68 commit bc0c66d

4 files changed

Lines changed: 19 additions & 16 deletions

File tree

src/murfey/client/analyser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,9 @@ def _xml_file(self, data_file: Path) -> Path:
398398
base_dir, mid_dir = find_longest_data_directory(data_file, data_directories)
399399
if not base_dir:
400400
return data_file.with_suffix(".xml")
401-
return base_dir / self._environment.visit / mid_dir / file_name
401+
# Add the visit directory to the file path and return it
402+
# The file is moved from a location where the visit name is not part of its path
403+
return base_dir / self._environment.visit / (mid_dir or "") / file_name
402404

403405
def enqueue(self, rsyncer: RSyncerUpdate):
404406
if not self._stopping and rsyncer.outcome == TransferResult.SUCCESS:

src/murfey/client/contexts/spa.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
from itertools import count
55
from pathlib import Path
6-
from typing import Any, Dict, List, Optional, OrderedDict, Tuple
6+
from typing import Any, Optional, OrderedDict
77

88
import xmltodict
99

@@ -50,10 +50,10 @@ def _file_transferred_to(
5050

5151

5252
def _grid_square_metadata_file(
53-
f: Path, data_directories: List[Path], visit: str, grid_square: int
53+
f: Path, data_directories: list[Path], visit: str, grid_square: int
5454
) -> Path:
5555
base_dir, mid_dir = find_longest_data_directory(f, data_directories)
56-
if not base_dir:
56+
if not base_dir or not mid_dir:
5757
raise ValueError(f"Could not determine grid square metadata path for {f}")
5858
metadata_file = (
5959
base_dir
@@ -113,7 +113,7 @@ def __init__(self, acquisition_software: str, basepath: Path, token: str):
113113
super().__init__("SPA", acquisition_software, token)
114114
self._basepath = basepath
115115
self._processing_job_stash: dict = {}
116-
self._foil_holes: Dict[int, List[int]] = {}
116+
self._foil_holes: dict[int, list[int]] = {}
117117

118118
def gather_metadata(
119119
self, metadata_file: Path, environment: MurfeyInstanceEnvironment | None = None
@@ -287,7 +287,7 @@ def _position_analysis(
287287
and self._foil_holes.get(grid_square) is None
288288
):
289289
self._foil_holes[grid_square] = []
290-
gs_pix_position: Tuple[
290+
gs_pix_position: tuple[
291291
Optional[int],
292292
Optional[int],
293293
Optional[float],
@@ -586,7 +586,7 @@ def _register_processing_job(
586586
self,
587587
tag: str,
588588
environment: MurfeyInstanceEnvironment,
589-
parameters: Dict[str, Any] | None = None,
589+
parameters: dict[str, Any] | None = None,
590590
):
591591
return
592592

src/murfey/client/destinations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
def find_longest_data_directory(
17-
match_path: Path, data_directories: list[str | Path]
17+
match_path: Path, data_directories: list[str] | list[Path]
1818
) -> tuple[Path | None, Path | None]:
1919
"""
2020
Determine the longest path in the data_directories list

tests/client/test_destinations.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ def test_find_longest_data_directory(
4141
):
4242
# Unpack test params
4343
match_path, use_path, (expected_base_dir, expected_mid_dir) = test_params
44-
data_directories: list[str | Path] = [
45-
Path(dd) if use_path else dd
46-
for dd in (
47-
"X:",
48-
"X:/DATA",
49-
"X:/DoseFractions",
50-
"X:/DoseFractions/DATA",
51-
)
44+
45+
# Construct data directories using strings or Paths as needed
46+
data_directories: list[str] | list[Path] = [
47+
"X:",
48+
"X:/DATA",
49+
"X:/DoseFractions",
50+
"X:/DoseFractions/DATA",
5251
]
52+
if use_path:
53+
data_directories = [Path(dd) for dd in data_directories]
5354
# Patch Pathlib's 'absolute()' function, since we are simulating Windows on Linux
5455
mocker.patch("murfey.client.destinations.Path.absolute", lambda self: self)
5556

0 commit comments

Comments
 (0)