Deprecate legacy top level exports#8294
Merged
jenshnielsen merged 8 commits intoJul 16, 2026
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8294 +/- ##
==========================================
- Coverage 71.12% 71.11% -0.01%
==========================================
Files 305 305
Lines 32001 32004 +3
==========================================
Hits 22760 22760
- Misses 9241 9244 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jenshnielsen
enabled auto-merge
July 14, 2026 22:33
The eager imports of the dataset, instrument, parameters, monitor and
station submodules in ``qcodes/__init__.py`` glued 83 modules into a
single import cycle. Combined with a generic ``ParameterBase`` whose
TypeVar default forward-references ``InstrumentBase`` and the
``ParamMeasT`` union alias used in a ``TypedDict``, this triggered an
internal error in mypy 2.2 ("Must not defer during final iteration").
Expose the discouraged top-level shorthands (``qcodes.Parameter``,
``qcodes.Measurement``, etc.) lazily via a module level ``__getattr__``
instead. This breaks the cycle so ``mypy src`` succeeds again. The
shorthands remain available at runtime but are intentionally no longer
statically typed; import from the respective submodules for type info.
The ``atexit`` handler that closes all instruments is moved into
``qcodes.instrument`` so importing the top level package no longer
eagerly imports the instrument submodule.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 05b20136-29a2-4bfe-834c-894d3efa9d4c
The parameter classes (Parameter, ManualParameter, DelegateParameter, etc.) were re-exported from qcodes.instrument for backwards compatibility. These now live in qcodes.parameters. Access them via a module level __getattr__ that emits a QCoDeSDeprecationWarning, and update the Legacy_Parameters example to import ArrayParameter from qcodes.parameters. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 05b20136-29a2-4bfe-834c-894d3efa9d4c
Expose qcodes.validators via the module level __getattr__ instead of importing it eagerly on 'import qcodes', keeping the top level import cheap. Also tidy the now-stale module comment and update the newsfragment. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 05b20136-29a2-4bfe-834c-894d3efa9d4c
Guard the module level __getattr__ in qcodes and qcodes.instrument behind 'if not TYPE_CHECKING' so the lazily provided short hands and deprecated parameter re-exports are reported as unknown attributes by static type checkers instead of silently resolving to Any. Runtime behaviour is unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 05b20136-29a2-4bfe-834c-894d3efa9d4c
Accessing the short hand aliases (qcodes.Parameter, qcodes.Measurement, qcodes.Monitor, qcodes.Station, etc.) from the top level qcodes namespace now emits a QCoDeSDeprecationWarning; import them from their respective submodules instead. The submodules these names live in (dataset, instrument, parameters, monitor, station) are added to the lazily imported submodules so that qcodes.dataset and friends keep working once the deprecated short hands are removed. validators is unchanged and not deprecated. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 05b20136-29a2-4bfe-834c-894d3efa9d4c
Verify that the deprecated short hand aliases on the top level qcodes namespace and the parameter classes re-exported from qcodes.instrument still resolve to the correct objects while emitting a QCoDeSDeprecationWarning. The direct attribute accesses are also intentionally type errors, silenced with '# type: ignore[attr-defined]' pragmas to document that behaviour. Also check that non-deprecated submodule access is warning free and that unknown attributes raise AttributeError. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 05b20136-29a2-4bfe-834c-894d3efa9d4c
The deprecation of the top level qcodes short hands and the qcodes.instrument parameter re-exports is a change to the public API, so classify the newsfragment as breaking rather than improved. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 05b20136-29a2-4bfe-834c-894d3efa9d4c
jenshnielsen
force-pushed
the
avoid_top_level_export
branch
from
July 16, 2026 16:49
9c03747 to
e72b589
Compare
jenshnielsen
force-pushed
the
avoid_top_level_export
branch
from
July 16, 2026 16:54
e72b589 to
96db6db
Compare
astafan8
approved these changes
Jul 16, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to no response for status checks
Jul 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The main benefits of the import changes are significantly faster import of qcodes top level module + a much smaller set of interconnected modules during type checking