Skip to content

Correct return types to match current bluesky protocols #1232

@evvaaaa

Description

@evvaaaa

Ophyd still uses older and less specific return types for some of the bluesky protocols.

class SomeDevice(Device):
    readable_sig = Component(SignalRO, "prefix")


def read_stuff(signal: Readable):
    pass


my_device = SomeDevice("prefix", name="name")

read_stuff(my_device.readable_sig)

gives type errors

Argument of type "SignalRO" cannot be assigned to parameter "signal" of type "Readable" in function "read_stuff"
  "SignalRO" is incompatible with protocol "Readable"
    "read" is an incompatible type
      Type "() -> dict[str | Unknown, dict[str, float | Unknown]]" cannot be assigned to type "() -> SyncOrAsync[Dict[str, Reading[Unknown]]]"
        Function return type "dict[str | Unknown, dict[str, float | Unknown]]" is incompatible with type "SyncOrAsync[Dict[str, Reading[Unknown]]]"
          Type "dict[str | Unknown, dict[str, float | Unknown]]" cannot be assigned to type "SyncOrAsync[Dict[str, Reading[Unknown]]]"
    "describe" is an incompatible type
      Type "() -> dict[str | Unknown, dict[str, Unknown]]" cannot be assigned to type "() -> SyncOrAsync[Dict[str, DataKey]]"
        Function return type "dict[str | Unknown, dict[str, Unknown]]" is incompatible with type "SyncOrAsync[Dict[str, DataKey]]"

Correcting

def read(self) -> OrderedDictType[str, Dict[str, Any]]:

and

def describe(self) -> OrderedDictType[str, Dict[str, Any]]:

to match

https://github.com/bluesky/bluesky/blob/88c403ffbfb539edfb74240703caca6c228480b7/src/bluesky/protocols.py#L269

and

https://github.com/bluesky/bluesky/blob/88c403ffbfb539edfb74240703caca6c228480b7/src/bluesky/protocols.py#L287

would fix the above.

There may be other places, e.g

def describe_collect(self) -> Dict[str, Dict]:

and

https://github.com/bluesky/bluesky/blob/88c403ffbfb539edfb74240703caca6c228480b7/src/bluesky/protocols.py#L312

@olliesilvester

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions