Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify find_instrument type #5293

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions qcodes/instrument/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import time
import weakref
from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, Protocol, TypeVar, cast, overload
from typing import TYPE_CHECKING, Any, Protocol, TypeVar, overload

from qcodes.utils import strip_attrs
from qcodes.validators import Anything
Expand Down Expand Up @@ -270,7 +270,9 @@ def find_instrument(cls, name: str, instrument_class: type[T]) -> T:
...

@classmethod
def find_instrument(cls, name: str, instrument_class: type[T] | None = None) -> T:
def find_instrument(
cls, name: str, instrument_class: type[T] | None = None
) -> T | Instrument:
"""
Find an existing instrument by name.

Expand Down Expand Up @@ -301,10 +303,7 @@ def find_instrument(cls, name: str, instrument_class: type[T] | None = None) ->
f"Instrument {name} is {type(ins)} but "
f"{internal_instrument_class} was requested"
)
# at this stage we have checked that the instrument is either of
# type instrument_class or Instrument if that is None. It is
# therefore safe to cast here.
ins = cast(T, ins)

return ins

@staticmethod
Expand Down