[PyQt] objcreator.py: DeprecationWarning: 'U' mode is deprecated

Valentin VALLS valentin.valls at esrf.fr
Thu Oct 24 09:29:56 BST 2019


> Patches are always welcome but they must work for all supported 
> versions of Python.
>
> Phil

Then, here is a patch. Hope the format is fone for you.

I don't think you have a public repository?

Regards

-------------- next part --------------
diff --git a/PyQt5/uic/objcreator.py b/PyQt5/uic/objcreator.py
index 921260250..8adc94017 100644
--- a/PyQt5/uic/objcreator.py
+++ b/PyQt5/uic/objcreator.py
@@ -37,7 +37,7 @@
 ##
 #############################################################################
 
-
+import sys
 import os.path
 
 from .exceptions import NoSuchWidgetError, WidgetPluginError
@@ -148,7 +148,11 @@ class QObjectCreator(object):
         loaded, or False if it wanted to be ignored.  Raise an exception if
         there was an error.
         """
-        plugin = open(filename, 'rU')
+        if sys.version_info < (3, ):
+            # Universal newline is not the default in python2
+            plugin = open(filename, 'rU')
+        else:
+            plugin = open(filename, 'r')
 
         try:
             exec(plugin.read(), plugin_globals, plugin_locals)


More information about the PyQt mailing list