Skip to content

Commit

Permalink
Merge pull request #5293 from jenshnielsen/find_instrument_type
Browse files Browse the repository at this point in the history
simplify find_instrument type
  • Loading branch information
jenshnielsen committed Jul 31, 2023
2 parents b6725a5 + b3c21fd commit 29097cb
Showing 1 changed file with 5 additions and 6 deletions.
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

0 comments on commit 29097cb

Please sign in to comment.