-
Notifications
You must be signed in to change notification settings - Fork 351
Change return type of root_instrument to Instrument #7924
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ | |
|
|
||
| if TYPE_CHECKING: | ||
| from collections.abc import Callable, Mapping, Sequence | ||
| from typing import NotRequired | ||
| from typing import NotRequired, Self | ||
|
|
||
| from qcodes.instrument.channel import ChannelTuple, InstrumentModule | ||
| from qcodes.logger.instrument_logger import InstrumentLoggerAdapter | ||
|
|
@@ -579,7 +579,7 @@ def ancestors(self) -> tuple[InstrumentBase, ...]: | |
| return (self,) | ||
|
|
||
| @property | ||
| def root_instrument(self) -> InstrumentBase: | ||
| def root_instrument(self) -> Self: | ||
|
||
| """ | ||
| The topmost parent of this module. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -526,7 +526,10 @@ def __init__( | |||||
| ) | ||||||
|
|
||||||
| @property | ||||||
| def root_instrument(self) -> "KeysightInfiniium": | ||||||
| def root_instrument(self) -> "KeysightInfiniium": # type: ignore[override] | ||||||
| # ideally this should be a generic type parameter but | ||||||
| # for now we override it here. This requies a mypy ignore | ||||||
|
||||||
| # for now we override it here. This requies a mypy ignore | |
| # for now we override it here. This requires a mypy ignore |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -142,7 +142,10 @@ def __init__( | |||||
| """Parameter digital_gain""" | ||||||
|
|
||||||
| @property | ||||||
| def root_instrument(self) -> "KeysightM9336A": | ||||||
| def root_instrument(self) -> "KeysightM9336A": # type: ignore[override] | ||||||
| # ideally this should be a generic type parameter but | ||||||
| # for now we override it here. This requies a mypy ignore | ||||||
|
||||||
| # for now we override it here. This requies a mypy ignore | |
| # for now we override it here. This requires a mypy ignore |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -300,7 +300,10 @@ def __init__( | |||||
| """Parameter polar""" | ||||||
|
|
||||||
| @property | ||||||
| def root_instrument(self) -> "KeysightPNABase": | ||||||
| def root_instrument(self) -> "KeysightPNABase": # type: ignore[override] | ||||||
| # ideally this should be a generic type parameter but | ||||||
| # for now we override it here. This requies a mypy ignore | ||||||
|
||||||
| # for now we override it here. This requies a mypy ignore | |
| # for now we override it here. This requires a mypy ignore |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -355,7 +355,10 @@ def __init__( | |||||
| """Parameter trace""" | ||||||
|
|
||||||
| @property | ||||||
| def root_instrument(self) -> "TektronixDPO7000xx": | ||||||
| def root_instrument(self) -> "TektronixDPO7000xx": # type: ignore[override] | ||||||
| # ideally this should be a generic type parameter but | ||||||
| # for now we override it here. This requies a mypy ignore | ||||||
|
||||||
| # for now we override it here. This requies a mypy ignore | |
| # for now we override it here. This requires a mypy ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment describes walking the parent hierarchy to locate the root, but the implementation simply returns
self._parent.root_instrumentwith acast. This makes the comment misleading and also relies oncast(type-only) rather than a runtime check. Consider either (a) simplifying/updating the comment to match the implementation and invariants, and/or (b) using a runtimeisinstance(..., Instrument)assertion (similar to the driver overrides in this PR) to enforce the contract that the channel’s root is anInstrument.