In your document you ought to have appropriate trove classifier indicating exactly what variations of Python your support. Since your project will not supporting Python 3 yet you ought to at the least bring program coding language :: Python :: 2 :: just given. If at all possible it’s also advisable to specify each major/minor form of Python that you perform service, e.g. Program Coding Language :: Python :: 2.7 .
Posses good test coverageA¶
After you have the laws supporting the oldest version of Python 2 you desire they to, you’ll want to make sure that your examination collection have great plans. Good principle is when you need to be positive enough in your examination room that any downfalls that appear after having apparatus rewrite their rule are real bugs during the gear rather than inside rule. If you would like several to aim for, try to overcome 80per cent insurance coverage (and do not think poor if you discover it hard receive better than 90% insurance). If you don’t currently have a tool to measure test coverage then is preferred.
After you have the rule well-tested you are prepared to start porting your rule to Python 3! But to totally know how your own laws will probably change and what you want to watch out for while you rule, you’ll want to see what changes Python 3 helps make with respect to Python 2. usually the two finest methods of performing definitely checking out the a€?what is Newa€? doc for every release of Python 3 plus the Porting to Python 3 guide (in fact it is free online). There is a handy cheat sheet from Python-Future venture.
Improve your codeA¶
When you feel like guess what happens differs from the others in Python 3 compared to Python 2, it is the right time to update your signal! You really have an option between two tools in porting the rule immediately: Futurize and Modernize. Which means you choose will depend on how much cash like Python 3 you desire your code to get. Futurize do their far better create Python 3 idioms and techniques exists in Python 2, e.g. backporting the bytes type from Python 3 so that you have actually semantic parity between your big versions of Python. Modernize, in contrast, is far more conservative and targets a Python 2/3 subset of Python, right relying on six to greatly help render being compatible. As Python 3 may be the potential future, it may be far better consider Futurize to begin with adjusting to any brand-new procedures that Python 3 introduces which you aren’t familiar with however.
No matter which tool you decide on, they will certainly improve your code to run under Python 3 while keeping appropriate for the type of Python 2 you began with. Based on how traditional you need to getting, you might work the instrument over your test suite first and visually inspect the diff to make certain the transformation was accurate. After you have converted the examination collection and validated that all the exams nevertheless go needlessly to say, then you can certainly convert the application rule with the knowledge that any reports which fail was a translation problems.
Sadly the various tools can’t automate every thing to produce their rule perform under Python 3 and therefore you can find a handful of items you will have to modify manually attain full Python 3 assistance (which of the steps are essential fluctuate within apparatus) . Browse the documentation for software you determine to use to see what it fixes automagically and exactly what it may do optionally to understand what will (not) getting fixed individually and what-you-may need certainly to fix on your own (example. using io.open() on the built-in open() purpose are off automatically in Modernize). The good news is, however, there are only a few things to watch out for that is certainly thought about large problems that may be difficult debug otherwise watched for.