Skip to content

ruff fix on UP032 breaks applied code when f-string is too long #7891

Closed
@Grosskopf

Description

Hi, I'm not sure where I should post this error but I have a weird chain reaction of errors that result in ruff breaking my code.

The following code results in a UP032 Error:

from django.utils.translation import gettext

long = 'long'
split_to = 'split_to'
gettext(
    'some super {} and complicated string so that the error code '
    'E501 Triggers when this is not {} multi-line'.format(
        long, split_to)
)

when I then run ruff --fix on it I get

from django.utils.translation import gettext

long = 'long'
split_to = 'split_to'
gettext(
    f'some super {long} and complicated string so that the error code '
    f'E501 Triggers when this is not {split_to} multi-line'
)

This would be perfect, I love the style of code, but there is a problem, this code does not work.
When I then go ahead and run makemessages as usual, the text generated from this is
some super {long} and complicated string so that the error code and the second line is lost

Should I report this upstream at Django or at python? I would prefer if this would work but sadly this is a rare edge case where ruff --fix breaks code.

this happens on ruff 0.0.290

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions