[PyQt] Writing dual python2/python3 code and the use of PyQt5.uic
phil at riverbankcomputing.com
Mon Mar 25 08:26:23 GMT 2019
On 25 Mar 2019, at 3:55 am, Eli Schwartz <eschwartz at archlinux.org> wrote:
> On 3/24/19 3:06 PM, Phil Thompson wrote:
>> I completely agree with the points you make. However the current PyQt
>> policy is to support all versions of Python v3. This sort of
>> committment is particularly important to commercial customers.
> Yes, if there is a clear current commitment to support these versions
> then indeed you cannot just cut off support without warning. Thanks for
>> Actually this is a good time to review this - given the imminent EOL
>> of Python v2.
>> I'll put out a draft devised policy (based on EOL dates) for comment
>> in the next day or so.
> That seems like a useful policy to establish. Especially with regard to
> older versions of a major release cycle. Of course I do have a biased
> (python2.7+, python3.5+ strictly open-source) perspective. :)
> As far as the original topic of uic using str(), in order to solve this
> while not using unicode_literals everywhere, I can see three solutions:
> - have separate python2 and python3 versions of these files which use
> u'' on python2, but retain 3.2 compatibility by having plain '' strings
> in the python3 version
This approach is taken for other things, see the port_v2 and port_v3 directories.
> - add a conditional check for sys.version_info and determine whether to
> call unicode() on the strings (slower than using u'', but the speed is
> probably negligible...)
> - moving some code to something like PyQt5/uic/unicode_constants.py, and
> using 'from __future__ import unicode_literals' to change only those
> files to use native unicode types, which should work on both python2 and
> python3 without affecting extra things like docstrings as it will only
> affect that file.
> And option four:
> - make a note to fix this, only after an EOL policy is devised and
> deployed which allows you to stop supporting 3.0-3.2 that do not support
> u'' strings.
That will certainly happen longer term.
> Do any of these options seem like a good idea to you? I'd probably go
> with the if sys.version_info[:1] == (2,): var = unicode(var)
So 1) now and 4) later.
More information about the PyQt