Skip to content

Remove Python 2 support

Michael Howitz edited this page Feb 11, 2020 · 10 revisions

Prerequisites

  • pyupgrade installed (the code examples below expect it to be on the search PATH.)

Steps

The following steps are necessary to remove Python 2 support from a package:

  • setup.py
    • Update version number to next major version.
    • Remove Python 2 from the list of classifiers.
    • Remove six from the list of dependencies
    • Update python_requires to python_requires='>=3.4, <4',
    • Remove other things pointing to Python 2 or PyPy[2].
  • tox.ini
    • Remove py27 and pypy from `envlist
    • Remove Python 2 specific environments
  • CHANGES.rst
    • Update the version number of the unreleased version
    • Add an entry: Drop support for Python 2.
  • pyupgrade
    • Run find src -name "*.py" -exec pyupgrade --py3-only {} \;
      • It updates the code to Python 3 e. g. by removing (some of) six usage
    • Run grep -rn six src
      • Remove or change all the usages of six
Clone this wiki locally