Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Python 2 remnants

I'm in the process of removing Python 2 support for many of my projects and I'd like to remove the Python 2 cruft that has build up over the years. I'm talking, for example, about the

# -*- coding: utf-8 -*-

headers, the object specification in

class Foobar(object):
    # ...

or the imports from __future__ and six.

How can I best find/remove those things?

like image 259
Nico Schlömer Avatar asked Jan 24 '26 10:01

Nico Schlömer


1 Answers

The pyupgrade tool does a great job of removing old cruft you no longer need. It supports upgrading to either Python 3+, 3.6+, or 3.7+, removing more and more cruft the newer version you can require.

The pyupgrade readme has an overview of what it fixes, which includes the coding header, the object superclass, unneeded __future__ imports, and many uses of the six library.

Notably, it does not remove the use of the future library.

like image 91
jodal Avatar answered Jan 27 '26 01:01

jodal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!