Mystifying message from ruff

I installed ruff today and messed around a little with its check command. I found one message in particular confusing/useless:

[I001] Import block is un-sorted or un-formatted

As far as I could tell, it didn’t like any of my blocks of import statements. When I looked it up, I was still confused. Here’s one block of imports it complained about in a small script:

import argparse
import os
import pickle                           # nosec
import sys

The imports are sorted as far as I can tell and all are stdlib modules. I don’t understand what it’s complaining about at all. The script has a blank line before and after the imports.

I poked around, but found nothing in the way of obvious answers or pointers to any sort of help community, so here I am. Pointers and/or explanations appreciated.

Doesn’t seem to like all the white spaces between your import and comment.

What @bsdz said.

fwiw, isort complains the same too. So the behaviour is consistent between ruff and isort.

$ cat imports.py 
import argparse
import os
import pickle                           # nosec
import sys

_ = argparse
_ = os
_ = pickle
_ = sys

(.venv) /tmp/app$ isort imports.py --check --diff
ERROR: /tmp/app/imports.py Imports are incorrectly sorted and/or formatted.
--- /tmp/app/imports.py:before  2026-07-26 20:11:52.050156
+++ /tmp/app/imports.py:after   2026-07-26 20:12:12.576898
@@ -1,6 +1,6 @@
 import argparse
 import os
-import pickle                           # nosec
+import pickle  # nosec
 import sys
 
 _ = argparse
(.venv) /tmp/app$ isort imports.py
Fixing /tmp/app/imports.py
(.venv) /tmp/app$ ruff check imports.py
All checks passed!

ruff check imports.py --fix

would have fixed it as well.

Thanks, not willing to turn over (re)formatting to a tool I’ve never used before. I’ve been using one version of Emacs’ python-mode or another for ~30 years. I’ll figure out how to suppress what to me are spurious messages.