question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DOC: Add contributor guidance about f-strings

See original GitHub issue

As we dropped support for Python 3.5, can we use f-strings now instead of those dreadful str.format() and '%s' % foo thingies? 😃 I think in many situations, f-strings are much more readable. What’s the other developers’ opinion on this?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
larsonercommented, Apr 29, 2020

Yes the informal policy is that once we bump a requirement (incl. Python) we start using features available from that requirement where / when it’s useful to do so, assuming people agree that those features are useful compared to what we’ve been doing. For example

  • we no longer need to use OrderedDict because dict maintains order in 3.6+
  • we started using np.mean(x, axis=0, keepdims=True) instead of np.mean(x, axis=0)[np.newaxis] once we bumped to a NumPy requirement that had keepdims
  • we never transitioned to prefer .format over % string because the benefits weren’t clear enough to everyone / it had its own drawbacks

f-syntax strings are probably nicer enough to prefer them going forward, though.

Feel free to add some variant of this to the dev docs if you want to semi-formalize the policy

1reaction
hoechenbergercommented, Apr 29, 2020

No objection but do not start a PR to change everywhere. Lets do it new code or when we need to touch old code

That’s exactly what I had in mind, sorry for not being clear in the beginning!

  • Use f-strings in new code when appropriate
  • Only change existing code when necessary
Read more comments on GitHub >

github_iconTop Results From Across the Web

Python 3's f-Strings: An Improved String Formatting Syntax ...
As of Python 3.6, f-strings are a great new way to format strings. ... Keep in mind that %-formatting is not recommended by...
Read more >
fstring.help: Python f-string guide
f-strings are strings with an f in front of them: f". ... self-documenting expressions and debugging - some examples adapted from the "what's...
Read more >
A Guide to Formatting with f-strings in Python - CIS Sandbox
This document will explain how to use the many options available with f-strings. Alignment. There are several ways to align variables in f-strings....
Read more >
Issue 28739: PEP 498: docstrings as f-strings - Python tracker
I suggest adding "Bytestring literals and non-trivial f-strings do not become docstrings." as the second sentence.
Read more >
The Complete Guide to Python f-Strings | Nick McCullum
Python f-strings are an improved method for formatting strings. This tutorial will teach you everything you need to know about using f-strings in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found