-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Formatter: Bug with Pragma Comment for pyright being moved to invalid position #8481
Comments
Any help would be greatly appreciated! I hoped it would be fixed here - #8431? But it does seem to be along the same avenue. |
Can you provide the original source code? The way you're describing the comment place, is it like this: # pyright: ignore[reportUnknownVariableType]
for a in
( Or, for a in # pyright: ignore[reportUnknownVariableType]
( |
It should be the second one. The code that I shared should show the same result that I am describing. Are you not able to reproduce it? |
Unfortunately I can't even use def test_function(
very_long_dictionary: dict, # pyright:ignore
):
something = [
a["foo"]
for a in # pyright: ignore[reportUnknownVariableType]
( # fmt:skip <- Needed to add this here
very_long_dictionary.get(
"longer_key_name" # pyright: ignore
)
or []
)
] |
Okay I got a way to reproduce this on terminal as it happens consistently in VSCode but not in terminal... Context: The most important line is where the Code is in file test.py # test.py
def test_function(
very_long_dictionary: dict, # pyright:ignore
):
something = [
a["foo"]
for a in # pyright: ignore[reportUnknownVariableType]
(
very_long_dictionary.get(
"longer_key_name" # pyright: ignore
)
or []
)
] Step 2. Run # test.py
def test_function(
very_long_dictionary: dict, # pyright:ignore
):
something = [
a["foo"]
for a in ( # pyright: ignore[reportUnknownVariableType]
very_long_dictionary.get(
"longer_key_name" # pyright: ignore
)
or []
)
] Step 3. Run # test.py
def test_function(
very_long_dictionary: dict, # pyright:ignore
):
something = [
a["foo"]
for a in
( # pyright: ignore[reportUnknownVariableType]
very_long_dictionary.get(
"longer_key_name" # pyright: ignore
)
or []
)
] |
I think this maybe be related to this other issue that I am creating to take about differences in no_cache. |
@MichaReiser Do you have any code pointers of why there might be instability here? I'm trying to look at #8431 to see if there is anything there but uncertain. |
This isn't related to caching but is an instability bug where the formatter requires two passes to reach the ultimate formatting (unfortunately, the worse). You can see this in the Playground where I copied the formatted code of the input as the second example. The issue comes from that the comment is a dangling comment of the comprehension when formatting the input source, but becomes a leading comment of A workaround to unblock you is to suppress formatting of the entire statement: something = [
a
for a in # pyright: ignore[reportUnknownVariableType]
(
b.get(
"longer_key_name",
)
)
] # fmt: skip |
This has been fixed by #12282 (preview only) |
Thank you so much! ❤️ |
Trying to enable ruff formatter on my repo and am getting an error when using in conjunction with a #pyright pragma comment. Its a bit convoluted of an example but this does error out. The
# pyright: ignore[reportUnknownVariableType]
should apply to thefor a in
line however keeps getting moved to where the parentheses is. If I try and move the parentheses or comment to the same line, it moves it back to what it looks like below. Interesting enough, in VsCode it moves the parentheses on the first save and then moves parentheses and comment later again on subsequent saves/running from terminal.Code example:
Running on ruff v0.1.3. Edit: Error still shows up on v0.1.4.
No specific rules for ruff format and config looks like this
The text was updated successfully, but these errors were encountered: