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

Emitting underscores in integers #336

Open
robertlagrant opened this issue Mar 19, 2024 · 2 comments
Open

Emitting underscores in integers #336

robertlagrant opened this issue Mar 19, 2024 · 2 comments

Comments

@robertlagrant
Copy link

robertlagrant commented Mar 19, 2024

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.

@JamesParrott
Copy link

JamesParrott commented Mar 20, 2024

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

@robertlagrant
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants