This Python module provide Flake8 with an extension that hunt down operations on string literal that may fail because there are not unicode strings.
pip install unicode-string-literal
There is nothing to do to take benefits of this extension once it has been installed. Flake8 will detect it automatically.
A W742 warning will be issued for any operation made on a non string literal.
For instance:
>>> "this will fail: {}".format(u'€')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\u20ac' in position 0: ordinal not in range(128)
>>>
This error will now be prevented with this extension:
$ cat << EOF | flake8 -
"this will fail: {}".format(u'€')
EOF
stdin:1:1: W743 Unsafe operation on str, should use unicode: 'this will fail: {}'
$
if the --utter-unicode-string-literals
option is passed to flake8
command,
then all str
string literals will raise an error.
Pull-requests are welcome. You can also submit your issues to the issues tracker
This Flake8 extension is licensed under the Apache License, Version 2.0. See LICENSE file for full license text.