-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[WIP] Add ruff configuration to pyproject.toml #9586
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
Conversation
modified: qiskit/algorithms/amplitude_estimators/ae_utils.py
This comment was marked as off-topic.
This comment was marked as off-topic.
qiskit/utils/mitigation/circuits.py
Outdated
@@ -114,10 +114,10 @@ def complete_meas_cal( | |||
|
|||
def tensored_meas_cal( | |||
mit_pattern: List[List[int]] = None, | |||
qr: Union[int, List["QuantumRegister"]] = None, | |||
cr: Union[int, List["ClassicalRegister"]] = None, | |||
qr: Union[int, List["QuantumRegister"]] = None, # noqa: F821 |
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 docs say that F821 is an "undefined name error" -- do you think this is that because the type is in quotes?
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.
Yes. That's it. I did not track down the reasoning. Of course, the name is in quotes precisely because the symbol is not defined. Maybe some people don't think this should be done, so there is a rule ?
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.
So the interesting thing is black isn't happy with this PR: Can you also update the Also we probably should add |
"qiskit/transpiler/passes/scheduling/calibration_creators.py" = ["F401"] | ||
"qiskit/transpiler/passes/scheduling/rzx_templates.py" = ["F401"] | ||
|
||
|
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.
Per the ruff docs and some of your comments on docstrings in #1179 I'm wondering if we want to add
[tool.ruff.pydocstyle]
convention = "google"
here too
https://github.com/charliermarsh/ruff#does-ruff-support-numpy--or-google-style-docstrings
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.
That's certainly worth trying.
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.
I added some doc string checks. But in order to make this more manageable, I plan to instead defer them to a later PR (provided we actually make a switch to ruff) However, several doc string errors/suggestions made by ruff have been merged in recent PRs.
I think Black's problems are real, and somewhat unrelated to Ruff - in the couple of places I spot-checked, it's because there's been a suppression comment added that doesn't follow the Black rules. Same-line comments need to be separated from the content by two spaces. Black should be able to autofix them. |
That should be compatible with ruff. |
Yeah sorry, I'm just saying that I don't think you've run black is all - no big deal. |
That's right. I was not clear on that point. I did not yet run black. But I need to do that. |
Ruff generates a |
…ssign a `lambda` expression, use a `def`" This reverts commit 93a2bd0.
This reverts commit d577c4c.
…:39:9: E731 [*] Do not assign a `lambda` expression, use a `def`" This reverts commit de596c1.
…format" This reverts commit 2863fd4. The reason for making these changes is not clear. A desired policy for formatting should be decided if we want to enforce a rule.
The output object is different with this change. So undo it.
The comments here remain useful, but I am closing this PR to avoid confusion. The current good PR is #10116 |
EDIT I will close this PR as we can still refer to it when closed. But it will continue to cause confusion if it remains open.
EDIT This PR is obsolete, replaced by #10116 . The latter PR is a much smaller, more incremental way forward. I am leaving this open as a draft because the discussion will be useful for possible further ruff PRs.
This PR is an experiment in using ruff, a linting tool, as suggested by @mtreinish (#1179 (comment)). The intent is to allow people to experiment withruff
onqiskit-terra
without committing yet to using it in CI.This PR replaces
pylint
withruff
for linting qiskit-terra. I have added several more lint tests to theruff
configuration that are not included in this PR. They will be included in a following PR, as this one is already fairly large.This PR should not be merged before #9689 and #9690 are. I'll also remove rules that reviewers object to or find questionable. Some of these can be reviewed in a subsequent PR.
The main
, or perhaps only,advantage that we expect at present is an increase in performance over pylint. The gain is indeed large; two or three orders of magnitude. Usingruff
also makes it easy to add pyflake plugins (reimplemented in Rust) that execute very quickly. On my thinkpadruff check qiskit test
finishes in about 350ms with an empty cache28ms.The set of lint checks included in this PR is not the same as the previous (pylint) set. And neither is a subset of the other.
Configuration
I have configured ruff in
pyproject.toml
. Alternatively, we could use a ruff-only config file.tox
is configured to useruff
rather thanpylint
. CI has also been switched frompylint
toruff
.It includes a bit of configuration in
pyproject.toml
. It also disables some checks on a line-by-line basis with# noqa: XXX
.TODO
I disabled some tests in particular files via configuration inThese ought to done instead viapyproject.toml
.# noqa:
comments in the files.You can run> ruff check test
. But you'll get many errors, as I did not yet correct or disable these.~~
Notes
E401
. I don't prefer this because it may not be obvious what you are disabling. But maybe there is a way to use a semantic tag. [EDIT: It appears there is no way.]