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

Change string formatting #147

Merged
merged 19 commits into from
Oct 24, 2021
Merged

Change string formatting #147

merged 19 commits into from
Oct 24, 2021

Conversation

psolyca
Copy link
Collaborator

@psolyca psolyca commented Dec 1, 2020

Strings formatting changes :

  • Fix TypeError in LandXML issue [BUG]potential type error #146
  • Concat strings ("" + "") to F-Strings
  • Old style (%) to F-Strings
  • Formatted strings (.format()) to F-Strings
  • Specific case of scanwin32.py
  • specific case of gettext strings

@psolyca psolyca changed the title [WIP] Change string formatting Change string formatting Dec 1, 2020
@steko
Copy link
Collaborator

steko commented Dec 1, 2020

@psolyca
Copy link
Collaborator Author

psolyca commented Dec 2, 2020

I have tried with flynt but it did not catch all strings. Do not know why !
I have also tried pyupgrade but that is worse, nothing had changed ^^
So I already have all my strings changed except gettext strings but I am making another pass to check everything is ok.

@psolyca
Copy link
Collaborator Author

psolyca commented Dec 2, 2020

@steko So looking at gettext and translation, F-Strings can not be used as-is.
We should keep the old style % syntax or the .format() one.
For the last one, we have to change all %s in .po files to {}. I do not think if it is worth it.

If we want to stick to F-Strings, a workaround is here https://stackoverflow.com/a/56264202 and we can modify our _ function.

@steko
Copy link
Collaborator

steko commented Dec 2, 2020

You did a huge work!

The straightforward approach seems to use f-strings everywhere, except where gettext is needed, and use .format() with gettext.

Or we could standardize on using .format() everywhere.

But most importantly we need to move away from implicit conversion and formatting.

@psolyca
Copy link
Collaborator Author

psolyca commented Dec 2, 2020

I thought of using .format() everywhere but it is claimed to be slower than F-Strings.
And % is faster than .format() : https://stackoverflow.com/questions/40714555/python-string-formatting-is-more-efficient-than-format-function
So maybe we can keep % for little string formatting as gettext could be.

@steko
Copy link
Collaborator

steko commented Dec 2, 2020

You did a huge work!

The straightforward approach seems to use f-strings everywhere, except where gettext is needed, and use .format() with gettext.

Or we could standardize on using .format() everywhere.

But most importantly we need to move away from implicit type conversion and formatting, adopting a consistent code style.

@steko
Copy link
Collaborator

steko commented Dec 3, 2020

On a second thought, perhaps the easiest solution is to use f-strings in the totalopenstation package, and %-formatting in the scripts directory. We don't need gettext in the package, only in the command line and GUI scripts.

@psolyca
Copy link
Collaborator Author

psolyca commented Dec 3, 2020

So I revert scripts files ?
Not a huge fan :p

@psolyca psolyca marked this pull request as ready for review September 26, 2021 19:50
@steko steko added this to the v0.6 milestone Oct 18, 2021
@steko
Copy link
Collaborator

steko commented Oct 21, 2021

@psolyca what do you think about the documentation I added? I thought it was important to document what we had decided and you implemented in this PR.

@psolyca
Copy link
Collaborator Author

psolyca commented Oct 21, 2021

Yes, good for me. I was surprised by the "user-facing" term as I am more used to front-end but it is a legit term.

I let you review this PR, I won't do it, it is not fair :p

docs/contributing/main.rst Outdated Show resolved Hide resolved
@steko steko merged commit ce72d54 into main Oct 24, 2021
@steko steko deleted the fix/string_formatting branch October 24, 2021 12:20
Copy link
Collaborator Author

@psolyca psolyca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok good to go.
When you do not read everything, you are one step behind ^^;

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

Successfully merging this pull request may close these issues.

None yet

2 participants