From a47f96bfde71e15a2006bcffc92e7d9accce538a Mon Sep 17 00:00:00 2001 From: Relm-Arrowny Date: Wed, 17 Apr 2024 16:36:22 +0000 Subject: [PATCH] change Dict to Mapping and fix all the mypy issue --- docs/conf.py | 2 +- src/ophyd_async/core/signal.py | 8 ++++---- tests/core/test_signal.py | 23 +++++++++++------------ 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 4a0b72fb7f..690d40aef4 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -118,7 +118,7 @@ # docs in the python documentation. intersphinx_mapping = { "python": ("https://docs.python.org/3", None), - "bluesky": ("https://blueskyproject.io/bluesky/", None), + "bluesky": ("https://blueskyproject.io/bluesky/main", None), "numpy": ("https://numpy.org/devdocs/", None), "databroker": ("https://blueskyproject.io/databroker/", None), "event-model": ("https://blueskyproject.io/event-model/main", None), diff --git a/src/ophyd_async/core/signal.py b/src/ophyd_async/core/signal.py index 6944fdb9e0..45cf0400cf 100644 --- a/src/ophyd_async/core/signal.py +++ b/src/ophyd_async/core/signal.py @@ -258,7 +258,7 @@ def set_sim_callback(signal: Signal[T], callback: ReadingValueCallback[T]) -> No async def _verify_readings( - func: Callable[[], dict[str, Reading] | Awaitable[dict[str, Reading]]], + func: Callable[[], Mapping[str, Reading] | Awaitable[Mapping[str, Reading]]], expectation: Mapping[str, Reading], ) -> None: """Take a read/read_configuration function that return a dictionary and @@ -308,7 +308,7 @@ async def assert_value(signal: SignalR[T], value: T) -> None: assert await signal.get_value() == value -async def assert_reading(readable: Readable, reading: Mapping[str, Reading]) -> None: +async def assert_reading(readable: Readable, reading: Dict[str, Reading]) -> None: """Assert readable by calling_verify_readings Parameters @@ -330,7 +330,7 @@ async def assert_reading(readable: Readable, reading: Mapping[str, Reading]) -> async def assert_configuration( configurable: Configurable, - configuration: Dict[str, Reading], + configuration: Mapping[str, Reading], ) -> None: """ Assert configurable generated by configurable.read_configuration by @@ -353,7 +353,7 @@ async def assert_configuration( await _verify_readings(configurable.read_configuration, configuration) -def assert_emitted(docs: Dict[str, list[DocumentType]], **numbers: int): +def assert_emitted(docs: Mapping[str, list[DocumentType]], **numbers: int): """Assert emitted""" assert list(docs) == list(numbers) assert {name: len(d) for name, d in docs.items()} == numbers diff --git a/tests/core/test_signal.py b/tests/core/test_signal.py index 9567fe4223..0db40e63ce 100644 --- a/tests/core/test_signal.py +++ b/tests/core/test_signal.py @@ -1,6 +1,7 @@ import asyncio import re import time +from typing import Mapping from unittest.mock import ANY import pytest @@ -179,30 +180,28 @@ async def test_assert_configuration(sim_readable: DummyReadable): set_sim_value(sim_readable.value, 123) set_sim_value(sim_readable.mode, "super mode") set_sim_value(sim_readable.mode2, "slow mode") - dummy_config_reading = { - "sim_readable-mode": Reading( + dummy_config_reading: Mapping[str, Reading] = { + "sim_readable-mode": ( { "alarm_severity": 0, "timestamp": ANY, "value": "super mode", } ), - "sim_readable-mode2": Reading( - { - "alarm_severity": 0, - "timestamp": ANY, - "value": "slow mode", - } - ), + "sim_readable-mode2": { + "alarm_severity": 0, + "timestamp": ANY, + "value": "slow mode", + }, } await assert_configuration(sim_readable, dummy_config_reading) # test for none awaitable part of verify from ophyd.sim import DetWithConf something = DetWithConf(name="det") - dummy_config_reading1 = { - "det_c": Reading({"value": 3, "timestamp": ANY}), - "det_d": Reading({"value": 4, "timestamp": ANY}), + dummy_config_reading1: Mapping[str, Reading] = { + "det_c": {"value": 3, "timestamp": ANY}, + "det_d": {"value": 4, "timestamp": ANY}, } await assert_configuration(something, dummy_config_reading1)