jameslamb / doppel-cli

Test framework for comparing the consistency of library APIs
https://doppel-cli.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
8 stars 12 forks source link

Replace uses of .format() with f-strings #204

Closed jameslamb closed 2 years ago

jameslamb commented 2 years ago

If you run the following from the root of this repo.

pip install --upgrade pylint
pylint doppel/ | grep consider-using-f-string

You'll see the following warnings.

doppel/describe.py:68:16: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
doppel/describe.py:71:14: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
doppel/describe.py:78:22: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
doppel/describe.py:81:14: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
doppel/describe.py:97:16: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
doppel/describe.py:103:14: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
doppel/DoppelTestError.py:17:15: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
doppel/PackageAPI.py:47:18: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
doppel/reporters.py:104:25: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
doppel/reporters.py:107:29: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
doppel/reporters.py:136:27: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
doppel/reporters.py:184:28: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
doppel/reporters.py:292:27: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
doppel/reporters.py:340:28: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
doppel/reporters.py:407:31: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)

These should be converted to use f-strings. So for example.

# before
"Could not figure out what {} is".format(obj_name)

# after
f"Could not figure out what {obj_name} is"

I'd welcome a pull request that converts these cases to f-strings.

How this improves doppel-cli

See https://cito.github.io/blog/f-strings/ and other information linked in https://github.com/microsoft/LightGBM/issues/4136. In addition to being a bit easier to read for common cases, f-strings are actually faster than most other string interpolation options.