Callbacks to the bluesky RE are currently called as callback(name, doc) which does not allow inferring the structure of doc when given a particular name. If we passed a tuple of the two and called callback(named_doc) then we could do type inference on the content. E.g.
Code sample in pyright playground
from typing import TypedDict, Literal, Unpack
class DocA(TypedDict):
foo: str
bar: int
class DocB(TypedDict):
foo: str
bat: float
NamedDocument = \
tuple[Literal["doc_a"], DocA] | \
tuple[Literal["doc_b"], DocB]
def my_callback(named_document: NamedDocument):
match named_document:
case "doc_a", doc:
num = doc["bar"]
case "doc_b", doc:
num = doc["bat"]
print(num)
This ticket is to decide if this is a good idea, then create the NamedDocument union so that a corresponding bluesky ticket can be created to discuss the callback changes on the bluesky time.
Acceptance Criteria
- Decide this is a good idea, then create the union