https://github.com/asottile/pyupgrade
> A tool to automatically upgrade syntax for newer versions of the
> language.
- Drop u str prefix
- Drop base object inheritance
- Drop args to super()
- Use set literals
- Use dict comprehension
- Use set comprehension
There were two used:
- print_function
- absolute_import
Both of these are mandatory in Python 3.0 onwards [1] and can therefore
be removed...mostly. Unfortunately, mypy is still running in Python 2.7
mode, meaning we need the 'print_function' future wherever we're calling
'print' with the 'file' argument. There's also a single
'absolute_import' future that must be retained as its removal breaks a
test for as-yet unknown reasons. TODOs are added to resolve both issues
in the future.
[1] https://docs.python.org/3/library/__future__.html
Signed-off-by: Stephen Finucane <stephen@that.guru>
In Python 3, the default encoding of source files is utf-8. The encoding
cookie is now unnecessary and redundant so remove it. For more details,
see the docs:
https://docs.python.org/3/howto/unicode.html#the-string-type
> The default encoding for Python source code is UTF-8, so you can
> simply include a Unicode character in a string literal ...
Includes a fix for the flake8 header checks to stop expecting an
encoding cookie.
There are still a couple of checks here but all of them can be removed
now:
- Check if using valid Python syntax
- Check if line length too long
- Check if using 'x == None/True/False'
- Check if using old HTML 3 tags
The first three are already handled by default by the 'flake8' tool. The
last one isn't replaced by anything, but it really isn't worth worrying
about now because the tags it checks for have been dead for a really
long time and would not be used by anyone writing HTML in the last 10
years. Combined, it means we can remove the entire file.
The 'style-check' target is updated to simply alias 'flake8'. It can be
removed in a future release. This allows us to stop using this target in
the Travis jobs, seeing as we already run flake8.
Signed-off-by: Stephen Finucane <stephen@that.guru>