Skip to content

Commit

Permalink
python3.8 type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrudd2 committed Jul 16, 2024
1 parent dd78f77 commit a30c83d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions alicat/mock.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Mock for offline testing of `FlowController`s."""
from __future__ import annotations

from random import choice, random
from time import sleep
from typing import Any, Dict, Union
from typing import Any
from unittest.mock import MagicMock

from .driver import FlowController as RealFlowController
Expand All @@ -24,7 +25,7 @@ def __init__(self, address: str, unit: str = 'A', *args: Any, **kwargs: Any) ->
self.hw = AsyncClientMock()
self.open = True
self.control_point: str = choice(['flow', 'pressure'])
self.state: Dict[str, Union[str, float]] = {
self.state: dict[str, str | float] = {
'setpoint': 10,
'gas': 'N2',
'mass_flow': 10 * (0.95 + 0.1 * random()),
Expand All @@ -41,7 +42,7 @@ def __init__(self, address: str, unit: str = 'A', *args: Any, **kwargs: Any) ->
'setpoint', 'gas']
self.firmware = '6v21.0-R22 Nov 30 2016,16:04:20'

async def get(self) -> Dict[str, Union[str, float]]:
async def get(self) -> dict[str, str | float]:
"""Return the full state."""
sleep(random() * 0.25)
return self.state
Expand All @@ -63,7 +64,7 @@ async def set_flow_rate(self, flowrate: float) -> None:
await self._set_control_point('flow')
await self._set_setpoint(flowrate)

async def set_gas(self, gas: Union[int, str]) -> None:
async def set_gas(self, gas: int | str) -> None:
"""Set the gas type."""
if isinstance(gas, int):
gas = self.gases[gas]
Expand Down

0 comments on commit a30c83d

Please sign in to comment.