GEPS 031: Python 3 support

From Gramps
Revision as of 08:53, 7 November 2012 by Bmcage (Talk | contribs) (Created page with "Gramps was written with python 2. Slowly the default python is becoming python 3. Gramps 4.0 will require python 2.7+. Ideally we also support python 3. Then in 2014-15 we can...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Gramps was written with python 2. Slowly the default python is becoming python 3. Gramps 4.0 will require python 2.7+. Ideally we also support python 3. Then in 2014-15 we can drop python 2.7 support. For convenience, we aim for python 3.2+


Guideline

No python 2.7 only constructs should be present, and no python 3.2 only constructs should be present.

How?

See patchset in [1].

Main attention points:

  • we should not use unicode anymore. Instead, import from gramps.gen.constfunc the cuni or friends functions to convert to unicode
  • we should not compare to basestring or unicode type. Instead use UNITYPE and STRTYPE from gramps.gen.constfunc
  • in python 3 many functions became iterators. Remove the old 2.7 names and replace with the 3.2 names as much as possible. Only when performance is really an issue, use an if construct on python version so that python 2.7 also uses an iterator.
  • you will see a lot of list(map ...) or list(range...) after conversion. Only remove this if you studied the code and know it will work in python 2 and 3
  • If special unicode symbols are needed, then use from __future__ import unicode_literals and # -*- coding: utf-8 -*- and adapt the 2.7 code to have it working with this.
  • to test on python version, use if sys.version_info[0] < 3: for consistency with the other patches.


Related Gramps Bugs

  • #2620: GEPS 031: Python 3 support - 3.2

See also Python 3 Deprecated