Alex Totheroh
Alex Totheroh

Reputation: 167

Confusion transitioning from Python 2 to Python 3: Why support both?

Context: migrating Python 2 app to Python 3

In the docs here: https://docs.python.org/3/howto/pyporting.html

They mention:

Once your dependencies are no longer blocking you, use continuous integration to make sure you stay compatible with Python 2 & 3 (tox can help test against multiple versions of Python; pip install tox)

If you are no longer blocked by your source code nor your dependencies to fully transition to Python 3, why would you continue to also support Python 2?

Is that only a consideration for when you might have users on both Python 2 and Python 3?

If nothing imports my Python app, then there's no risk in fully migrating to Python 3 and dropping Python 2 support, correct?

Upvotes: 1

Views: 237

Answers (5)

Martijn Pieters
Martijn Pieters

Reputation: 1121744

You missed that the document starts with the assumption you want to support both:

With Python 3 being the future of Python while Python 2 is still in active use, it is good to have your project available for both major releases of Python. This guide is meant to help you figure out how best to support both Python 2 & 3 simultaneously.

That's the premise of the document, and it is only natural that it then tells you how to keep your code compatible. Yes, the Python core team will end support entirely in a a short few months time, but that doesn't mean that this document was written with that in mind.

You can use the document to port to Python 3, and then drop Python 2 support entirely, yes, that's fine too.

Upvotes: 2

Booboo
Booboo

Reputation: 44108

This topic is particularly germane if you have developed code for the Python Package Index (PyPI) in Python 2 and are porting it to support both Python 2 and Python 3. You will have a "customer base" for both versions for at least the short foreseeable future.

Upvotes: -1

snakecharmerb
snakecharmerb

Reputation: 55629

If you are no longer blocked by your source code nor your dependencies to fully transition to Python 3, why would you continue to also support Python 2?

Nowadays you would probably not bother supporting Python 2 in a stand-alone app, but when that document was written, Python 2 was the norm, so supporting both versions was essential for widely used applications and libraries.

Is that only a consideration for when you might have users on both Python 2 and Python 3?

Yes

If nothing imports my Python app, then there's no risk in fully migrating to Python 3 and dropping Python 2 support, correct?

It depends on the user base that your app targets. You can expect most personal / consumer users to have Python 3 on their machines, or to be able to install it if it is not present or not the default Python (though note installing Python 3 may non-trivial for non-technical users).

Commercial or institutional users may be required to use operating systems that don't have Python 3 installed, and may not have the rights to install Python 3 themselves. In this case you would need to support Python 2 until these organisations upgrade to a suitable OS version.

Upvotes: 4

Virtual Dreamer
Virtual Dreamer

Reputation: 43

python 2 will be left not updated very soon so it's better to consider shifting to 3

Upvotes: -1

RTG87
RTG87

Reputation: 21

Yeah I think they are still supporting that keeping legacy Python 2 code in mind.

Upvotes: -1

Related Questions