[PyQt] Writing dual python2/python3 code and the use of PyQt5.uic

Eli Schwartz eschwartz at archlinux.org
Mon Mar 25 03:55:32 GMT 2019


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
clarifying.

> 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

- 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.

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)


-- 
Eli Schwartz
Bug Wrangler and Trusted User

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 1601 bytes
Desc: OpenPGP digital signature
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190324/60d1418b/attachment.sig>


More information about the PyQt mailing list