Skip to content

Commit 2f33081

Browse files
committed
Fix compatibility with Python 3.7
1 parent 51c78cd commit 2f33081

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

mypy.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[mypy]
2-
python_version = 3.8
2+
python_version = 3.7
33

44
### --strict
55
# warn_unused_configs = True

nuts/context.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"""Provide necessary information that is needed for a specific test."""
2-
import functools
32
import pathlib
43
from typing import Any, Callable, Optional, Dict, Union
54

@@ -11,6 +10,9 @@
1110
from nuts.helpers.result import NutsResult
1211

1312

13+
_TransformedResult = Dict[str, Any]
14+
15+
1416
class NutsContext:
1517
"""
1618
Base context class. Holds all necessary information that is needed for a specific test.
@@ -20,6 +22,7 @@ class NutsContext:
2022

2123
def __init__(self, nuts_parameters: Any = None):
2224
self.nuts_parameters = nuts_parameters or {}
25+
self._cached_result: Optional[_TransformedResult] = None
2326

2427
def initialize(self) -> None:
2528
"""Initialize dependencies for this context after it has been created."""
@@ -44,21 +47,23 @@ def general_result(self) -> Any:
4447
"""
4548
raise NotImplementedError
4649

47-
def transform_result(self, general_result: Any) -> Dict[str, Any]:
50+
def transform_result(self, general_result: Any) -> _TransformedResult:
4851
"""
4952
:param general_result: raw result
5053
:return: processed result ready to be passed to a test
5154
"""
5255
raise NotImplementedError
5356

54-
@functools.cached_property
55-
def transformed_result(self) -> Dict[str, Any]:
57+
@property
58+
def transformed_result(self) -> _TransformedResult:
5659
"""
5760
The (processed) results of the network task, ready to be passed on to a test's fixture.
5861
The results are cached, so that general_result does not need to be called multiple times as it might
5962
access the network.
6063
"""
61-
return self.transform_result(self.general_result())
64+
if self._cached_result is None:
65+
self._cached_result = self.transform_result(self.general_result())
66+
return self._cached_result
6267

6368

6469
class NornirNutsContext(NutsContext):

0 commit comments

Comments
 (0)