Skip to content
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

String alignment is broken #138

Open
giampaolo opened this issue Sep 15, 2022 · 3 comments
Open

String alignment is broken #138

giampaolo opened this issue Sep 15, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@giampaolo
Copy link

In python "%Ns" can be used to align strings, e.g.

>>> print("hello %30s" % "world")
'hello                          world'

flynt --aggressive erroneously convert the above statement to:

print(f"hello {'world':30}")

Instead it should be converted to:

print(f"hello {'world':>30}")
@ikamensh ikamensh added the bug Something isn't working label Sep 15, 2022
@ikamensh
Copy link
Owner

Thanks for the report.

So the default alignment differs, giving no specifier means right aligned in %; but is left-aligned in fstring/.format. Any exceptions or corner cases you know?

@giampaolo
Copy link
Author

Mmm.. I suppose there should be 2 conversions:

1:

print("hello %30s" % "world")
print(f"hello {'world':>30}")

2:

print("hello %-30s" % "world")
print(f"hello {'world':<30}")

@ikamensh
Copy link
Owner

should be solved by #194

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants