Skip to content

Commit d977550

Browse files
Work around python 3.8 lack of support for type unions
1 parent 388a593 commit d977550

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/hip_ra/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@
44
import tempfile
55
import uuid
66
from pathlib import Path
7-
from types import MappingProxyType
7+
from typing import Any
88

99
from geophires_x_client.common import _get_logger
1010
from hip_ra import HIP_RA
1111

1212

1313
class HipRaInputParameters:
1414

15-
def __init__(self, file_path_or_params_dict: str | MappingProxyType):
15+
def __init__(self, file_path_or_params_dict: Any):
1616
if isinstance(file_path_or_params_dict, dict):
1717
tmp_file_path = Path(tempfile.gettempdir(), f'hip-ra-params_{uuid.uuid1()}.txt')
1818
with open(tmp_file_path, 'w') as f:
1919
f.writelines(
2020
[', '.join([str(p) for p in param_item]) + '\n' for param_item in file_path_or_params_dict.items()]
2121
)
2222
file_path_or_params_dict = str(tmp_file_path)
23+
elif not isinstance(file_path_or_params_dict, (str, Path)):
24+
raise ValueError('Provide either file path as string or parameters as dict')
2325

2426
self._input_file_path = Path(file_path_or_params_dict)
2527
self._output_file_path = Path(

tests/hip_ra_x_tests/test_hip_ra_x.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,9 @@ def test_hip_ra_input_parameters_init(self):
445445
input_file_contents,
446446
)
447447

448+
with self.assertRaises(ValueError):
449+
HipRaInputParameters(1)
450+
448451
def _new_hip_ra_test_instance(self, enable_hip_ra_logging_config=False, pre_re_stash_runner=None) -> HIP_RA_X:
449452
stash_cwd = Path.cwd()
450453
stash_sys_argv = sys.argv

0 commit comments

Comments
 (0)