Implement remaining ruff 0.16 lints - #8368
Draft
jenshnielsen wants to merge 7 commits into
Draft
Conversation
Instrument driver modules that are part of the public qcodes namespace cannot be renamed without breaking user code, so they are exempted via lint.pep8-naming.extend-ignore-names. Test modules with invalid names are renamed to lower case. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8be348f8-5322-4e8d-b75a-3d00baca556f
Update the Contributor guide and the "Creating Instrument Drivers" example notebook to state that driver modules should be named using lower case snake_case, with vendor/model capitalization only in the class name. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8be348f8-5322-4e8d-b75a-3d00baca556f
Rename the private module level loggers `_LOG` to `_LOGGER` so that ruff recognises them as loggers, switch several catch-all handlers to `Logger.exception` so that the traceback is logged, narrow the exceptions caught in the Triton driver, chain the exception raised by AWG70000A and explicitly mark the remaining intentional catch-alls with `noqa: BLE001`. The example notebooks deliberately catch broad exceptions to demonstrate that an operation is rejected, so `docs/*` ignores the rule. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8be348f8-5322-4e8d-b75a-3d00baca556f
`Station.add_component` now logs the traceback when snapshotting a component fails rather than silently swallowing it. The test cleanup fixture uses `contextlib.suppress`. The remaining silent handlers are in teardown paths (`Instrument.__del__` and `strip_attrs`) that must never raise and must not log since the logging machinery may already be torn down, so they are explicitly marked as intentional. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8be348f8-5322-4e8d-b75a-3d00baca556f
Replace the bare `Exception` raised in a number of drivers with a specific builtin exception: `ValueError` for invalid arguments, `RuntimeError` for using the instrument in an unsupported state and `NotImplementedError` for the unimplemented AlazarTech ATS acquisition modes. All of these are subclasses of `Exception` so existing code that catches `Exception` is unaffected. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8be348f8-5322-4e8d-b75a-3d00baca556f
Now that the drivers raise specific exceptions, several of the handlers added when enabling BLE001 can be narrowed to the exceptions that the guarded code actually raises: `VisaIOError` when waiting for the AWG5014, `OSError`/`VisaIOError` when reading an Infiniium screenshot, the `OSError` raised by `check_for_error` when aborting a SignalHound acquisition and the subprocess/json errors when querying pip. The remaining blind handlers guard user supplied validators, arbitrary module imports and teardown paths, so their `noqa` comments now state why. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8be348f8-5322-4e8d-b75a-3d00baca556f
New code should raise `TypeError` when rejecting a value because of its type. The 46 existing type checks that raise `ValueError` or `RuntimeError` are deliberately left unchanged and marked with `noqa: TRY004`: `TypeError` is not a subclass of either, so changing them would break user code that catches the current exception. `RUF100` will flag the `noqa` as unused if such a call site is ever changed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8be348f8-5322-4e8d-b75a-3d00baca556f
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #8368 +/- ##
=======================================
Coverage 71.09% 71.10%
=======================================
Files 305 305
Lines 31934 31933 -1
=======================================
Hits 22705 22705
+ Misses 9229 9228 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
No description provided.