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

Fixes issue #41 with a reference to f-strings to address issue #41 #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ But seriously: beautiful code without tests is simply worse than even the uglies

This is a section for arguments we'd rather not settle. Don't rewrite other people's code because of this stuff. Feel free to use these forms interchangeably.

### `str.format` vs overloaded format `%`
### `str.format` vs overloaded format `%` vs f-strings

`str.format` is more robust, yet `%` with `"%s %s"` printf-style strings is more concise. Both will be around forever.

Expand All @@ -556,6 +556,9 @@ But use whichever one you please. We choose not to care.

[str-format]: https://docs.python.org/2/library/string.html#formatspec

F-strings are [new in Python 3.6](https://docs.python.org/3/reference/lexical_analysis.html#f-strings) You may find them easier to compose and to read `f"result: {value:{width}.{precision}}"`. The tradeoffs are [localization](https://stackoverflow.com/a/56264202/5181298) and [security](http://lucumr.pocoo.org/2016/12/29/careful-with-str-format/). Python executes f-strings, so they present an additional attack surface: avoid including user-generated data.


### `if item` vs `if item is not None`

This is unrelated to the earlier rule on `==` vs `is` for `None`. In this case, we are actually taking advantage of Python's "truthiness rules" to our benefit in `if item`, e.g. as a shorthand "item is not None or empty string."
Expand Down