Openage: Use Python 3.6 f-strings

Created on 3 Nov 2020  路  6Comments  路  Source: SFTtech/openage

Python formatted strings are much better to read and supposedly faster than %-formatted strings. Our python code uses a bunch of %-formatted strings which could be replaced with f-string syntax.

Example

Current %-formatted syntax:

ability_ref = "%s.%s" % (game_entity_name, ability_name)

f-string syntax:

ability_ref = f"{game_entity_name}.{ability_name}"
code quality improvement python

Most helpful comment

I will be reviewing everything, but it seams it does it perfectly 100% of the time, though I have reverted some changes, since I am not 100% sure (and not able to properly test). But yeah, I will have 95% converted, and will flag the rest, by the end of this week.

All 6 comments

I am on it, have done something similar in an equally big project successfully with flynt.
https://pypi.org/project/flynt/

Hopefully flynt can deal with some of the more messy code blocks :)

I will be reviewing everything, but it seams it does it perfectly 100% of the time, though I have reverted some changes, since I am not 100% sure (and not able to properly test). But yeah, I will have 95% converted, and will flag the rest, by the end of this week.

@TobiasFP If you want you can already make a PR and have me double-check the results from flynt. I will probably be able to spot most errors quickly.

Thansk.
Just finishing up now.
There might be some small issues, like in:
strings.py:
colorized = 'x1b[{colorcode}m{string}x1b[m'.format(
colorcode=colorcode, string=string)

I think the x1b is a problem for flynt, which is why I have reversed (hopefully) all these conversions.
99% of the conversion is fine though.

I'll now test for all games. If the converter runs through for them, there's not much breakage to worry about.

Edit: Works!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TheJJ picture TheJJ  路  11Comments

momo-aux picture momo-aux  路  10Comments

kevinmartinjos picture kevinmartinjos  路  4Comments

LeandroStanger picture LeandroStanger  路  9Comments

k3x picture k3x  路  7Comments