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

'!' flag doesn't add space in "no-prefix" case #4

Closed
polyanskiy opened this issue Jan 10, 2023 · 5 comments
Closed

'!' flag doesn't add space in "no-prefix" case #4

polyanskiy opened this issue Jan 10, 2023 · 5 comments

Comments

@polyanskiy
Copy link

Very useful package!
I am using it with a '!' flag to display an output of a joulemeter with a space between the number and the unit for better readability. This works fine except the 1--1000 "no-prefix" range: in this case no space is added.

f'{Float(0.123):!.3H}J'
'123 mJ'
f'{Float(123):!.3H}J'
'123J'
f'{Float(123000):!.3H}J'
'123 kJ'
@avylove
Copy link
Contributor

avylove commented Jan 10, 2023

@polyanskiy, thanks for reporting this.

You're right, I can see where that is happening and why you would want the space. I think this was an oversight on my part.

The problem I have is how to handle a case where a space is not desired. For example, if you're not adding anything after the prefix. Ideally, both cases could be handled intuitively. I'd like to think on it before I implement something. My currently thought is a double flag !! could specify to trim the space when no prefix is listed, but I'm not sure if that would be consistent with the regular Python spec.

What are your thoughts on it?

@polyanskiy
Copy link
Author

polyanskiy commented Jan 10, 2023

hmm... I don't see how to handle this without a different flag (or a double flag as you suggest).
... Actually, is there a realistic situation when the space is needed other than for separating the unit from the number? I mean, when a prefix is used to simply shorten the number (e.g., "$1M"), the space is never used.

@avylove
Copy link
Contributor

avylove commented Jan 12, 2023

You never really know how someone is going to use a library. It's best to be flexible and non-opinionated.
Regardless, I think the behavior for ! should be consistent. I pushed a commit that fixes the behavior. Please confirm it works for you. I'll do a release soon.

@polyanskiy
Copy link
Author

polyanskiy commented Jan 12, 2023

It's working!
Thanks
image image

@avylove
Copy link
Contributor

avylove commented Jan 15, 2023

Fixed and added !! flag in 0.6.0. Thanks for reporting!

@avylove avylove closed this as completed Jan 15, 2023
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