tomlkit icon indicating copy to clipboard operation
tomlkit copied to clipboard

Emitting underscores in integers

Open robertlagrant opened this issue 5 months ago • 2 comments

TOML allows an underscore anywhere in an integer, as long as there is a digit each side of it:

For large numbers, you may use underscores between digits to enhance readability. Each underscore must be surrounded by at least one digit on each side.

int5 = 1_000
int6 = 5_349_221
int7 = 53_49_221  # Indian number system grouping
int8 = 1_2_3_4_5  # VALID but discouraged

I'd like to be able to emit an underscore-formatted integer when dump/sing a TOML file.

This is probably quite hard to implement with full flexibility, but it would be good to either be able to indicate some level of customisation, e.g. "use an underscore to indicate 100s" or "use an underscore to indicate 1000s", or alternatively to be able to supply a _-formatted integer as a string, and have tomlkit render it as a number, without quotation marks.

Happy to discuss if there's interest. Otherwise I can try a PR, but I'd rather get some consensus first.

robertlagrant avatar Mar 19 '24 17:03 robertlagrant

Apologies Robert. I've just realised this is a proposal for tomlkit.dump and tomlkit.dumps

JamesParrott avatar Mar 20 '24 12:03 JamesParrott

Ah I didn't even consider that! I'll make it a bit clearer.

robertlagrant avatar Mar 21 '24 11:03 robertlagrant