Skip to content

Commit

Permalink
Merge pull request bluesky#1803 from bluesky/1800-make-reading-generic
Browse files Browse the repository at this point in the history
made `Reading` generic on the type of `Reading.value`
  • Loading branch information
evalott100 authored Sep 26, 2024
2 parents ace1a96 + 0f311a1 commit 22b5bd5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
14 changes: 6 additions & 8 deletions src/bluesky/consolidators.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,12 @@ def __init__(self, stream_resource: StreamResource, descriptor: EventDescriptor)
# 3. Get 'dtype', required by the schema, which is a fuzzy JSON spec like 'number'
# and make a best effort to convert it to a numpy spec like '<u8'.
# 4. If unable to do any of the above, pass through whatever string is in 'dtype'.
self.dtype = (
np.dtype(
data_desc.get("dtype_numpy") # standard location
or data_desc.get(
"dtype_str", # legacy location
# try to guess numpy dtype from JSON type
DTYPE_LOOKUP.get(data_desc["dtype"], data_desc["dtype"])
)
self.dtype = np.dtype(
data_desc.get("dtype_numpy") # standard location
or data_desc.get(
"dtype_str", # legacy location
# try to guess numpy dtype from JSON type
DTYPE_LOOKUP.get(data_desc["dtype"], data_desc["dtype"]),
)
)
self.chunk_size = self._sres_parameters.get("chunk_size", None)
Expand Down
10 changes: 6 additions & 4 deletions src/bluesky/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ class ReadingOptional(TypedDict, total=False):
message: str


class Reading(ReadingOptional):
T = TypeVar("T")
P = ParamSpec("P")


class Reading(Generic[T], ReadingOptional):
"""A dictionary containing the value and timestamp of a piece of scan data"""

#: The current value, as a JSON encodable type or numpy array
value: Any
value: T
#: Timestamp in seconds since the UNIX epoch
timestamp: float

Expand All @@ -71,8 +75,6 @@ class Reading(ReadingOptional):
]


T = TypeVar("T")
P = ParamSpec("P")
SyncOrAsync = Union[T, Awaitable[T]]
SyncOrAsyncIterator = Union[Iterator[T], AsyncIterator[T]]

Expand Down

0 comments on commit 22b5bd5

Please sign in to comment.