Home

Awesome

flake8-use-fstring

Release Status PyPI package Supported Python versions

Jump-start into modern Python by forcing yourself to use f-strings.

Works only with python>=3.6 since it was when f-strings were introduced.

Installation

pip install flake8-use-fstring

Reported Errors

Available Configurations

--percent-greedy and --format-greedy

This plugin checks each python statement (logical line) and see if % or .format is used.

Since flake8 is only a code style checker and not a type checker, it's impossible to tell for sure if the value before % or .format is a string.

Thus, greedy level is introduced to control when the plugin should report errors.

If the value immediately before % or .format is not a string, using level 1 or 2 may result in false positives. See tests/example.py for examples. Thus level 0 is the default level. However, for most projects it should be reasonable to use greedy level 2 with confidence.

To set greedy levels, set --percent-greedy=<level> and --format-greedy=<level> in the command line, or set percent-greedy=<level> and format-greedy=<level> in the .flake8 config file.

--enable-extensions=FS003 and --fstring-ignore-format

This plugin can also check for strings that appear to be f-strings but don't have the f prefix.

FS003 will be reported if a string:

Due to the potential for false positives, this check (FS003) is disabled by default. To enable this check, add the --enable-extensions=FS003 command line option, or set enable-extensions=FS003 in the .flake8 config file.

NOTE: If you use the --ignore option of flake8, the default ignore list will be overwritten. See --ignore vs --extend-ignore.

The missing prefix check normally ignores strings that are using % or .format formatting. To check those strings as well, add the --fstring-ignore-format command line option, or set fstring-ignore-format=True in the .flake8 config file.

Additional Notes

Byte literals

Byte literals (strings that are prefixed with a literal b) will not be checked since Python does not support f-strings for them (as of 3.9).