Bug #6363

Support Python 3

Added by M T 2 months ago. Updated about 1 month ago.

Status:Rejected Start date:01/09/2019
Priority:High Due date:12/31/2019
Assignee:- % Done:


Target version:-
Chirp Version:daily Platform:All
Model affected:(All models)


Python 2 is approaching its EOL in less than a year: https://pythonclock.org/

Many repos are removing support for it, including Homebrew.

Please consider refactoring Chirp's code base to be Python 3 compatible.

2to3.patch - Update to Python 3 with PyGObject (most of the way there) (455.4 kB) M T, 01/28/2019 07:38 pm

2to3.patch.gz - SUPERSEDES ALL PRIOR PATCHES SUBMITTED IN THIS ISSUE - Update to Python 3 with PyGObject (most of the way there) (88.3 kB) M T, 01/28/2019 11:01 pm


Updated by M T about 1 month ago

The attached patch should get you a long way to Python 3 with PyGObject. Many things are still not working, but should be relatively simple to correct. The main issues are:

  • Python 3 division / is real by default. This means that int(1) / int(2) will yield float(0.5). Floor (integer) division is explicitly designated by the // operator. I have tried to use floor division where it is obviously correct (e.g., with byte math), but the rest of the code base will need to be audited (esp. around frequency calculations in many of the drivers). (Mind your modulo % operators too, since Python 3 will happily accept @float@s as operands there, too.)
  • Files are special now. file(…) is gone, and, depending on the mode, open(…) will give you one of an io.TextIOBase (that deals in Unicode) and an io.RawIOBase (that deals in bytes). (See https://docs.python.org/3/library/io.html for details.) String constants in Python 3 are all Unicode, so you really need to be precise about exactly which you want to use in each context. This will likely take some careful review and experimentation. Some frustration may ensue, but I'm happy to pair with you on these as they come up, if helpful. (There's a learning curve.)

Please let me know if I can provide any additional assistance. I recommend trying to apply this patch soon before too many changes are made to the existing code base to avoid merge conflicts.

Updated by M T about 1 month ago

A couple more improvements (ignore previous patch).

Updated by Dan Smith about 1 month ago

  • Status changed from New to Rejected

I'm closing this a s a dupe of #495 along with the others. Some more details are available in there.

Thanks for your patch, it got me thinking about some things. I'm not interested in applying something so large to the tree and hoping for the best. A lot of things need a lot of work to continue working sanely. I'm going to send a mail to the list soon with some details about the start. I hope you and anyone else that is interested in working on this can jump on that and help out.

Also available in: Atom PDF