-
-
Notifications
You must be signed in to change notification settings - Fork 307
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
hatch fmt
leads to unresolvable ruff
setting conflict with from __future__ import annotations
#1459
Comments
The solution would be to run just the formatter first via |
Hmm, running |
You would have to add configuration for that, see the config file in this repo |
Ah, so |
No it does but what's happening is that the linter comes first followed by the formatter and you're encountering an error in the former so the only way is to run the other one separately. This is a known issue where everything is not yet cohesive which is why they have a plan to only have a single command, and also the reason I have implemented this as a single command in preparation for that future. |
I see! Thanks. Let me continue to play around with it. |
I still have to add the https://gitlab.com/warsaw/public/-/blob/hatch-fmt/src/public/public.py#L3 |
I'm confused, why is it trying to move the import somewhere other than the top? |
Great question! I'm confused why it wants to do that too. |
Fixed? |
Nope, even with ruff 0.4.3. |
You provide a minimal reproducible example file and open up an issue over there? |
So, you don't think it's a |
If you can provide a very small file to reproduce we could test by just enabling that single offending rule. |
I don't know if this is reproducible outside the repository, but the file triggering the problem is public.py. Another way to reproduce it is: $ git clone https://gitlab.com/warsaw/public.git
$ cd public
# Edit src/public/public.py to remove the noqa comment from the future import line
$ hatch fmt --check src
src/public/public.py:7:1: I001 [*] Import block is un-sorted or un-formatted
Found 1 error.
[*] 1 fixable with the `--fix` option.
$ hatch fmt src
src/public/public.py:11:1: F404 `from __future__` imports must occur at the beginning of the file
Found 2 errors (1 fixed, 1 remaining).
$ git diff
diff --git a/src/public/public.py b/src/public/public.py
index 96bd404..bbe8d7f 100644
--- a/src/public/public.py
+++ b/src/public/public.py
@@ -4,11 +4,12 @@
# and linter will be in conflict between I001 and F404 (which wants to move
# this import to below `import sys`. Ruff's unified linter and formatter
# will hopefully resolve this: https://github.com/astral-sh/ruff/issues/8232
-from __future__ import annotations # noqa: I001
-
import sys
-from typing import Any, TYPE_CHECKING, overload
+from typing import TYPE_CHECKING, Any, overload
+
+from __future__ import annotations
+
if TYPE_CHECKING:
from .types import ModuleAware
|
Disable Hatch static analysis config: https://hatch.pypa.io/latest/config/internal/static-analysis/#no-config |
Sorry, are you saying that this is not a bug in hatch, or it is caused by the ruff lint/formatter problem? One thing that I think would help to debug further is to be able to print the commands hatch is running with higher verbosity in |
I'm not precisely sure what caused the issue but I thought that you weren't extending when in fact you seem to be doing so. I wonder what happens when you try the persistent config approach. |
Let's start with this branch: https://gitlab.com/warsaw/public/-/tree/hatch-fmt
Specifically, the
src/public/public.py
file starts with these lines:Running
hatch fmt check
gives me this error:and would make this change:
Let's let hatch fix it:
Uh oh! The
I001
andF404
can't be resolved without ignoring one or the other. Since__future__
imports should go at the top, it's probably better to ignore theI001
but such a blanket ignore could hide other import sorting issues.The text was updated successfully, but these errors were encountered: