ikamensh / flynt

A tool to automatically convert old string literal formatting to f-strings
MIT License
689 stars 33 forks source link

Handle %s strings with length and alignment #194

Open Lalufu opened 1 year ago

Lalufu commented 1 year ago

%s format strings allow for padding and alignment, but their behaviour is very different from fstrings.

%20s will pad a string to 20 characters, and right align %-20s will pad a string to 20 characters, and left align

This behaviour is carried over from the C *printf() functions.

This patch adds the ability to properly convert these to fstrings, using the correct alignment markers.

The feature is gated behind aggressive mode for now.

The earlier code did already convert %20s, but changed the alignment (the resulting fstring would be left aligned instead of right), and did not understand %-20s at all.