-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Potential inconsistency between Ruff's I
and isort
#2104
Comments
This does look like an incompatibility. I think the thing to decide is whether it's a known and accepted deviation, or not :) Do you have a preference between the outputs? Did it cause any problems, or the issue is more that it deviated at all? |
Personally, I like Ruff's variant more as it keeps imports from a specific module in one statement. I don't know if the |
Ruff will respect that noqa in both cases, but I don't think Flake8 respects the version that Ruff outputs. |
This is the case for me, we run both isort and Ruff in continuous integration testing so either will fail unless an ungainly I don't particularly mind which style 'wins'. A |
I prefer isort's output here as it is more granular for the ignores/disables to work. from dvc.api.data import open # pylint: disable=redefined-builtin
from dvc.api.data import read
__all__ = ["read", "open"]
--- script.py
+++ script.py
@@ -1,4 +1,6 @@
-from dvc.api.data import open # pylint: disable=redefined-builtin
-from dvc.api.data import read
+from dvc.api.data import (
+ open, # pylint: disable=redefined-builtin
+ read,
+)
__all__ = ["read", "open"] And, script.py:1:0: W0622: Redefining built-in 'open' (redefined-builtin) |
Yeah I think we should likely change this going forward given the handling of action comments. |
Sure it can, you just need to move the comment to the right line. from dvc.api.data import ( # pylint: disable=redefined-builtin
open,
read,
)
__all__ = ["read", "open"] Ruff can’t be sure in advance which line the comment belongs on (and honestly, its first guess makes more sense), but once you put it on the right line, Ruff will leave it there. |
I'm going to close this for now as an intentional deviation. If we receive more reports or more feedback on it, as always, I'll reconsider. |
I believe this is distinct from #1718; cross-linking in case there are similarities, though.
isort version: 5.11.4
Ruff version: 230
isort config:
Commands:
Note Ruff wants to re-format to:
whereas
isort
wants to reformat to:This appeared in the Sphinx project where some imports are type-comment only (e.g. in giving type annotations to iterators, where the pattern is
for item in items: # type: blah`, should MyPy not be able to deduce the type of
item``).A
The text was updated successfully, but these errors were encountered: